Skip to content

Commit 9fd6af8

Browse files
authored
Merge pull request webpack#7657 from mohsen1/enable-noImplicitThis
Enable noImplicitThis TypeScript compiler option
2 parents 2dde005 + bc86359 commit 9fd6af8

File tree

11 files changed

+263
-73
lines changed

11 files changed

+263
-73
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module.exports = {
3535
"prop": "property",
3636
"memberof": "DONTUSE",
3737
"class": "DONTUSE",
38-
"extends": "DONTUSE",
3938
"inheritdoc": "DONTUSE",
4039
"description": "DONTUSE",
4140
"readonly": "DONTUSE"

lib/Chunk.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const util = require("util");
88
const SortableSet = require("./util/SortableSet");
99
const intersect = require("./util/SetHelpers").intersect;
1010
const GraphHelpers = require("./GraphHelpers");
11+
const Entrypoint = require("./Entrypoint");
1112
let debugId = 1000;
1213
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
1314
const ERR_CHUNK_INITIAL =
@@ -123,9 +124,6 @@ class Chunk {
123124
this._modules = new SortableSet(undefined, sortByIdentifier);
124125
/** @type {string?} */
125126
this.filenameTemplate = undefined;
126-
127-
/** @private */
128-
this._groups = new SortableSet(undefined, sortChunkGroupById);
129127
/** @private @type {SortableSet<ChunkGroup>} */
130128
this._groups = new SortableSet(undefined, sortChunkGroupById);
131129
/** @type {string[]} */
@@ -185,7 +183,11 @@ class Chunk {
185183
hasRuntime() {
186184
for (const chunkGroup of this._groups) {
187185
// We only need to check the first one
188-
return chunkGroup.isInitial() && chunkGroup.getRuntimeChunk() === this;
186+
return (
187+
chunkGroup.isInitial() &&
188+
chunkGroup instanceof Entrypoint &&
189+
chunkGroup.getRuntimeChunk() === this
190+
);
189191
}
190192
return false;
191193
}
@@ -749,17 +751,37 @@ class Chunk {
749751
// TODO remove in webpack 5
750752
Object.defineProperty(Chunk.prototype, "forEachModule", {
751753
configurable: false,
752-
value: util.deprecate(function(fn) {
753-
this._modules.forEach(fn);
754-
}, "Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead")
754+
value: util.deprecate(
755+
/**
756+
* @deprecated
757+
* @this {Chunk}
758+
* @typedef {function(any, any, Set<any>): void} ForEachModuleCallback
759+
* @param {ForEachModuleCallback} fn Callback function
760+
* @returns {void}
761+
*/
762+
function(fn) {
763+
this._modules.forEach(fn);
764+
},
765+
"Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead"
766+
)
755767
});
756768

757769
// TODO remove in webpack 5
758770
Object.defineProperty(Chunk.prototype, "mapModules", {
759771
configurable: false,
760-
value: util.deprecate(function(fn) {
761-
return Array.from(this._modules, fn);
762-
}, "Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead")
772+
value: util.deprecate(
773+
/**
774+
* @deprecated
775+
* @this {Chunk}
776+
* @typedef {function(any, number): any} MapModulesCallback
777+
* @param {MapModulesCallback} fn Callback function
778+
* @returns {TODO[]} result of mapped modules
779+
*/
780+
function(fn) {
781+
return Array.from(this._modules, fn);
782+
},
783+
"Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead"
784+
)
763785
});
764786

765787
// TODO remove in webpack 5

lib/ChunkGroup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const compareLocations = require("./compareLocations");
1111
/** @typedef {import("./Module")} Module */
1212
/** @typedef {import("./ModuleReason")} ModuleReason */
1313

14-
/** @typedef {{id: number}} HasId */
1514
/** @typedef {{module: Module, loc: TODO, request: string}} OriginRecord */
1615
/** @typedef {string|{name: string}} ChunkGroupOptions */
1716

@@ -26,8 +25,8 @@ const getArray = set => Array.from(set);
2625

2726
/**
2827
* A convenience method used to sort chunks based on their id's
29-
* @param {HasId} a first sorting comparator
30-
* @param {HasId} b second sorting comparator
28+
* @param {ChunkGroup} a first sorting comparator
29+
* @param {ChunkGroup} b second sorting comparator
3130
* @returns {1|0|-1} a sorting index to determine order
3231
*/
3332
const sortById = (a, b) => {
@@ -63,6 +62,7 @@ class ChunkGroup {
6362
/** @type {number} */
6463
this.groupDebugId = debugId++;
6564
this.options = options;
65+
/** @type {SortableSet<ChunkGroup>} */
6666
this._children = new SortableSet(undefined, sortById);
6767
this._parents = new SortableSet(undefined, sortById);
6868
this._blocks = new SortableSet();

lib/Compilation.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,21 +2442,48 @@ class Compilation extends Tapable {
24422442
}
24432443

24442444
// TODO remove in webpack 5
2445-
Compilation.prototype.applyPlugins = util.deprecate(function(name, ...args) {
2446-
this.hooks[
2447-
name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase())
2448-
].call(...args);
2449-
}, "Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead");
2445+
Compilation.prototype.applyPlugins = util.deprecate(
2446+
/**
2447+
* @deprecated
2448+
* @param {string} name Name
2449+
* @param {any[]} args Other arguments
2450+
* @returns {void}
2451+
* @this {Compilation}
2452+
*/
2453+
function(name, ...args) {
2454+
this.hooks[
2455+
name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase())
2456+
].call(...args);
2457+
},
2458+
"Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead"
2459+
);
24502460

24512461
// TODO remove in webpack 5
24522462
Object.defineProperty(Compilation.prototype, "moduleTemplate", {
24532463
configurable: false,
2454-
get: util.deprecate(function() {
2455-
return this.moduleTemplates.javascript;
2456-
}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"),
2457-
set: util.deprecate(function(value) {
2458-
this.moduleTemplates.javascript = value;
2459-
}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead.")
2464+
get: util.deprecate(
2465+
/**
2466+
* @deprecated
2467+
* @this {Compilation}
2468+
* @returns {TODO} module template
2469+
*/
2470+
function() {
2471+
return this.moduleTemplates.javascript;
2472+
},
2473+
"Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"
2474+
),
2475+
set: util.deprecate(
2476+
/**
2477+
* @deprecated
2478+
* @param {ModuleTemplate} value Template value
2479+
* @this {Compilation}
2480+
* @returns {void}
2481+
*/
2482+
function(value) {
2483+
this.moduleTemplates.javascript = value;
2484+
},
2485+
"Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead."
2486+
)
24602487
});
24612488

24622489
module.exports = Compilation;

lib/ContextModule.js

Lines changed: 116 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
1010
const Template = require("./Template");
1111
const contextify = require("./util/identifier").contextify;
1212

13+
/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
1314
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
1415

1516
/**
@@ -703,56 +704,141 @@ webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
703704
// TODO remove in webpack 5
704705
Object.defineProperty(ContextModule.prototype, "recursive", {
705706
configurable: false,
706-
get: util.deprecate(function() {
707-
return this.options.recursive;
708-
}, "ContextModule.recursive has been moved to ContextModule.options.recursive"),
709-
set: util.deprecate(function(value) {
710-
this.options.recursive = value;
711-
}, "ContextModule.recursive has been moved to ContextModule.options.recursive")
707+
get: util.deprecate(
708+
/**
709+
* @deprecated
710+
* @this {ContextModule}
711+
* @returns {boolean} is recursive
712+
*/
713+
function() {
714+
return this.options.recursive;
715+
},
716+
"ContextModule.recursive has been moved to ContextModule.options.recursive"
717+
),
718+
set: util.deprecate(
719+
/**
720+
* @deprecated
721+
* @this {ContextModule}
722+
* @param {boolean} value is recursive
723+
* @returns {void}
724+
*/
725+
function(value) {
726+
this.options.recursive = value;
727+
},
728+
"ContextModule.recursive has been moved to ContextModule.options.recursive"
729+
)
712730
});
713731

714732
// TODO remove in webpack 5
715733
Object.defineProperty(ContextModule.prototype, "regExp", {
716734
configurable: false,
717-
get: util.deprecate(function() {
718-
return this.options.regExp;
719-
}, "ContextModule.regExp has been moved to ContextModule.options.regExp"),
720-
set: util.deprecate(function(value) {
721-
this.options.regExp = value;
722-
}, "ContextModule.regExp has been moved to ContextModule.options.regExp")
735+
get: util.deprecate(
736+
/**
737+
* @deprecated
738+
* @this {ContextModule}
739+
* @returns {RegExp} regular expression
740+
*/
741+
function() {
742+
return this.options.regExp;
743+
},
744+
"ContextModule.regExp has been moved to ContextModule.options.regExp"
745+
),
746+
set: util.deprecate(
747+
/**
748+
* @deprecated
749+
* @this {ContextModule}
750+
* @param {RegExp} value Regular expression
751+
* @returns {void}
752+
*/
753+
function(value) {
754+
this.options.regExp = value;
755+
},
756+
"ContextModule.regExp has been moved to ContextModule.options.regExp"
757+
)
723758
});
724759

725760
// TODO remove in webpack 5
726761
Object.defineProperty(ContextModule.prototype, "addon", {
727762
configurable: false,
728-
get: util.deprecate(function() {
729-
return this.options.addon;
730-
}, "ContextModule.addon has been moved to ContextModule.options.addon"),
731-
set: util.deprecate(function(value) {
732-
this.options.addon = value;
733-
}, "ContextModule.addon has been moved to ContextModule.options.addon")
763+
get: util.deprecate(
764+
/**
765+
* @deprecated
766+
* @this {ContextModule}
767+
* @returns {string} addon
768+
*/
769+
function() {
770+
return this.options.addon;
771+
},
772+
"ContextModule.addon has been moved to ContextModule.options.addon"
773+
),
774+
set: util.deprecate(
775+
/**
776+
* @deprecated
777+
* @this {ContextModule}
778+
* @param {string} value addon
779+
* @returns {void}
780+
*/
781+
function(value) {
782+
this.options.addon = value;
783+
},
784+
"ContextModule.addon has been moved to ContextModule.options.addon"
785+
)
734786
});
735787

736788
// TODO remove in webpack 5
737789
Object.defineProperty(ContextModule.prototype, "async", {
738790
configurable: false,
739-
get: util.deprecate(function() {
740-
return this.options.mode;
741-
}, "ContextModule.async has been moved to ContextModule.options.mode"),
742-
set: util.deprecate(function(value) {
743-
this.options.mode = value;
744-
}, "ContextModule.async has been moved to ContextModule.options.mode")
791+
get: util.deprecate(
792+
/**
793+
* @deprecated
794+
* @this {ContextModule}
795+
* @returns {boolean} is async
796+
*/
797+
function() {
798+
return this.options.mode;
799+
},
800+
"ContextModule.async has been moved to ContextModule.options.mode"
801+
),
802+
set: util.deprecate(
803+
/**
804+
* @deprecated
805+
* @this {ContextModule}
806+
* @param {ContextMode} value Context mode
807+
* @returns {void}
808+
*/
809+
function(value) {
810+
this.options.mode = value;
811+
},
812+
"ContextModule.async has been moved to ContextModule.options.mode"
813+
)
745814
});
746815

747816
// TODO remove in webpack 5
748817
Object.defineProperty(ContextModule.prototype, "chunkName", {
749818
configurable: false,
750-
get: util.deprecate(function() {
751-
return this.options.chunkName;
752-
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"),
753-
set: util.deprecate(function(value) {
754-
this.options.chunkName = value;
755-
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName")
819+
get: util.deprecate(
820+
/**
821+
* @deprecated
822+
* @this {ContextModule}
823+
* @returns {string} chunk name
824+
*/
825+
function() {
826+
return this.options.chunkName;
827+
},
828+
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
829+
),
830+
set: util.deprecate(
831+
/**
832+
* @deprecated
833+
* @this {ContextModule}
834+
* @param {string} value chunk name
835+
* @returns {void}
836+
*/
837+
function(value) {
838+
this.options.chunkName = value;
839+
},
840+
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
841+
)
756842
});
757843

758844
module.exports = ContextModule;

0 commit comments

Comments
 (0)