Skip to content

Commit 51fa786

Browse files
authored
Merge pull request webpack#7117 from webpack/feature/template-type-support
Feature/template type support
2 parents c39c963 + a9c771a commit 51fa786

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/Chunk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class Chunk {
128128
this.chunkReason = undefined;
129129
/** @type {boolean} */
130130
this.extraAsync = false;
131+
this.removedModules = undefined;
131132
}
132133

133134
/**

lib/Module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const ModuleReason = require("./ModuleReason");
1111
const SortableSet = require("./util/SortableSet");
1212
const Template = require("./Template");
1313

14-
/** @typedef {typeof import("./Chunk")} Chunk */
15-
/** @typedef {typeof import("./RequestShortener")} RequestShortener */
14+
/** @typedef {import("./Chunk")} Chunk */
15+
/** @typedef {import("./RequestShortener")} RequestShortener */
1616

1717
const EMPTY_RESOLVE_OPTIONS = {};
1818

@@ -69,7 +69,7 @@ class Module extends DependenciesBlock {
6969
this._chunks = new SortableSet(undefined, sortById);
7070

7171
// Info from Compilation (per Compilation)
72-
/** @type {number | string} */
72+
/** @type {number|string} */
7373
this.id = null;
7474
/** @type {number} */
7575
this.index = null;

lib/Template.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ const stringifyIdSortPredicate = (a, b) => {
4444
return 0;
4545
};
4646

47-
//TODO: Change type to Module when import works
48-
//https://github.com/Microsoft/TypeScript/issues/23375
4947
/**
50-
* @param {HasId} module the module to compare against
48+
* @param {Module} module the module to compare against
5149
* @returns {boolean} return true if module.id is equal to type "number"
5250
*/
5351
const moduleIdIsNumber = module => {
@@ -177,17 +175,19 @@ class Template {
177175

178176
/**
179177
*
180-
* @param {HasId[]} modules - a collection of modules to get array bounds for
178+
* @param {Module[]} modules a collection of modules to get array bounds for
181179
* @returns {[number, number] | false} returns the upper and lower array bounds
182180
* or false if not every module has a number based id
183181
*/
184182
static getModulesArrayBounds(modules) {
183+
// Typeguards don't work for .every() with predicate functions
184+
// https://github.com/Microsoft/TypeScript/issues/23799
185185
if (!modules.every(moduleIdIsNumber)) return false;
186186
var maxId = -Infinity;
187187
var minId = Infinity;
188188
for (const module of modules) {
189-
if (maxId < module.id) maxId = module.id;
190-
if (minId > module.id) minId = module.id;
189+
if (maxId < module.id) maxId = /** @type {number} */ (module.id);
190+
if (minId > module.id) minId = /** @type {number} */ (module.id);
191191
}
192192
if (minId < 16 + ("" + minId).length) {
193193
// add minId x ',' instead of 'Array(minId).concat(…)'
@@ -206,7 +206,6 @@ class Template {
206206
}
207207

208208
/**
209-
*
210209
* @param {Chunk} chunk chunk whose modules will be rendered
211210
* @param {ModuleFilterPredicate} filterFn function used to filter modules from chunk to render
212211
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance used to render modules

0 commit comments

Comments
 (0)