Skip to content

Commit a911bd9

Browse files
refactor(types): more
1 parent e381884 commit a911bd9

10 files changed

+41
-15
lines changed

lib/AsyncDependenciesBlock.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AsyncDependenciesBlock extends DependenciesBlock {
2323
/**
2424
* @param {ChunkGroupOptions & { entryOptions?: EntryOptions }} groupOptions options for the group
2525
* @param {DependencyLocation=} loc the line of code
26-
* @param {string=} request the request
26+
* @param {(string | null)=} request the request
2727
*/
2828
constructor(groupOptions, loc, request) {
2929
super();

lib/DllEntryPlugin.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class DllEntryPlugin {
5858
this.options.name
5959
),
6060
this.options,
61-
callback
61+
error => {
62+
if (error) return callback(error);
63+
callback();
64+
}
6265
);
6366
});
6467
}

lib/dependencies/HarmonyTopLevelThisParserPlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class HarmonyTopLevelThisParserPlugin {
3030
);
3131
dep.loc = /** @type {DependencyLocation} */ (node.loc);
3232
parser.state.module.addPresentationalDependency(dep);
33-
return this;
33+
return true;
3434
}
3535
});
3636
}

lib/dependencies/ProvidedDependency.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ModuleDependency = require("./ModuleDependency");
1717
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
1818
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
1919
/** @typedef {import("../ModuleGraph")} ModuleGraph */
20+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
2021
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
2122
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
2223
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -127,7 +128,9 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
127128
}
128129
) {
129130
const dep = /** @type {ProvidedDependency} */ (dependency);
130-
const connection = moduleGraph.getConnection(dep);
131+
const connection =
132+
/** @type {ModuleGraphConnection} */
133+
(moduleGraph.getConnection(dep));
131134
const exportsInfo = moduleGraph.getExportsInfo(connection.module);
132135
const usedName = exportsInfo.getUsedName(dep.ids, runtime);
133136
initFragments.push(

lib/dependencies/RequireContextDependencyParserPlugin.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77

88
const RequireContextDependency = require("./RequireContextDependency");
99

10+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
11+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
12+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
13+
1014
module.exports = class RequireContextDependencyParserPlugin {
15+
/**
16+
* @param {JavascriptParser} parser the parser
17+
* @returns {void}
18+
*/
1119
apply(parser) {
1220
parser.hooks.call
1321
.for("require.context")
@@ -19,19 +27,19 @@ module.exports = class RequireContextDependencyParserPlugin {
1927
case 4: {
2028
const modeExpr = parser.evaluateExpression(expr.arguments[3]);
2129
if (!modeExpr.isString()) return;
22-
mode = modeExpr.string;
30+
mode = /** @type {string} */ (modeExpr.string);
2331
}
2432
// falls through
2533
case 3: {
2634
const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
2735
if (!regExpExpr.isRegExp()) return;
28-
regExp = regExpExpr.regExp;
36+
regExp = /** @type {RegExp} */ (regExpExpr.regExp);
2937
}
3038
// falls through
3139
case 2: {
3240
const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
3341
if (!recursiveExpr.isBoolean()) return;
34-
recursive = recursiveExpr.bool;
42+
recursive = /** @type {boolean} */ (recursiveExpr.bool);
3543
}
3644
// falls through
3745
case 1: {
@@ -45,9 +53,9 @@ module.exports = class RequireContextDependencyParserPlugin {
4553
mode,
4654
category: "commonjs"
4755
},
48-
expr.range
56+
/** @type {Range} */ (expr.range)
4957
);
50-
dep.loc = expr.loc;
58+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
5159
dep.optional = !!parser.scope.inTry;
5260
parser.state.current.addDependency(dep);
5361
return true;

lib/dependencies/RequireEnsureDependenciesBlock.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
99
const makeSerializable = require("../util/makeSerializable");
1010

11+
/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
12+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
13+
1114
class RequireEnsureDependenciesBlock extends AsyncDependenciesBlock {
1215
/**
13-
* @param {TODO} chunkName chunk name
14-
* @param {TODO} loc location info
16+
* @param {ChunkGroupOptions & { entryOptions?: TODO }} chunkName chunk name
17+
* @param {DependencyLocation} loc location info
1518
*/
1619
constructor(chunkName, loc) {
1720
super(chunkName, loc, null);

lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const RequireEnsureDependency = require("./RequireEnsureDependency");
1010
const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
1111
const getFunctionExpression = require("./getFunctionExpression");
1212

13+
/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
14+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
15+
1316
module.exports = class RequireEnsureDependenciesBlockParserPlugin {
1417
apply(parser) {
1518
parser.hooks.call
@@ -57,7 +60,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
5760
}
5861

5962
const depBlock = new RequireEnsureDependenciesBlock(
60-
chunkName,
63+
/** @type {ChunkGroupOptions & { entryOptions?: TODO }} */ (
64+
chunkName
65+
),
6166
expr.loc
6267
);
6368
const errorCallbackExists =

lib/dependencies/RequireHeaderDependency.js

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class RequireHeaderDependency extends NullDependency {
3535
super.serialize(context);
3636
}
3737

38+
/**
39+
* @param {ObjectDeserializerContext} context context
40+
* @returns {RequireHeaderDependency} RequireHeaderDependency
41+
*/
3842
static deserialize(context) {
3943
const obj = new RequireHeaderDependency(context.read());
4044
obj.deserialize(context);

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"allowJs": true,
77
"checkJs": true,
88
"noEmit": true,
9-
"strict": true,
9+
"strict": false,
1010
"noImplicitThis": true,
1111
"alwaysStrict": true,
1212
"types": ["node"],

types.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ declare class AsyncDependenciesBlock extends DependenciesBlock {
355355
entryOptions?: EntryOptions;
356356
},
357357
loc?: SyntheticDependencyLocation | RealDependencyLocation,
358-
request?: string
358+
request?: null | string
359359
);
360360
groupOptions: RawChunkGroupOptions & { name?: string } & {
361361
entryOptions?: EntryOptions;
362362
};
363363
loc?: SyntheticDependencyLocation | RealDependencyLocation;
364-
request?: string;
364+
request?: null | string;
365365
chunkName?: string;
366366
module: any;
367367
}

0 commit comments

Comments
 (0)