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",
"memberof": "DONTUSE",
"class": "DONTUSE",
"extends": "DONTUSE",
"inheritdoc": "DONTUSE",
"description": "DONTUSE",
"readonly": "DONTUSE"

View File

@ -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<ChunkGroup>} */
/** @private @type {SortableSet<ChunkGroup | Entrypoint>} */
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) {
value: util.deprecate(
/**
* @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")
},
"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) {
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")
},
"Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead"
)
});
// TODO remove in webpack 5

View File

@ -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<ChunkGroup>} */
this._children = new SortableSet(undefined, sortById);
this._parents = new SortableSet(undefined, sortById);
this._blocks = new SortableSet();

View File

@ -2438,21 +2438,48 @@ class Compilation extends Tapable {
}
// TODO remove in webpack 5
Compilation.prototype.applyPlugins = util.deprecate(function(name, ...args) {
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");
},
"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() {
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(function(value) {
},
"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.")
},
"Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead."
)
});
module.exports = Compilation;

View File

@ -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() {
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(function(value) {
},
"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")
},
"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() {
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(function(value) {
},
"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")
},
"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() {
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(function(value) {
},
"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")
},
"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() {
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(function(value) {
},
"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")
},
"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() {
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(function(value) {
},
"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")
},
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
)
});
module.exports = ContextModule;

View File

@ -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) {
value: util.deprecate(
/**
* @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")
},
"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) {
value: util.deprecate(
/**
* @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")
},
"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() {
get: util.deprecate(
/**
* @deprecated
* @returns {void}
* @this {Module}
*/
function() {
return this.buildMeta;
}, "Module.meta was renamed to Module.buildMeta"),
set: util.deprecate(function(value) {
},
"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")
},
"Module.meta was renamed to Module.buildMeta"
)
});
/** @type {function(): string} */

View File

@ -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) {
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")
},
"Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead"
)
});
module.exports = Parser;

View File

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

View File

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

View File

@ -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;

View File

@ -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",

View File

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

View File

@ -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"