Skip to content

Commit

Permalink
refactor(types): more
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 21, 2023
1 parent e381884 commit a911bd9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/AsyncDependenciesBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AsyncDependenciesBlock extends DependenciesBlock {
/**
* @param {ChunkGroupOptions & { entryOptions?: EntryOptions }} groupOptions options for the group
* @param {DependencyLocation=} loc the line of code
* @param {string=} request the request
* @param {(string | null)=} request the request
*/
constructor(groupOptions, loc, request) {
super();
Expand Down
5 changes: 4 additions & 1 deletion lib/DllEntryPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class DllEntryPlugin {
this.options.name
),
this.options,
callback
error => {
if (error) return callback(error);
callback();
}
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dependencies/HarmonyTopLevelThisParserPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HarmonyTopLevelThisParserPlugin {
);
dep.loc = /** @type {DependencyLocation} */ (node.loc);
parser.state.module.addPresentationalDependency(dep);
return this;
return true;
}
});
}
Expand Down
5 changes: 4 additions & 1 deletion lib/dependencies/ProvidedDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ModuleDependency = require("./ModuleDependency");
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
Expand Down Expand Up @@ -127,7 +128,9 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
}
) {
const dep = /** @type {ProvidedDependency} */ (dependency);
const connection = moduleGraph.getConnection(dep);
const connection =
/** @type {ModuleGraphConnection} */
(moduleGraph.getConnection(dep));
const exportsInfo = moduleGraph.getExportsInfo(connection.module);
const usedName = exportsInfo.getUsedName(dep.ids, runtime);
initFragments.push(
Expand Down
18 changes: 13 additions & 5 deletions lib/dependencies/RequireContextDependencyParserPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@

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

/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */

module.exports = class RequireContextDependencyParserPlugin {
/**
* @param {JavascriptParser} parser the parser
* @returns {void}
*/
apply(parser) {
parser.hooks.call
.for("require.context")
Expand All @@ -19,19 +27,19 @@ module.exports = class RequireContextDependencyParserPlugin {
case 4: {
const modeExpr = parser.evaluateExpression(expr.arguments[3]);
if (!modeExpr.isString()) return;
mode = modeExpr.string;
mode = /** @type {string} */ (modeExpr.string);
}
// falls through
case 3: {
const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
if (!regExpExpr.isRegExp()) return;
regExp = regExpExpr.regExp;
regExp = /** @type {RegExp} */ (regExpExpr.regExp);
}
// falls through
case 2: {
const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
if (!recursiveExpr.isBoolean()) return;
recursive = recursiveExpr.bool;
recursive = /** @type {boolean} */ (recursiveExpr.bool);
}
// falls through
case 1: {
Expand All @@ -45,9 +53,9 @@ module.exports = class RequireContextDependencyParserPlugin {
mode,
category: "commonjs"
},
expr.range
/** @type {Range} */ (expr.range)
);
dep.loc = expr.loc;
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
dep.optional = !!parser.scope.inTry;
parser.state.current.addDependency(dep);
return true;
Expand Down
7 changes: 5 additions & 2 deletions lib/dependencies/RequireEnsureDependenciesBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
const makeSerializable = require("../util/makeSerializable");

/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */

class RequireEnsureDependenciesBlock extends AsyncDependenciesBlock {
/**
* @param {TODO} chunkName chunk name
* @param {TODO} loc location info
* @param {ChunkGroupOptions & { entryOptions?: TODO }} chunkName chunk name
* @param {DependencyLocation} loc location info
*/
constructor(chunkName, loc) {
super(chunkName, loc, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const RequireEnsureDependency = require("./RequireEnsureDependency");
const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
const getFunctionExpression = require("./getFunctionExpression");

/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */

module.exports = class RequireEnsureDependenciesBlockParserPlugin {
apply(parser) {
parser.hooks.call
Expand Down Expand Up @@ -57,7 +60,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
}

const depBlock = new RequireEnsureDependenciesBlock(
chunkName,
/** @type {ChunkGroupOptions & { entryOptions?: TODO }} */ (
chunkName
),
expr.loc
);
const errorCallbackExists =
Expand Down
4 changes: 4 additions & 0 deletions lib/dependencies/RequireHeaderDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class RequireHeaderDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
* @returns {RequireHeaderDependency} RequireHeaderDependency
*/
static deserialize(context) {
const obj = new RequireHeaderDependency(context.read());
obj.deserialize(context);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"allowJs": true,
"checkJs": true,
"noEmit": true,
"strict": true,
"strict": false,
"noImplicitThis": true,
"alwaysStrict": true,
"types": ["node"],
Expand Down
4 changes: 2 additions & 2 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ declare class AsyncDependenciesBlock extends DependenciesBlock {
entryOptions?: EntryOptions;
},
loc?: SyntheticDependencyLocation | RealDependencyLocation,
request?: string
request?: null | string
);
groupOptions: RawChunkGroupOptions & { name?: string } & {
entryOptions?: EntryOptions;
};
loc?: SyntheticDependencyLocation | RealDependencyLocation;
request?: string;
request?: null | string;
chunkName?: string;
module: any;
}
Expand Down

0 comments on commit a911bd9

Please sign in to comment.