Enable noImplicitThis TypeScript compiler option

This commit is contained in:
Mohsen Azimi 2018-07-05 08:07:46 +03:00
parent bdd4442c44
commit a0e1ad920e
13 changed files with 270 additions and 77 deletions

View File

@ -35,7 +35,6 @@ module.exports = {
"prop": "property", "prop": "property",
"memberof": "DONTUSE", "memberof": "DONTUSE",
"class": "DONTUSE", "class": "DONTUSE",
"extends": "DONTUSE",
"inheritdoc": "DONTUSE", "inheritdoc": "DONTUSE",
"description": "DONTUSE", "description": "DONTUSE",
"readonly": "DONTUSE" "readonly": "DONTUSE"

View File

@ -15,6 +15,7 @@ const ERR_CHUNK_INITIAL =
/** @typedef {import("./Module.js")} Module */ /** @typedef {import("./Module.js")} Module */
/** @typedef {import("./ChunkGroup")} ChunkGroup */ /** @typedef {import("./ChunkGroup")} ChunkGroup */
/** @typedef {import("./Entrypoint")} Entrypoint */
/** @typedef {import("./ModuleReason.js")} ModuleReason */ /** @typedef {import("./ModuleReason.js")} ModuleReason */
/** @typedef {import("webpack-sources").Source} Source */ /** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("./util/createHash").Hash} Hash */ /** @typedef {import("./util/createHash").Hash} Hash */
@ -126,7 +127,7 @@ class Chunk {
/** @private */ /** @private */
this._groups = new SortableSet(undefined, sortChunkGroupById); this._groups = new SortableSet(undefined, sortChunkGroupById);
/** @private @type {SortableSet<ChunkGroup>} */ /** @private @type {SortableSet<ChunkGroup | Entrypoint>} */
this._groups = new SortableSet(undefined, sortChunkGroupById); this._groups = new SortableSet(undefined, sortChunkGroupById);
/** @type {string[]} */ /** @type {string[]} */
this.files = []; this.files = [];
@ -185,7 +186,11 @@ class Chunk {
hasRuntime() { hasRuntime() {
for (const chunkGroup of this._groups) { for (const chunkGroup of this._groups) {
// We only need to check the first one // 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; return false;
} }
@ -749,17 +754,37 @@ class Chunk {
// TODO remove in webpack 5 // TODO remove in webpack 5
Object.defineProperty(Chunk.prototype, "forEachModule", { Object.defineProperty(Chunk.prototype, "forEachModule", {
configurable: false, configurable: false,
value: util.deprecate(function(fn) { value: util.deprecate(
this._modules.forEach(fn); /**
}, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead") * @deprecated
* @this {Chunk}
* @typedef {function(any, any, Set<any>): 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 // TODO remove in webpack 5
Object.defineProperty(Chunk.prototype, "mapModules", { Object.defineProperty(Chunk.prototype, "mapModules", {
configurable: false, configurable: false,
value: util.deprecate(function(fn) { value: util.deprecate(
return Array.from(this._modules, fn); /**
}, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead") * @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 // TODO remove in webpack 5

View File

@ -11,7 +11,6 @@ const compareLocations = require("./compareLocations");
/** @typedef {import("./Module")} Module */ /** @typedef {import("./Module")} Module */
/** @typedef {import("./ModuleReason")} ModuleReason */ /** @typedef {import("./ModuleReason")} ModuleReason */
/** @typedef {{id: number}} HasId */
/** @typedef {{module: Module, loc: TODO, request: string}} OriginRecord */ /** @typedef {{module: Module, loc: TODO, request: string}} OriginRecord */
/** @typedef {string|{name: string}} ChunkGroupOptions */ /** @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 * A convenience method used to sort chunks based on their id's
* @param {HasId} a first sorting comparator * @param {ChunkGroup} a first sorting comparator
* @param {HasId} b second sorting comparator * @param {ChunkGroup} b second sorting comparator
* @returns {1|0|-1} a sorting index to determine order * @returns {1|0|-1} a sorting index to determine order
*/ */
const sortById = (a, b) => { const sortById = (a, b) => {
@ -63,6 +62,7 @@ class ChunkGroup {
/** @type {number} */ /** @type {number} */
this.groupDebugId = debugId++; this.groupDebugId = debugId++;
this.options = options; this.options = options;
/** @type {SortableSet<ChunkGroup>} */
this._children = new SortableSet(undefined, sortById); this._children = new SortableSet(undefined, sortById);
this._parents = new SortableSet(undefined, sortById); this._parents = new SortableSet(undefined, sortById);
this._blocks = new SortableSet(); this._blocks = new SortableSet();

View File

@ -2438,21 +2438,48 @@ class Compilation extends Tapable {
} }
// TODO remove in webpack 5 // TODO remove in webpack 5
Compilation.prototype.applyPlugins = util.deprecate(function(name, ...args) { Compilation.prototype.applyPlugins = util.deprecate(
this.hooks[ /**
name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase()) * @deprecated
].call(...args); * @param {string} name Name
}, "Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead"); * @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 // TODO remove in webpack 5
Object.defineProperty(Compilation.prototype, "moduleTemplate", { Object.defineProperty(Compilation.prototype, "moduleTemplate", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.moduleTemplates.javascript; /**
}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"), * @deprecated
set: util.deprecate(function(value) { * @this {Compilation}
this.moduleTemplates.javascript = value; * @returns {TODO} module template
}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead.") */
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; module.exports = Compilation;

View File

@ -10,6 +10,7 @@ const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
const Template = require("./Template"); const Template = require("./Template");
const contextify = require("./util/identifier").contextify; const contextify = require("./util/identifier").contextify;
/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */ /** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
class ContextModule extends Module { class ContextModule extends Module {
@ -684,56 +685,141 @@ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
// TODO remove in webpack 5 // TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "recursive", { Object.defineProperty(ContextModule.prototype, "recursive", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.options.recursive; /**
}, "ContextModule.recursive has been moved to ContextModule.options.recursive"), * @deprecated
set: util.deprecate(function(value) { * @this {ContextModule}
this.options.recursive = value; * @returns {boolean} is recursive
}, "ContextModule.recursive has been moved to ContextModule.options.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 // TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "regExp", { Object.defineProperty(ContextModule.prototype, "regExp", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.options.regExp; /**
}, "ContextModule.regExp has been moved to ContextModule.options.regExp"), * @deprecated
set: util.deprecate(function(value) { * @this {ContextModule}
this.options.regExp = value; * @returns {RegExp} regular expression
}, "ContextModule.regExp has been moved to ContextModule.options.regExp") */
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 // TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "addon", { Object.defineProperty(ContextModule.prototype, "addon", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.options.addon; /**
}, "ContextModule.addon has been moved to ContextModule.options.addon"), * @deprecated
set: util.deprecate(function(value) { * @this {ContextModule}
this.options.addon = value; * @returns {string} addon
}, "ContextModule.addon has been moved to ContextModule.options.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 // TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "async", { Object.defineProperty(ContextModule.prototype, "async", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.options.mode; /**
}, "ContextModule.async has been moved to ContextModule.options.mode"), * @deprecated
set: util.deprecate(function(value) { * @this {ContextModule}
this.options.mode = value; * @returns {boolean} is async
}, "ContextModule.async has been moved to ContextModule.options.mode") */
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 // TODO remove in webpack 5
Object.defineProperty(ContextModule.prototype, "chunkName", { Object.defineProperty(ContextModule.prototype, "chunkName", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.options.chunkName; /**
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"), * @deprecated
set: util.deprecate(function(value) { * @this {ContextModule}
this.options.chunkName = value; * @returns {string} chunk name
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName") */
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; module.exports = ContextModule;

View File

@ -339,17 +339,35 @@ class Module extends DependenciesBlock {
// TODO remove in webpack 5 // TODO remove in webpack 5
Object.defineProperty(Module.prototype, "forEachChunk", { Object.defineProperty(Module.prototype, "forEachChunk", {
configurable: false, configurable: false,
value: util.deprecate(function(fn) { value: util.deprecate(
this._chunks.forEach(fn); /**
}, "Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead") * @deprecated
* @param {function(any, any, Set<any>): 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 // TODO remove in webpack 5
Object.defineProperty(Module.prototype, "mapChunks", { Object.defineProperty(Module.prototype, "mapChunks", {
configurable: false, configurable: false,
value: util.deprecate(function(fn) { value: util.deprecate(
return Array.from(this._chunks, fn); /**
}, "Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead") * @deprecated
* @param {function(any, any): void} fn Mapper function
* @returns {Array<TODO>} 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 // TODO remove in webpack 5
@ -366,12 +384,29 @@ Object.defineProperty(Module.prototype, "entry", {
// TODO remove in webpack 5 // TODO remove in webpack 5
Object.defineProperty(Module.prototype, "meta", { Object.defineProperty(Module.prototype, "meta", {
configurable: false, configurable: false,
get: util.deprecate(function() { get: util.deprecate(
return this.buildMeta; /**
}, "Module.meta was renamed to Module.buildMeta"), * @deprecated
set: util.deprecate(function(value) { * @returns {void}
this.buildMeta = value; * @this {Module}
}, "Module.meta was renamed to Module.buildMeta") */
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} */ /** @type {function(): string} */

View File

@ -2185,9 +2185,18 @@ class Parser extends Tapable {
// TODO remove in webpack 5 // TODO remove in webpack 5
Object.defineProperty(Parser.prototype, "getCommentOptions", { Object.defineProperty(Parser.prototype, "getCommentOptions", {
configurable: false, configurable: false,
value: util.deprecate(function(range) { value: util.deprecate(
return this.parseCommentOptions(range).options; /**
}, "Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead") * @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; module.exports = Parser;

View File

@ -3,6 +3,7 @@
/** /**
* A subset of Set that offers sorting functionality * A subset of Set that offers sorting functionality
* @template T item type in set * @template T item type in set
* @extends {Set<T>}
*/ */
class SortableSet extends Set { class SortableSet extends Set {
/** /**

View File

@ -128,8 +128,17 @@ class StackedSetMap {
} }
// TODO remove in webpack 5 // TODO remove in webpack 5
StackedSetMap.prototype.push = util.deprecate(function(item) { StackedSetMap.prototype.push = util.deprecate(
this.add(item); /**
}, "This is no longer an Array: Use add instead."); * @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; module.exports = StackedSetMap;

View File

@ -69,6 +69,7 @@ webpack.WebpackOptionsApply = WebpackOptionsApply;
webpack.Compiler = Compiler; webpack.Compiler = Compiler;
webpack.MultiCompiler = MultiCompiler; webpack.MultiCompiler = MultiCompiler;
webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin; webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin;
// @ts-ignore Global @this directive is not supported
webpack.validate = validateSchema.bind(this, webpackOptionsSchema); webpack.validate = validateSchema.bind(this, webpackOptionsSchema);
webpack.validateSchema = validateSchema; webpack.validateSchema = validateSchema;
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError; webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;

View File

@ -73,7 +73,7 @@
"script-loader": "~0.7.0", "script-loader": "~0.7.0",
"simple-git": "^1.65.0", "simple-git": "^1.65.0",
"style-loader": "^0.19.1", "style-loader": "^0.19.1",
"typescript": "^2.9.1", "typescript": "^3.0.0-dev.20180628",
"url-loader": "^0.6.2", "url-loader": "^0.6.2",
"val-loader": "^1.0.2", "val-loader": "^1.0.2",
"vm-browserify": "~0.0.0", "vm-browserify": "~0.0.0",

View File

@ -7,6 +7,7 @@
"checkJs": true, "checkJs": true,
"noEmit": true, "noEmit": true,
"strict": false, "strict": false,
"noImplicitThis": true,
"alwaysStrict": true, "alwaysStrict": true,
"types": ["node"], "types": ["node"],
"esModuleInterop": true "esModuleInterop": true

View File

@ -5130,8 +5130,8 @@ preserve@^0.2.0:
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@^1.13.5: prettier@^1.13.5:
version "1.13.5" version "1.13.7"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.5.tgz#7ae2076998c8edce79d63834e9b7b09fead6bfd0" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.7.tgz#850f3b8af784a49a6ea2d2eaa7ed1428a34b7281"
pretty-format@^22.4.3: pretty-format@^22.4.3:
version "22.4.3" version "22.4.3"
@ -6502,9 +6502,9 @@ typedarray@^0.0.6:
version "0.0.6" version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
typescript@^2.9.1: typescript@^3.0.0-dev.20180628:
version "2.9.2" version "3.0.0-dev.20180628"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.0-dev.20180628.tgz#9f70006d4e04daa5bb7a8b9db96e3728683330a6"
ua-parser-js@^0.7.9: ua-parser-js@^0.7.9:
version "0.7.18" version "0.7.18"