diff --git a/.eslintrc.js b/.eslintrc.js index 477b21dba..b7b50beca 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -35,7 +35,6 @@ module.exports = { "prop": "property", "memberof": "DONTUSE", "class": "DONTUSE", - "extends": "DONTUSE", "inheritdoc": "DONTUSE", "description": "DONTUSE", "readonly": "DONTUSE" diff --git a/lib/Chunk.js b/lib/Chunk.js index 7d9ad3a05..95d3588f0 100644 --- a/lib/Chunk.js +++ b/lib/Chunk.js @@ -15,6 +15,7 @@ const ERR_CHUNK_INITIAL = /** @typedef {import("./Module.js")} Module */ /** @typedef {import("./ChunkGroup")} ChunkGroup */ +/** @typedef {import("./Entrypoint")} Entrypoint */ /** @typedef {import("./ModuleReason.js")} ModuleReason */ /** @typedef {import("webpack-sources").Source} Source */ /** @typedef {import("./util/createHash").Hash} Hash */ @@ -126,7 +127,7 @@ class Chunk { /** @private */ this._groups = new SortableSet(undefined, sortChunkGroupById); - /** @private @type {SortableSet} */ + /** @private @type {SortableSet} */ this._groups = new SortableSet(undefined, sortChunkGroupById); /** @type {string[]} */ this.files = []; @@ -185,7 +186,11 @@ class Chunk { hasRuntime() { for (const chunkGroup of this._groups) { // We only need to check the first one - return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this; + return ( + chunkGroup.isInitial() && + // prettier-ignore + /** @type {Entrypoint} */ (chunkGroup).getRuntimeChunk() === this + ); } return false; } @@ -749,17 +754,37 @@ class Chunk { // TODO remove in webpack 5 Object.defineProperty(Chunk.prototype, "forEachModule", { configurable: false, - value: util.deprecate(function(fn) { - this._modules.forEach(fn); - }, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead") + value: util.deprecate( + /** + * @deprecated + * @this {Chunk} + * @typedef {function(any, any, Set): void} ForEachModuleCallback + * @param {ForEachModuleCallback} fn Callback function + * @returns {void} + */ + function(fn) { + this._modules.forEach(fn); + }, + "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead" + ) }); // TODO remove in webpack 5 Object.defineProperty(Chunk.prototype, "mapModules", { configurable: false, - value: util.deprecate(function(fn) { - return Array.from(this._modules, fn); - }, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead") + value: util.deprecate( + /** + * @deprecated + * @this {Chunk} + * @typedef {function(any, number): any} MapModulesCallback + * @param {MapModulesCallback} fn Callback function + * @returns {TODO[]} result of mapped modules + */ + function(fn) { + return Array.from(this._modules, fn); + }, + "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead" + ) }); // TODO remove in webpack 5 diff --git a/lib/ChunkGroup.js b/lib/ChunkGroup.js index 19e8f3c67..4acbc46c3 100644 --- a/lib/ChunkGroup.js +++ b/lib/ChunkGroup.js @@ -11,7 +11,6 @@ const compareLocations = require("./compareLocations"); /** @typedef {import("./Module")} Module */ /** @typedef {import("./ModuleReason")} ModuleReason */ -/** @typedef {{id: number}} HasId */ /** @typedef {{module: Module, loc: TODO, request: string}} OriginRecord */ /** @typedef {string|{name: string}} ChunkGroupOptions */ @@ -26,8 +25,8 @@ const getArray = set => Array.from(set); /** * A convenience method used to sort chunks based on their id's - * @param {HasId} a first sorting comparator - * @param {HasId} b second sorting comparator + * @param {ChunkGroup} a first sorting comparator + * @param {ChunkGroup} b second sorting comparator * @returns {1|0|-1} a sorting index to determine order */ const sortById = (a, b) => { @@ -63,6 +62,7 @@ class ChunkGroup { /** @type {number} */ this.groupDebugId = debugId++; this.options = options; + /** @type {SortableSet} */ this._children = new SortableSet(undefined, sortById); this._parents = new SortableSet(undefined, sortById); this._blocks = new SortableSet(); diff --git a/lib/Compilation.js b/lib/Compilation.js index c1be909f1..1008ee3e9 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -2438,21 +2438,48 @@ class Compilation extends Tapable { } // TODO remove in webpack 5 -Compilation.prototype.applyPlugins = util.deprecate(function(name, ...args) { - this.hooks[ - name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase()) - ].call(...args); -}, "Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead"); +Compilation.prototype.applyPlugins = util.deprecate( + /** + * @deprecated + * @param {string} name Name + * @param {any[]} args Other arguments + * @returns {void} + * @this {Compilation} + */ + function(name, ...args) { + this.hooks[ + name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase()) + ].call(...args); + }, + "Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead" +); // TODO remove in webpack 5 Object.defineProperty(Compilation.prototype, "moduleTemplate", { configurable: false, - get: util.deprecate(function() { - return this.moduleTemplates.javascript; - }, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"), - set: util.deprecate(function(value) { - this.moduleTemplates.javascript = value; - }, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead.") + get: util.deprecate( + /** + * @deprecated + * @this {Compilation} + * @returns {TODO} module template + */ + function() { + return this.moduleTemplates.javascript; + }, + "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead" + ), + set: util.deprecate( + /** + * @deprecated + * @param {ModuleTemplate} value Template value + * @this {Compilation} + * @returns {void} + */ + function(value) { + this.moduleTemplates.javascript = value; + }, + "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead." + ) }); module.exports = Compilation; diff --git a/lib/ContextModule.js b/lib/ContextModule.js index 9db2914b7..dbf197ecc 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -10,6 +10,7 @@ const AsyncDependenciesBlock = require("./AsyncDependenciesBlock"); const Template = require("./Template"); const contextify = require("./util/identifier").contextify; +/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */ /** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */ class ContextModule extends Module { @@ -684,56 +685,141 @@ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`; // TODO remove in webpack 5 Object.defineProperty(ContextModule.prototype, "recursive", { configurable: false, - get: util.deprecate(function() { - return this.options.recursive; - }, "ContextModule.recursive has been moved to ContextModule.options.recursive"), - set: util.deprecate(function(value) { - this.options.recursive = value; - }, "ContextModule.recursive has been moved to ContextModule.options.recursive") + get: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @returns {boolean} is recursive + */ + function() { + return this.options.recursive; + }, + "ContextModule.recursive has been moved to ContextModule.options.recursive" + ), + set: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @param {boolean} value is recursive + * @returns {void} + */ + function(value) { + this.options.recursive = value; + }, + "ContextModule.recursive has been moved to ContextModule.options.recursive" + ) }); // TODO remove in webpack 5 Object.defineProperty(ContextModule.prototype, "regExp", { configurable: false, - get: util.deprecate(function() { - return this.options.regExp; - }, "ContextModule.regExp has been moved to ContextModule.options.regExp"), - set: util.deprecate(function(value) { - this.options.regExp = value; - }, "ContextModule.regExp has been moved to ContextModule.options.regExp") + get: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @returns {RegExp} regular expression + */ + function() { + return this.options.regExp; + }, + "ContextModule.regExp has been moved to ContextModule.options.regExp" + ), + set: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @param {RegExp} value Regular expression + * @returns {void} + */ + function(value) { + this.options.regExp = value; + }, + "ContextModule.regExp has been moved to ContextModule.options.regExp" + ) }); // TODO remove in webpack 5 Object.defineProperty(ContextModule.prototype, "addon", { configurable: false, - get: util.deprecate(function() { - return this.options.addon; - }, "ContextModule.addon has been moved to ContextModule.options.addon"), - set: util.deprecate(function(value) { - this.options.addon = value; - }, "ContextModule.addon has been moved to ContextModule.options.addon") + get: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @returns {string} addon + */ + function() { + return this.options.addon; + }, + "ContextModule.addon has been moved to ContextModule.options.addon" + ), + set: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @param {string} value addon + * @returns {void} + */ + function(value) { + this.options.addon = value; + }, + "ContextModule.addon has been moved to ContextModule.options.addon" + ) }); // TODO remove in webpack 5 Object.defineProperty(ContextModule.prototype, "async", { configurable: false, - get: util.deprecate(function() { - return this.options.mode; - }, "ContextModule.async has been moved to ContextModule.options.mode"), - set: util.deprecate(function(value) { - this.options.mode = value; - }, "ContextModule.async has been moved to ContextModule.options.mode") + get: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @returns {boolean} is async + */ + function() { + return this.options.mode; + }, + "ContextModule.async has been moved to ContextModule.options.mode" + ), + set: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @param {ContextMode} value Context mode + * @returns {void} + */ + function(value) { + this.options.mode = value; + }, + "ContextModule.async has been moved to ContextModule.options.mode" + ) }); // TODO remove in webpack 5 Object.defineProperty(ContextModule.prototype, "chunkName", { configurable: false, - get: util.deprecate(function() { - return this.options.chunkName; - }, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"), - set: util.deprecate(function(value) { - this.options.chunkName = value; - }, "ContextModule.chunkName has been moved to ContextModule.options.chunkName") + get: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @returns {string} chunk name + */ + function() { + return this.options.chunkName; + }, + "ContextModule.chunkName has been moved to ContextModule.options.chunkName" + ), + set: util.deprecate( + /** + * @deprecated + * @this {ContextModule} + * @param {string} value chunk name + * @returns {void} + */ + function(value) { + this.options.chunkName = value; + }, + "ContextModule.chunkName has been moved to ContextModule.options.chunkName" + ) }); module.exports = ContextModule; diff --git a/lib/Module.js b/lib/Module.js index b0a533a85..6af441559 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -339,17 +339,35 @@ class Module extends DependenciesBlock { // TODO remove in webpack 5 Object.defineProperty(Module.prototype, "forEachChunk", { configurable: false, - value: util.deprecate(function(fn) { - this._chunks.forEach(fn); - }, "Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead") + value: util.deprecate( + /** + * @deprecated + * @param {function(any, any, Set): void} fn callback function + * @returns {void} + * @this {Module} + */ + function(fn) { + this._chunks.forEach(fn); + }, + "Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead" + ) }); // TODO remove in webpack 5 Object.defineProperty(Module.prototype, "mapChunks", { configurable: false, - value: util.deprecate(function(fn) { - return Array.from(this._chunks, fn); - }, "Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead") + value: util.deprecate( + /** + * @deprecated + * @param {function(any, any): void} fn Mapper function + * @returns {Array} Array of chunks mapped + * @this {Module} + */ + function(fn) { + return Array.from(this._chunks, fn); + }, + "Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead" + ) }); // TODO remove in webpack 5 @@ -366,12 +384,29 @@ Object.defineProperty(Module.prototype, "entry", { // TODO remove in webpack 5 Object.defineProperty(Module.prototype, "meta", { configurable: false, - get: util.deprecate(function() { - return this.buildMeta; - }, "Module.meta was renamed to Module.buildMeta"), - set: util.deprecate(function(value) { - this.buildMeta = value; - }, "Module.meta was renamed to Module.buildMeta") + get: util.deprecate( + /** + * @deprecated + * @returns {void} + * @this {Module} + */ + function() { + return this.buildMeta; + }, + "Module.meta was renamed to Module.buildMeta" + ), + set: util.deprecate( + /** + * @deprecated + * @param {TODO} value Value + * @returns {void} + * @this {Module} + */ + function(value) { + this.buildMeta = value; + }, + "Module.meta was renamed to Module.buildMeta" + ) }); /** @type {function(): string} */ diff --git a/lib/Parser.js b/lib/Parser.js index 515df3877..787f67d61 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -2185,9 +2185,18 @@ class Parser extends Tapable { // TODO remove in webpack 5 Object.defineProperty(Parser.prototype, "getCommentOptions", { configurable: false, - value: util.deprecate(function(range) { - return this.parseCommentOptions(range).options; - }, "Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead") + value: util.deprecate( + /** + * @deprecated + * @param {TODO} range Range + * @returns {void} + * @this {Parser} + */ + function(range) { + return this.parseCommentOptions(range).options; + }, + "Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead" + ) }); module.exports = Parser; diff --git a/lib/util/SortableSet.js b/lib/util/SortableSet.js index f391f07d0..44b692f37 100644 --- a/lib/util/SortableSet.js +++ b/lib/util/SortableSet.js @@ -3,6 +3,7 @@ /** * A subset of Set that offers sorting functionality * @template T item type in set + * @extends {Set} */ class SortableSet extends Set { /** diff --git a/lib/util/StackedSetMap.js b/lib/util/StackedSetMap.js index 589b68d52..fcf628b0d 100644 --- a/lib/util/StackedSetMap.js +++ b/lib/util/StackedSetMap.js @@ -128,8 +128,17 @@ class StackedSetMap { } // TODO remove in webpack 5 -StackedSetMap.prototype.push = util.deprecate(function(item) { - this.add(item); -}, "This is no longer an Array: Use add instead."); +StackedSetMap.prototype.push = util.deprecate( + /** + * @deprecated + * @this {StackedSetMap} + * @param {any} item Item to add + * @returns {void} + */ + function(item) { + this.add(item); + }, + "This is no longer an Array: Use add instead." +); module.exports = StackedSetMap; diff --git a/lib/webpack.js b/lib/webpack.js index f5a8af68f..a8e474605 100644 --- a/lib/webpack.js +++ b/lib/webpack.js @@ -69,6 +69,7 @@ webpack.WebpackOptionsApply = WebpackOptionsApply; webpack.Compiler = Compiler; webpack.MultiCompiler = MultiCompiler; webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin; +// @ts-ignore Global @this directive is not supported webpack.validate = validateSchema.bind(this, webpackOptionsSchema); webpack.validateSchema = validateSchema; webpack.WebpackOptionsValidationError = WebpackOptionsValidationError; diff --git a/package.json b/package.json index a22497fff..d4fbe036b 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "script-loader": "~0.7.0", "simple-git": "^1.65.0", "style-loader": "^0.19.1", - "typescript": "^2.9.1", + "typescript": "^3.0.0-dev.20180628", "url-loader": "^0.6.2", "val-loader": "^1.0.2", "vm-browserify": "~0.0.0", diff --git a/tsconfig.json b/tsconfig.json index ab2f8191e..b4a8a3be5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "checkJs": true, "noEmit": true, "strict": false, + "noImplicitThis": true, "alwaysStrict": true, "types": ["node"], "esModuleInterop": true diff --git a/yarn.lock b/yarn.lock index 037df12f4..9f4adfa45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5130,8 +5130,8 @@ preserve@^0.2.0: resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" prettier@^1.13.5: - version "1.13.5" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.5.tgz#7ae2076998c8edce79d63834e9b7b09fead6bfd0" + version "1.13.7" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.7.tgz#850f3b8af784a49a6ea2d2eaa7ed1428a34b7281" pretty-format@^22.4.3: version "22.4.3" @@ -6502,9 +6502,9 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@^2.9.1: - version "2.9.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" +typescript@^3.0.0-dev.20180628: + version "3.0.0-dev.20180628" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.0-dev.20180628.tgz#9f70006d4e04daa5bb7a8b9db96e3728683330a6" ua-parser-js@^0.7.9: version "0.7.18"