Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: more types #17236

Merged
merged 12 commits into from May 23, 2023
5 changes: 5 additions & 0 deletions lib/DllEntryPlugin.js
Expand Up @@ -10,6 +10,11 @@ const DllEntryDependency = require("./dependencies/DllEntryDependency");
const EntryDependency = require("./dependencies/EntryDependency");

class DllEntryPlugin {
/**
* @param {string} context context
* @param {string[]} entries entry names
* @param {TODO} options options
*/
constructor(context, entries, options) {
this.context = context;
this.entries = entries;
Expand Down
4 changes: 4 additions & 0 deletions lib/PrefetchPlugin.js
Expand Up @@ -10,6 +10,10 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
/** @typedef {import("./Compiler")} Compiler */

class PrefetchPlugin {
/**
* @param {string} context context or request if context is not set
* @param {string} [request] request
*/
constructor(context, request) {
if (request) {
this.context = context;
Expand Down
12 changes: 12 additions & 0 deletions lib/SelfModuleFactory.js
Expand Up @@ -5,11 +5,23 @@

"use strict";

/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
/** @typedef {import("./ModuleGraph")} ModuleGraph */

class SelfModuleFactory {
/**
* @param {ModuleGraph} moduleGraph module graph
*/
constructor(moduleGraph) {
this.moduleGraph = moduleGraph;
}

/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {
const module = this.moduleGraph.getParentModule(data.dependencies[0]);
callback(null, {
Expand Down
2 changes: 2 additions & 0 deletions lib/css/CssParser.js
Expand Up @@ -19,6 +19,8 @@ const walkCssTokens = require("./walkCssTokens");

/** @typedef {import("../Parser").ParserState} ParserState */
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
/** @typedef {[number, number]} Range */

const CC_LEFT_CURLY = "{".charCodeAt(0);
const CC_RIGHT_CURLY = "}".charCodeAt(0);
const CC_COLON = ":".charCodeAt(0);
Expand Down
11 changes: 11 additions & 0 deletions lib/debug/ProfilingPlugin.js
Expand Up @@ -17,6 +17,7 @@ const createSchemaValidation = require("../util/create-schema-validation");
const { dirname, mkdirpSync } = require("../util/fs");

/** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */

const validate = createSchemaValidation(
Expand Down Expand Up @@ -72,6 +73,11 @@ class Profiler {
]);
}

/**
* @param {string} method method name
* @param {object} [params] params
* @returns {Promise<TODO>} Promise for the result
*/
sendCommand(method, params) {
if (this.hasSession()) {
return new Promise((res, rej) => {
Expand Down Expand Up @@ -203,6 +209,11 @@ class ProfilingPlugin {
this.outputPath = options.outputPath || "events.json";
}

/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
const tracer = createTrace(
compiler.intermediateFileSystem,
Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/AMDDefineDependency.js
Expand Up @@ -12,6 +12,7 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

Expand Down Expand Up @@ -107,6 +108,13 @@ const DEFINITIONS = {
};

class AMDDefineDependency extends NullDependency {
/**
* @param {Range} range range
* @param {Range} arrayRange array range
* @param {Range} functionRange function range
* @param {Range} objectRange object range
* @param {boolean} namedModule true, when define is called with a name
*/
constructor(range, arrayRange, functionRange, objectRange, namedModule) {
super();
this.range = range;
Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/AMDDefineDependencyParserPlugin.js
Expand Up @@ -16,6 +16,8 @@ const DynamicExports = require("./DynamicExports");
const LocalModuleDependency = require("./LocalModuleDependency");
const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");

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

const isBoundFunctionExpression = expr => {
if (expr.type !== "CallExpression") return false;
if (expr.callee.type !== "MemberExpression") return false;
Expand Down Expand Up @@ -43,6 +45,10 @@ class AMDDefineDependencyParserPlugin {
this.options = options;
}

/**
* @param {JavascriptParser} parser the parser
* @returns {void}
*/
apply(parser) {
parser.hooks.call
.for("define")
Expand Down
7 changes: 7 additions & 0 deletions lib/dependencies/AMDPlugin.js
Expand Up @@ -32,8 +32,10 @@ const ConstDependency = require("./ConstDependency");
const LocalModuleDependency = require("./LocalModuleDependency");
const UnsupportedDependency = require("./UnsupportedDependency");

/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../javascript/JavascriptParser")} Parser */

const PLUGIN_NAME = "AMDPlugin";

Expand Down Expand Up @@ -125,6 +127,11 @@ class AMDPlugin {
);
});

/**
* @param {Parser} parser parser parser
* @param {JavascriptParserOptions} parserOptions parserOptions
* @returns {void}
*/
const handler = (parser, parserOptions) => {
if (parserOptions.amd !== undefined && !parserOptions.amd) return;

Expand Down
5 changes: 5 additions & 0 deletions lib/dependencies/AMDRequireArrayDependency.js
Expand Up @@ -12,10 +12,15 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class AMDRequireArrayDependency extends NullDependency {
/**
* @param {TODO} depsArray deps array
* @param {Range} range range
*/
constructor(depsArray, range) {
super();

Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/AMDRequireContextDependency.js
Expand Up @@ -8,10 +8,16 @@
const makeSerializable = require("../util/makeSerializable");
const ContextDependency = require("./ContextDependency");

/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class AMDRequireContextDependency extends ContextDependency {
/**
* @param {TODO} options options
* @param {Range} range range
* @param {Range} valueRange value range
*/
constructor(options, range, valueRange) {
super(options);

Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/AMDRequireDependenciesBlock.js
Expand Up @@ -8,7 +8,13 @@
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
const makeSerializable = require("../util/makeSerializable");

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

class AMDRequireDependenciesBlock extends AsyncDependenciesBlock {
/**
* @param {DependencyLocation} loc location info
* @param {string=} request request
*/
constructor(loc, request) {
super(null, loc, request);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js
Expand Up @@ -19,6 +19,8 @@ const { getLocalModule } = require("./LocalModulesHelpers");
const UnsupportedDependency = require("./UnsupportedDependency");
const getFunctionExpression = require("./getFunctionExpression");

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

class AMDRequireDependenciesBlockParserPlugin {
constructor(options) {
this.options = options;
Expand Down Expand Up @@ -50,6 +52,10 @@ class AMDRequireDependenciesBlockParserPlugin {
return bindThis;
}

/**
* @param {JavascriptParser} parser the parser
* @returns {void}
*/
apply(parser) {
parser.hooks.call
.for("require")
Expand Down
7 changes: 7 additions & 0 deletions lib/dependencies/AMDRequireDependency.js
Expand Up @@ -13,10 +13,17 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class AMDRequireDependency extends NullDependency {
/**
* @param {Range} outerRange outer range
* @param {Range} arrayRange array range
* @param {Range} functionRange function range
* @param {Range} errorCallbackRange error callback range
*/
constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
super();

Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/AMDRequireItemDependency.js
Expand Up @@ -9,7 +9,13 @@ const makeSerializable = require("../util/makeSerializable");
const ModuleDependency = require("./ModuleDependency");
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");

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

class AMDRequireItemDependency extends ModuleDependency {
/**
* @param {string} request the request string
* @param {Range} range location in source code
*/
constructor(request, range) {
super(request);

Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/CachedConstDependency.js
Expand Up @@ -18,11 +18,17 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/Hash")} Hash */

class CachedConstDependency extends NullDependency {
/**
* @param {string} expression expression
* @param {Range} range range
* @param {string} identifier identifier
*/
constructor(expression, range, identifier) {
super();

Expand Down
11 changes: 11 additions & 0 deletions lib/dependencies/CommonJsExportRequireDependency.js
Expand Up @@ -22,15 +22,26 @@ const processExportInfo = require("./processExportInfo");
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../Module")} Module */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
/** @typedef {import("./CommonJsDependencyHelpers").CommonJSDependencyBaseKeywords} CommonJSDependencyBaseKeywords */

const idsSymbol = Symbol("CommonJsExportRequireDependency.ids");

const EMPTY_OBJECT = {};

class CommonJsExportRequireDependency extends ModuleDependency {
/**
* @param {Range} range range
* @param {Range} valueRange value range
* @param {CommonJSDependencyBaseKeywords} base base
* @param {string[]} names names
* @param {string} request request
* @param {string[]} ids ids
* @param {boolean} resultUsed true, when the result is used
*/
constructor(range, valueRange, base, names, request, ids, resultUsed) {
super(request);
this.range = range;
Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/CommonJsExportsDependency.js
Expand Up @@ -16,12 +16,20 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("./CommonJsDependencyHelpers").CommonJSDependencyBaseKeywords} CommonJSDependencyBaseKeywords */

const EMPTY_OBJECT = {};

class CommonJsExportsDependency extends NullDependency {
/**
* @param {Range} range range
* @param {Range} valueRange value range
* @param {CommonJSDependencyBaseKeywords} base base
* @param {string[]} names names
*/
constructor(range, valueRange, base, names) {
super();
this.range = range;
Expand Down
4 changes: 2 additions & 2 deletions lib/dependencies/CommonJsExportsParserPlugin.js
Expand Up @@ -18,7 +18,6 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");

/** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
/** @typedef {import("estree").CallExpression} CallExpression */
/** @typedef {import("estree").Expression} ExpressionNode */
/** @typedef {import("estree").Expression} Expression */
/** @typedef {import("estree").Super} Super */

Expand Down Expand Up @@ -95,7 +94,7 @@ const isFalsyLiteral = expr => {

/**
* @param {JavascriptParser} parser the parser
* @param {ExpressionNode} expr expression
* @param {Expression} expr expression
* @returns {{ argument: BasicEvaluatedExpression, ids: string[] } | undefined} parsed call
*/
const parseRequireCall = (parser, expr) => {
Expand Down Expand Up @@ -134,6 +133,7 @@ class CommonJsExportsParserPlugin {

/**
* @param {JavascriptParser} parser the parser
* @returns {void}
*/
apply(parser) {
const enableStructuredExports = () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/dependencies/CommonJsFullRequireDependency.js
Expand Up @@ -16,14 +16,15 @@ const ModuleDependency = require("./ModuleDependency");
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */

class CommonJsFullRequireDependency extends ModuleDependency {
/**
* @param {string} request the request string
* @param {[number, number]} range location in source code
* @param {Range} range location in source code
* @param {string[]} names accessed properties on module
*/
constructor(request, range, names) {
Expand Down
14 changes: 14 additions & 0 deletions lib/dependencies/CommonJsPlugin.js
Expand Up @@ -34,9 +34,18 @@ const {
} = require("../javascript/JavascriptParserHelpers");
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");

/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../javascript/JavascriptParser")} Parser */

const PLUGIN_NAME = "CommonJsPlugin";

class CommonJsPlugin {
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(
PLUGIN_NAME,
Expand Down Expand Up @@ -162,6 +171,11 @@ class CommonJsPlugin {
);
});

/**
* @param {Parser} parser parser parser
* @param {JavascriptParserOptions} parserOptions parserOptions
* @returns {void}
*/
const handler = (parser, parserOptions) => {
if (parserOptions.commonjs !== undefined && !parserOptions.commonjs)
return;
Expand Down