| | |
| | | /** @typedef {import("estree").ObjectExpression} ObjectExpression */ |
| | | /** @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").ExportedVariableInfo} ExportedVariableInfo */ |
| | | /** @typedef {import("../javascript/JavascriptParser").Range} Range */ |
| | | /** @typedef {import("./LocalModule")} LocalModule */ |
| | | |
| | | /** |
| | | * Checks whether this object is bound function expression. |
| | | * @param {Expression | SpreadElement} expr expression |
| | | * @returns {expr is CallExpression} true if it's a bound function expression |
| | | */ |
| | |
| | | /** @typedef {FunctionExpression | ArrowFunctionExpression} UnboundFunctionExpression */ |
| | | |
| | | /** |
| | | * Checks whether this object is unbound function expression. |
| | | * @param {Expression | SpreadElement} expr expression |
| | | * @returns {expr is FunctionExpression | ArrowFunctionExpression} true when unbound function expression |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Checks whether this object is callable. |
| | | * @param {Expression | SpreadElement} expr expression |
| | | * @returns {expr is FunctionExpression | ArrowFunctionExpression | CallExpression} true when callable |
| | | */ |
| | |
| | | |
| | | class AMDDefineDependencyParserPlugin { |
| | | /** |
| | | * Creates an instance of AMDDefineDependencyParserPlugin. |
| | | * @param {JavascriptParserOptions} options parserOptions |
| | | */ |
| | | constructor(options) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | const deps = []; |
| | | const array = /** @type {string[]} */ (param.array); |
| | | for (const [idx, request] of array.entries()) { |
| | | /** @type {string | LocalModuleDependency | AMDRequireItemDependency} */ |
| | | let dep; |
| | | /** @type {undefined | null | LocalModule} */ |
| | | let localModule; |
| | | if (request === "require") { |
| | | identifiers[idx] = request; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 {undefined | null | LocalModule} */ |
| | | let localModule; |
| | | |
| | | if (param.string === "require") { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided parser. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {CallExpression} expr call expression |
| | | * @param {BasicEvaluatedExpression} param param |
| | |
| | | } |
| | | |
| | | /** |
| | | * Process call define. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {CallExpression} expr call expression |
| | | * @returns {boolean | undefined} result |
| | |
| | | let inTry; |
| | | if (fn && isUnboundFunctionExpression(fn)) { |
| | | inTry = parser.scope.inTry; |
| | | parser.inScope(/** @type {Identifier[]} */ (fnParams), () => { |
| | | for (const [name, varInfo] of fnRenames) { |
| | | parser.setVariable(name, varInfo); |
| | | parser.inFunctionScope( |
| | | true, |
| | | /** @type {Identifier[]} */ (fnParams), |
| | | () => { |
| | | for (const [name, varInfo] of fnRenames) { |
| | | parser.setVariable(name, varInfo); |
| | | } |
| | | parser.scope.inTry = /** @type {boolean} */ (inTry); |
| | | if (fn.body.type === "BlockStatement") { |
| | | parser.detectMode(fn.body.body); |
| | | const prev = parser.prevStatement; |
| | | parser.preWalkStatement(fn.body); |
| | | parser.prevStatement = prev; |
| | | parser.walkStatement(fn.body); |
| | | } else { |
| | | parser.walkExpression(fn.body); |
| | | } |
| | | } |
| | | parser.scope.inTry = /** @type {boolean} */ (inTry); |
| | | if (fn.body.type === "BlockStatement") { |
| | | parser.detectMode(fn.body.body); |
| | | const prev = parser.prevStatement; |
| | | parser.preWalkStatement(fn.body); |
| | | parser.prevStatement = prev; |
| | | parser.walkStatement(fn.body); |
| | | } else { |
| | | parser.walkExpression(fn.body); |
| | | } |
| | | }); |
| | | ); |
| | | } else if (fn && isBoundFunctionExpression(fn)) { |
| | | inTry = parser.scope.inTry; |
| | | |
| | |
| | | /** @type {FunctionExpression} */ |
| | | (/** @type {MemberExpression} */ (fn.callee).object); |
| | | |
| | | parser.inScope( |
| | | parser.inFunctionScope( |
| | | true, |
| | | /** @type {Identifier[]} */ |
| | | (object.params).filter( |
| | | (i) => !["require", "module", "exports"].includes(i.name) |
| | |
| | | } |
| | | |
| | | /** |
| | | * New define dependency. |
| | | * @param {Range} range range |
| | | * @param {Range | null} arrayRange array range |
| | | * @param {Range | null} functionRange function range |
| | |
| | | } |
| | | |
| | | /** |
| | | * New require array dependency. |
| | | * @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array |
| | | * @param {Range} range range |
| | | * @returns {AMDRequireArrayDependency} AMDRequireArrayDependency |
| | |
| | | } |
| | | |
| | | /** |
| | | * New require item dependency. |
| | | * @param {string} request request |
| | | * @param {Range=} range range |
| | | * @returns {AMDRequireItemDependency} AMDRequireItemDependency |