| | |
| | | /** @typedef {import("estree").SourceLocation} SourceLocation */ |
| | | /** @typedef {import("estree").SpreadElement} SpreadElement */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ |
| | | /** @typedef {import("../Dependency")} Dependency */ |
| | | /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ |
| | | /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */ |
| | | /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ |
| | | /** @typedef {import("../javascript/JavascriptParser").Range} Range */ |
| | | /** @typedef {import("./LocalModule")} LocalModule */ |
| | | |
| | | const PLUGIN_NAME = "AMDRequireDependenciesBlockParserPlugin"; |
| | | |
| | | class AMDRequireDependenciesBlockParserPlugin { |
| | | /** |
| | | * Creates an instance of AMDRequireDependenciesBlockParserPlugin. |
| | | * @param {JavascriptParserOptions} options parserOptions |
| | | */ |
| | | constructor(options) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Process function argument. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {Expression | SpreadElement} expression expression |
| | | * @returns {boolean} need bind this |
| | |
| | | let bindThis = true; |
| | | const fnData = getFunctionExpression(expression); |
| | | if (fnData) { |
| | | parser.inScope( |
| | | parser.inFunctionScope( |
| | | true, |
| | | fnData.fn.params.filter( |
| | | (i) => |
| | | !["require", "module", "exports"].includes( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided parser. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {CallExpression} expr call expression |
| | | * @param {BasicEvaluatedExpression} param param |
| | |
| | | } else if (param.isConstArray()) { |
| | | /** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */ |
| | | const deps = []; |
| | | for (const request of /** @type {EXPECTED_ANY[]} */ (param.array)) { |
| | | for (const request of /** @type {string[]} */ (param.array)) { |
| | | /** @type {string | LocalModuleDependency | AMDRequireItemDependency} */ |
| | | let dep; |
| | | /** @type {undefined | null | LocalModule} */ |
| | | let localModule; |
| | | if (request === "require") { |
| | | dep = RuntimeGlobals.require; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided parser. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {CallExpression} expr call expression |
| | | * @param {BasicEvaluatedExpression} param param |
| | |
| | | } |
| | | return true; |
| | | } else if (param.isString()) { |
| | | /** @type {Dependency} */ |
| | | let dep; |
| | | /** @type {LocalModule | null | undefined} */ |
| | | let localModule; |
| | | if (param.string === "require") { |
| | | dep = new ConstDependency( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided parser. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {CallExpression} expr call expression |
| | | * @param {BasicEvaluatedExpression} param param |
| | |
| | | } |
| | | |
| | | /** |
| | | * Process array for request string. |
| | | * @param {BasicEvaluatedExpression} param param |
| | | * @returns {string | undefined} result |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Process item for request string. |
| | | * @param {BasicEvaluatedExpression} param param |
| | | * @returns {string | undefined} result |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Process call require. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {CallExpression} expr call expression |
| | | * @returns {boolean | undefined} result |
| | |
| | | } |
| | | |
| | | if (expr.arguments.length === 1) { |
| | | parser.inScope([], () => { |
| | | parser.inFunctionScope(true, [], () => { |
| | | result = this.processArray( |
| | | parser, |
| | | expr, |
| | |
| | | |
| | | if (expr.arguments.length === 2 || expr.arguments.length === 3) { |
| | | try { |
| | | parser.inScope([], () => { |
| | | parser.inFunctionScope(true, [], () => { |
| | | result = this.processArray( |
| | | parser, |
| | | expr, |
| | |
| | | } |
| | | |
| | | /** |
| | | * New require dependencies block. |
| | | * @param {DependencyLocation} loc location |
| | | * @param {string=} request request |
| | | * @returns {AMDRequireDependenciesBlock} AMDRequireDependenciesBlock |
| | |
| | | } |
| | | |
| | | /** |
| | | * New require dependency. |
| | | * @param {Range} outerRange outer range |
| | | * @param {Range} arrayRange array range |
| | | * @param {Range | null} functionRange function range |
| | |
| | | } |
| | | |
| | | /** |
| | | * New require item dependency. |
| | | * @param {string} request request |
| | | * @param {Range=} range range |
| | | * @returns {AMDRequireItemDependency} AMDRequireItemDependency |
| | |
| | | } |
| | | |
| | | /** |
| | | * New require array dependency. |
| | | * @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array |
| | | * @param {Range} range range |
| | | * @returns {AMDRequireArrayDependency} AMDRequireArrayDependency |