From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送
---
node_modules/webpack/lib/javascript/JavascriptParser.js | 259 +++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 235 insertions(+), 24 deletions(-)
diff --git a/node_modules/webpack/lib/javascript/JavascriptParser.js b/node_modules/webpack/lib/javascript/JavascriptParser.js
index 2d7d304..89ac808 100644
--- a/node_modules/webpack/lib/javascript/JavascriptParser.js
+++ b/node_modules/webpack/lib/javascript/JavascriptParser.js
@@ -94,11 +94,26 @@
/** @typedef {import("estree").MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration */
/** @typedef {import("estree").MaybeNamedClassDeclaration} MaybeNamedClassDeclaration */
/**
+ * Defines the shared type used by this module.
* @template T
* @typedef {import("tapable").AsArray<T>} AsArray<T>
*/
/** @typedef {import("../Parser").ParserState} ParserState */
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
+
+/** @typedef {import("../dependencies/LocalModule")} LocalModule */
+/** @typedef {import("../dependencies/HarmonyExportImportedSpecifierDependency").HarmonyStarExportsList} HarmonyStarExportsList */
+
+/**
+ * Defines the known javascript parser state type used by this module.
+ * @typedef {object} KnownJavascriptParserState
+ * @property {Set<string>=} harmonyNamedExports
+ * @property {HarmonyStarExportsList=} harmonyStarExports
+ * @property {number=} lastHarmonyImportOrder
+ * @property {LocalModule[]=} localModules
+ */
+
+/** @typedef {ParserState & KnownJavascriptParserState} JavascriptParserState */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Module")} Module */
@@ -112,7 +127,7 @@
/** @typedef {Set<DestructuringAssignmentProperty>} DestructuringAssignmentProperties */
// TODO remove cast when @types/estree has been updated to import assertions
-/** @typedef {import("estree").ImportExpression & { phase?: "defer" }} ImportExpression */
+/** @typedef {import("estree").ImportExpression & { phase?: "defer" | "source" }} ImportExpression */
/** @type {string[]} */
const EMPTY_ARRAY = [];
@@ -126,6 +141,7 @@
const importAssertions = (Parser) =>
class extends Parser {
/**
+ * Parses with clause.
* @this {InstanceType<AcornParser>}
* @returns {ImportAttribute[]} import attributes
*/
@@ -191,6 +207,7 @@
/** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
/**
+ * Gets import attributes.
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
* @returns {ImportAttributes | undefined} import attributes
*/
@@ -274,6 +291,7 @@
class VariableInfo {
/**
+ * Creates an instance of VariableInfo.
* @param {ScopeInfo} declaredScope scope in which the variable is declared
* @param {string | undefined} name which name the variable use, defined name or free name or tagged name
* @param {VariableInfoFlagsType} flags how the variable is created
@@ -287,6 +305,7 @@
}
/**
+ * Checks whether this variable info is free.
* @returns {boolean} the variable is free or not
*/
isFree() {
@@ -294,6 +313,7 @@
}
/**
+ * Checks whether this variable info is tagged.
* @returns {boolean} the variable is tagged by tagVariable or not
*/
isTagged() {
@@ -305,13 +325,15 @@
/** @typedef {Literal | string | null | undefined} ImportSource */
/**
- * @typedef {Omit<ParseOptions, "sourceType"> & {sourceType: "module" | "script" | "auto"}} InternalParseOptions
+ * Defines the internal parse options type used by this module.
+ * @typedef {Omit<ParseOptions, "sourceType" | "ecmaVersion"> & { sourceType: "module" | "script" | "auto" }} InternalParseOptions
*/
/**
+ * Defines the parse options type used by this module.
* @typedef {object} ParseOptions
* @property {"module" | "script"} sourceType
- * @property {EcmaVersion=} ecmaVersion
+ * @property {EcmaVersion} ecmaVersion
* @property {boolean=} locations
* @property {boolean=} comments
* @property {boolean=} ranges
@@ -321,6 +343,7 @@
*/
/**
+ * Defines the parse result type used by this module.
* @typedef {object} ParseResult
* @property {Program} ast
* @property {Comment[]} comments
@@ -328,21 +351,24 @@
*/
/**
+ * Defines the parse function type used by this module.
* @typedef {(code: string, options: ParseOptions) => ParseResult} ParseFunction
*/
/** @typedef {symbol} Tag */
/** @typedef {import("../dependencies/HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
+/** @typedef {import("../dependencies/HarmonyImportDependencyParserPlugin").HarmonySpecifierGuards} HarmonySpecifierGuards */
/** @typedef {import("../dependencies/ImportParserPlugin").ImportSettings} ImportSettings */
/** @typedef {import("../dependencies/CommonJsImportsParserPlugin").CommonJsImportSettings} CommonJsImportSettings */
/** @typedef {import("../CompatibilityPlugin").CompatibilitySettings} CompatibilitySettings */
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
-/** @typedef {HarmonySettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings} KnownTagData */
+/** @typedef {HarmonySettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings | HarmonySpecifierGuards} KnownTagData */
/** @typedef {KnownTagData | Record<string, EXPECTED_ANY>} TagData */
/**
+ * Defines the tag info type used by this module.
* @typedef {object} TagInfo
* @property {Tag} tag
* @property {TagData=} data
@@ -358,6 +384,7 @@
const SCOPE_INFO_TERMINATED_THROW = 2;
/**
+ * Defines the scope info type used by this module.
* @typedef {object} ScopeInfo
* @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
* @property {boolean | "arrow"} topLevelScope
@@ -372,6 +399,7 @@
/** @typedef {[number, number]} Range */
/**
+ * Defines the destructuring assignment property type used by this module.
* @typedef {object} DestructuringAssignmentProperty
* @property {string} id
* @property {Range} range
@@ -465,6 +493,7 @@
class JavascriptParser extends Parser {
/**
+ * Creates an instance of JavascriptParser.
* @param {"module" | "script" | "auto"=} sourceType default source type
* @param {{ parse?: ParseFunction }=} options parser options
*/
@@ -506,6 +535,8 @@
statement: new SyncBailHook(["statement"]),
/** @type {SyncBailHook<[IfStatement], boolean | void>} */
statementIf: new SyncBailHook(["statement"]),
+ /** @type {SyncBailHook<[Expression], ((walk: () => void) => void) | void>} */
+ collectGuards: new SyncBailHook(["expression"]),
/** @type {SyncBailHook<[Expression, ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration], boolean | void>} */
classExtendsExpression: new SyncBailHook([
"expression",
@@ -666,7 +697,7 @@
/** @type {ScopeInfo} */
this.scope = /** @type {EXPECTED_ANY} */ (undefined);
- /** @type {ParserState} */
+ /** @type {JavascriptParserState} */
this.state = /** @type {EXPECTED_ANY} */ (undefined);
/** @type {Comment[] | undefined} */
this.comments = undefined;
@@ -734,6 +765,7 @@
return;
}
+ /** @type {undefined | string} */
let regExp;
const arg1 = expr.arguments[0];
@@ -756,6 +788,7 @@
);
}
+ /** @type {undefined | string} */
let flags;
const arg2 = expr.arguments[1];
@@ -938,6 +971,7 @@
(a === true && b === false) || (a === false && b === true);
/**
+ * Handle template string compare.
* @param {BasicEvaluatedExpression} left left
* @param {BasicEvaluatedExpression} right right
* @param {BasicEvaluatedExpression} res res
@@ -946,6 +980,7 @@
*/
const handleTemplateStringCompare = (left, right, res, eql) => {
/**
+ * Returns value.
* @param {BasicEvaluatedExpression[]} parts parts
* @returns {string} value
*/
@@ -959,6 +994,7 @@
return value;
};
/**
+ * Returns value.
* @param {BasicEvaluatedExpression[]} parts parts
* @returns {string} value
*/
@@ -1442,6 +1478,7 @@
}
});
/**
+ * Tap evaluate with variable info.
* @param {"Identifier" | "ThisExpression" | "MemberExpression"} exprType expression type name
* @param {(node: Expression | SpreadElement) => GetInfoResult | undefined} getInfo get info
* @returns {void}
@@ -1584,7 +1621,7 @@
const arg1Eval = this.evaluateExpression(arg1);
if (!arg1Eval.isString()) return;
const arg1Value = /** @type {string} */ (arg1Eval.string);
-
+ /** @type {number} */
let result;
if (arg2) {
if (arg2.type === "SpreadElement") return;
@@ -1629,7 +1666,9 @@
.for(fn)
.tap(CLASS_NAME, (expr, param) => {
if (!param.isString()) return;
+ /** @type {BasicEvaluatedExpression} */
let arg1;
+ /** @type {string} */
let result;
const str = /** @type {string} */ (param.string);
switch (expr.arguments.length) {
@@ -1667,9 +1706,10 @@
}
/**
+ * Gets simplified template result.
* @param {"cooked" | "raw"} kind kind of values to get
* @param {TemplateLiteral} templateLiteralExpr TemplateLiteral expr
- * @returns {{quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[]}} Simplified template
+ * @returns {{ quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[] }} Simplified template
*/
const getSimplifiedTemplateResult = (kind, templateLiteralExpr) => {
/** @type {BasicEvaluatedExpression[]} */
@@ -1751,7 +1791,8 @@
.for("concat")
.tap(CLASS_NAME, (expr, param) => {
if (!param.isString() && !param.isWrapped()) return;
- let stringSuffix = null;
+ /** @type {undefined | BasicEvaluatedExpression} */
+ let stringSuffix;
let hasUnknownParams = false;
/** @type {BasicEvaluatedExpression[]} */
const innerExpressions = [];
@@ -1827,6 +1868,7 @@
if (!param.isString()) return;
if (expr.arguments.length !== 1) return;
if (expr.arguments[0].type === "SpreadElement") return;
+ /** @type {string[]} */
let result;
const arg = this.evaluateExpression(expr.arguments[0]);
if (arg.isString()) {
@@ -1852,6 +1894,7 @@
const condition = this.evaluateExpression(expr.test);
const conditionValue = condition.asBool();
+ /** @type {BasicEvaluatedExpression} */
let res;
if (conditionValue === undefined) {
const consequent = this.evaluateExpression(expr.consequent);
@@ -1898,7 +1941,7 @@
const expr = /** @type {ChainExpression} */ (_expr);
/** @type {Expression[]} */
const optionalExpressionsStack = [];
- /** @type {Expression|Super} */
+ /** @type {Expression | Super} */
let next = expr.expression;
while (
@@ -1939,6 +1982,7 @@
}
/**
+ * Destructuring assignment properties for.
* @param {Expression} node node
* @returns {DestructuringAssignmentProperties | undefined} destructured identifiers
*/
@@ -1948,6 +1992,7 @@
}
/**
+ * Gets rename identifier.
* @param {Expression | SpreadElement} expr expression
* @returns {string | VariableInfo | undefined} identifier
*/
@@ -1959,6 +2004,7 @@
}
/**
+ * Processes the provided classy.
* @param {ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration} classy a class node
* @returns {void}
*/
@@ -1970,6 +2016,7 @@
this.walkExpression(classy.superClass);
}
if (classy.body && classy.body.type === "ClassBody") {
+ /** @type {Identifier[]} */
const scopeParams = [];
// Add class name in scope for recursive calls
if (classy.id) {
@@ -2142,6 +2189,7 @@
}
/**
+ * Block pre walk statement.
* @param {Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration} statement statement
*/
blockPreWalkStatement(statement) {
@@ -2175,6 +2223,7 @@
}
/**
+ * Processes the provided statement.
* @param {Statement | ModuleDeclaration | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} statement statement
*/
walkStatement(statement) {
@@ -2263,6 +2312,7 @@
// Real Statements
/**
+ * Pre walk block statement.
* @param {BlockStatement} statement block statement
*/
preWalkBlockStatement(statement) {
@@ -2270,6 +2320,7 @@
}
/**
+ * Walk block statement.
* @param {BlockStatement | StaticBlock} statement block statement
*/
walkBlockStatement(statement) {
@@ -2283,6 +2334,7 @@
}
/**
+ * Walk expression statement.
* @param {ExpressionStatement} statement expression statement
*/
walkExpressionStatement(statement) {
@@ -2290,6 +2342,7 @@
}
/**
+ * Pre walk if statement.
* @param {IfStatement} statement if statement
*/
preWalkIfStatement(statement) {
@@ -2300,13 +2353,22 @@
}
/**
+ * Processes the provided statement.
* @param {IfStatement} statement if statement
*/
walkIfStatement(statement) {
const result = this.hooks.statementIf.call(statement);
if (result === undefined) {
- this.walkExpression(statement.test);
- this.walkNestedStatement(statement.consequent);
+ const inGuard = this.hooks.collectGuards.call(statement.test);
+ if (inGuard) {
+ inGuard(() => {
+ this.walkExpression(statement.test);
+ this.walkNestedStatement(statement.consequent);
+ });
+ } else {
+ this.walkExpression(statement.test);
+ this.walkNestedStatement(statement.consequent);
+ }
const consequentTerminated = this.scope.terminated;
this.scope.terminated = undefined;
@@ -2329,6 +2391,7 @@
}
/**
+ * Pre walk labeled statement.
* @param {LabeledStatement} statement with statement
*/
preWalkLabeledStatement(statement) {
@@ -2336,6 +2399,7 @@
}
/**
+ * Walk labeled statement.
* @param {LabeledStatement} statement with statement
*/
walkLabeledStatement(statement) {
@@ -2350,6 +2414,7 @@
}
/**
+ * Pre walk with statement.
* @param {WithStatement} statement with statement
*/
preWalkWithStatement(statement) {
@@ -2357,6 +2422,7 @@
}
/**
+ * Walk with statement.
* @param {WithStatement} statement with statement
*/
walkWithStatement(statement) {
@@ -2367,6 +2433,7 @@
}
/**
+ * Pre walk switch statement.
* @param {SwitchStatement} statement switch statement
*/
preWalkSwitchStatement(statement) {
@@ -2374,6 +2441,7 @@
}
/**
+ * Walk switch statement.
* @param {SwitchStatement} statement switch statement
*/
walkSwitchStatement(statement) {
@@ -2382,6 +2450,7 @@
}
/**
+ * Walk terminating statement.
* @param {ReturnStatement | ThrowStatement} statement return or throw statement
*/
walkTerminatingStatement(statement) {
@@ -2397,6 +2466,7 @@
}
/**
+ * Walk return statement.
* @param {ReturnStatement} statement return statement
*/
walkReturnStatement(statement) {
@@ -2404,6 +2474,7 @@
}
/**
+ * Walk throw statement.
* @param {ThrowStatement} statement return statement
*/
walkThrowStatement(statement) {
@@ -2411,6 +2482,7 @@
}
/**
+ * Pre walk try statement.
* @param {TryStatement} statement try statement
*/
preWalkTryStatement(statement) {
@@ -2420,6 +2492,7 @@
}
/**
+ * Walk try statement.
* @param {TryStatement} statement try statement
*/
walkTryStatement(statement) {
@@ -2457,6 +2530,7 @@
}
/**
+ * Pre walk while statement.
* @param {WhileStatement} statement while statement
*/
preWalkWhileStatement(statement) {
@@ -2464,6 +2538,7 @@
}
/**
+ * Walk while statement.
* @param {WhileStatement} statement while statement
*/
walkWhileStatement(statement) {
@@ -2474,6 +2549,7 @@
}
/**
+ * Pre walk do while statement.
* @param {DoWhileStatement} statement do while statement
*/
preWalkDoWhileStatement(statement) {
@@ -2481,6 +2557,7 @@
}
/**
+ * Walk do while statement.
* @param {DoWhileStatement} statement do while statement
*/
walkDoWhileStatement(statement) {
@@ -2491,6 +2568,7 @@
}
/**
+ * Pre walk for statement.
* @param {ForStatement} statement for statement
*/
preWalkForStatement(statement) {
@@ -2501,6 +2579,7 @@
}
/**
+ * Walk for statement.
* @param {ForStatement} statement for statement
*/
walkForStatement(statement) {
@@ -2536,6 +2615,7 @@
}
/**
+ * Pre walk for in statement.
* @param {ForInStatement} statement for statement
*/
preWalkForInStatement(statement) {
@@ -2546,6 +2626,7 @@
}
/**
+ * Walk for in statement.
* @param {ForInStatement} statement for statement
*/
walkForInStatement(statement) {
@@ -2574,6 +2655,7 @@
}
/**
+ * Pre walk for of statement.
* @param {ForOfStatement} statement statement
*/
preWalkForOfStatement(statement) {
@@ -2587,6 +2669,7 @@
}
/**
+ * Walk for of statement.
* @param {ForOfStatement} statement for statement
*/
walkForOfStatement(statement) {
@@ -2615,6 +2698,7 @@
}
/**
+ * Pre walk function declaration.
* @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
*/
preWalkFunctionDeclaration(statement) {
@@ -2624,6 +2708,7 @@
}
/**
+ * Walk function declaration.
* @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
*/
walkFunctionDeclaration(statement) {
@@ -2646,6 +2731,7 @@
}
/**
+ * Block pre walk expression statement.
* @param {ExpressionStatement} statement expression statement
*/
blockPreWalkExpressionStatement(statement) {
@@ -2657,6 +2743,7 @@
}
/**
+ * Pre walk assignment expression.
* @param {AssignmentExpression} expression assignment expression
*/
preWalkAssignmentExpression(expression) {
@@ -2664,6 +2751,7 @@
}
/**
+ * Enter destructuring assignment.
* @param {Pattern} pattern pattern
* @param {Expression} expression assignment expression
* @returns {Expression | undefined} destructuring expression
@@ -2705,6 +2793,7 @@
}
/**
+ * Module pre walk import declaration.
* @param {ImportDeclaration} statement statement
*/
modulePreWalkImportDeclaration(statement) {
@@ -2750,6 +2839,7 @@
}
/**
+ * Processes the provided declaration.
* @param {Declaration} declaration declaration
* @param {OnIdent} onIdent on ident callback
*/
@@ -2775,6 +2865,7 @@
}
/**
+ * Module pre walk export named declaration.
* @param {ExportNamedDeclaration} statement statement
*/
modulePreWalkExportNamedDeclaration(statement) {
@@ -2815,6 +2906,7 @@
}
/**
+ * Block pre walk export named declaration.
* @param {ExportNamedDeclaration} statement statement
*/
blockPreWalkExportNamedDeclaration(statement) {
@@ -2866,6 +2958,7 @@
}
/**
+ * Walk export named declaration.
* @param {ExportNamedDeclaration} statement the statement
*/
walkExportNamedDeclaration(statement) {
@@ -2875,6 +2968,7 @@
}
/**
+ * Block pre walk export default declaration.
* @param {ExportDefaultDeclaration} statement statement
*/
blockPreWalkExportDefaultDeclaration(statement) {
@@ -2910,6 +3004,7 @@
}
/**
+ * Walk export default declaration.
* @param {ExportDefaultDeclaration} statement statement
*/
walkExportDefaultDeclaration(statement) {
@@ -2944,6 +3039,7 @@
}
/**
+ * Module pre walk export all declaration.
* @param {ExportAllDeclaration} statement statement
*/
modulePreWalkExportAllDeclaration(statement) {
@@ -2959,6 +3055,7 @@
}
/**
+ * Pre walk variable declaration.
* @param {VariableDeclaration} statement variable declaration
*/
preWalkVariableDeclaration(statement) {
@@ -2967,6 +3064,7 @@
}
/**
+ * Block pre walk variable declaration.
* @param {VariableDeclaration} statement variable declaration
*/
blockPreWalkVariableDeclaration(statement) {
@@ -2982,6 +3080,7 @@
}
/**
+ * Pre walk variable declaration.
* @param {VariableDeclaration} statement variable declaration
* @param {HookMap<SyncBailHook<[Identifier], boolean | void>>} hookMap map of hooks
*/
@@ -3008,6 +3107,7 @@
}
/**
+ * Pre walk object pattern.
* @param {ObjectPattern} objectPattern object pattern
* @returns {DestructuringAssignmentProperties | undefined} set of names or undefined if not all keys are identifiers
*/
@@ -3072,6 +3172,7 @@
}
/**
+ * Pre walk array pattern.
* @param {ArrayPattern} arrayPattern array pattern
* @returns {Set<DestructuringAssignmentProperty> | undefined} set of names or undefined if not all keys are identifiers
*/
@@ -3102,6 +3203,7 @@
}
/**
+ * Pre walk variable declarator.
* @param {VariableDeclarator} declarator variable declarator
*/
preWalkVariableDeclarator(declarator) {
@@ -3111,6 +3213,7 @@
}
/**
+ * Walk variable declaration.
* @param {VariableDeclaration} statement variable declaration
*/
walkVariableDeclaration(statement) {
@@ -3147,6 +3250,7 @@
}
/**
+ * Block pre walk class declaration.
* @param {ClassDeclaration | MaybeNamedClassDeclaration} statement class declaration
*/
blockPreWalkClassDeclaration(statement) {
@@ -3156,6 +3260,7 @@
}
/**
+ * Walk class declaration.
* @param {ClassDeclaration | MaybeNamedClassDeclaration} statement class declaration
*/
walkClassDeclaration(statement) {
@@ -3163,6 +3268,7 @@
}
/**
+ * Pre walk switch cases.
* @param {SwitchCase[]} switchCases switch statement
*/
preWalkSwitchCases(switchCases) {
@@ -3173,6 +3279,7 @@
}
/**
+ * Processes the provided switch case.
* @param {SwitchCase[]} switchCases switch statement
*/
walkSwitchCases(switchCases) {
@@ -3213,6 +3320,7 @@
}
/**
+ * Pre walk catch clause.
* @param {CatchClause} catchClause catch clause
*/
preWalkCatchClause(catchClause) {
@@ -3220,6 +3328,7 @@
}
/**
+ * Processes the provided catch clause.
* @param {CatchClause} catchClause catch clause
*/
walkCatchClause(catchClause) {
@@ -3239,6 +3348,7 @@
}
/**
+ * Processes the provided pattern.
* @param {Pattern} pattern pattern
*/
walkPattern(pattern) {
@@ -3262,6 +3372,7 @@
}
/**
+ * Walk assignment pattern.
* @param {AssignmentPattern} pattern assignment pattern
*/
walkAssignmentPattern(pattern) {
@@ -3270,6 +3381,7 @@
}
/**
+ * Walk object pattern.
* @param {ObjectPattern} pattern pattern
*/
walkObjectPattern(pattern) {
@@ -3286,6 +3398,7 @@
}
/**
+ * Walk array pattern.
* @param {ArrayPattern} pattern array pattern
*/
walkArrayPattern(pattern) {
@@ -3296,6 +3409,7 @@
}
/**
+ * Processes the provided pattern.
* @param {RestElement} pattern rest element
*/
walkRestElement(pattern) {
@@ -3303,6 +3417,7 @@
}
/**
+ * Processes the provided expression.
* @param {(Expression | SpreadElement | null)[]} expressions expressions
*/
walkExpressions(expressions) {
@@ -3314,6 +3429,7 @@
}
/**
+ * Processes the provided expression.
* @param {Expression | SpreadElement | PrivateIdentifier | Super} expression expression
*/
walkExpression(expression) {
@@ -3397,6 +3513,7 @@
}
/**
+ * Walk await expression.
* @param {AwaitExpression} expression await expression
*/
walkAwaitExpression(expression) {
@@ -3407,6 +3524,7 @@
}
/**
+ * Walk array expression.
* @param {ArrayExpression} expression array expression
*/
walkArrayExpression(expression) {
@@ -3416,6 +3534,7 @@
}
/**
+ * Walk spread element.
* @param {SpreadElement} expression spread element
*/
walkSpreadElement(expression) {
@@ -3425,6 +3544,7 @@
}
/**
+ * Walk object expression.
* @param {ObjectExpression} expression object expression
*/
walkObjectExpression(expression) {
@@ -3439,6 +3559,7 @@
}
/**
+ * Processes the provided prop.
* @param {Property | SpreadElement} prop property or spread element
*/
walkProperty(prop) {
@@ -3462,6 +3583,7 @@
}
/**
+ * Walk function expression.
* @param {FunctionExpression} expression arrow function expression
*/
walkFunctionExpression(expression) {
@@ -3491,6 +3613,7 @@
}
/**
+ * Walk arrow function expression.
* @param {ArrowFunctionExpression} expression arrow function expression
*/
walkArrowFunctionExpression(expression) {
@@ -3514,6 +3637,7 @@
}
/**
+ * Walk sequence expression.
* @param {SequenceExpression} expression the sequence
*/
walkSequenceExpression(expression) {
@@ -3552,6 +3676,7 @@
}
/**
+ * Walk update expression.
* @param {UpdateExpression} expression the update expression
*/
walkUpdateExpression(expression) {
@@ -3559,6 +3684,7 @@
}
/**
+ * Walk unary expression.
* @param {UnaryExpression} expression the unary expression
*/
walkUnaryExpression(expression) {
@@ -3582,6 +3708,7 @@
}
/**
+ * Walk left right expression.
* @param {LogicalExpression | BinaryExpression} expression the expression
*/
walkLeftRightExpression(expression) {
@@ -3590,6 +3717,7 @@
}
/**
+ * Walk binary expression.
* @param {BinaryExpression} expression the binary expression
*/
walkBinaryExpression(expression) {
@@ -3599,6 +3727,7 @@
}
/**
+ * Walk logical expression.
* @param {LogicalExpression} expression the logical expression
*/
walkLogicalExpression(expression) {
@@ -3611,6 +3740,7 @@
}
/**
+ * Walk assignment expression.
* @param {AssignmentExpression} expression assignment expression
*/
walkAssignmentExpression(expression) {
@@ -3686,13 +3816,22 @@
}
/**
+ * Walk conditional expression.
* @param {ConditionalExpression} expression conditional expression
*/
walkConditionalExpression(expression) {
const result = this.hooks.expressionConditionalOperator.call(expression);
if (result === undefined) {
- this.walkExpression(expression.test);
- this.walkExpression(expression.consequent);
+ const inGuard = this.hooks.collectGuards.call(expression.test);
+ if (inGuard) {
+ inGuard(() => {
+ this.walkExpression(expression.test);
+ this.walkExpression(expression.consequent);
+ });
+ } else {
+ this.walkExpression(expression.test);
+ this.walkExpression(expression.consequent);
+ }
if (expression.alternate) {
this.walkExpression(expression.alternate);
@@ -3705,6 +3844,7 @@
}
/**
+ * Walk new expression.
* @param {NewExpression} expression new expression
*/
walkNewExpression(expression) {
@@ -3721,6 +3861,7 @@
}
/**
+ * Walk yield expression.
* @param {YieldExpression} expression yield expression
*/
walkYieldExpression(expression) {
@@ -3730,6 +3871,7 @@
}
/**
+ * Walk template literal.
* @param {TemplateLiteral} expression template literal
*/
walkTemplateLiteral(expression) {
@@ -3739,6 +3881,7 @@
}
/**
+ * Walk tagged template expression.
* @param {TaggedTemplateExpression} expression tagged template expression
*/
walkTaggedTemplateExpression(expression) {
@@ -3753,6 +3896,7 @@
}
/**
+ * Walk class expression.
* @param {ClassExpression} expression the class expression
*/
walkClassExpression(expression) {
@@ -3760,6 +3904,7 @@
}
/**
+ * Walk chain expression.
* @param {ChainExpression} expression expression
*/
walkChainExpression(expression) {
@@ -3775,6 +3920,7 @@
}
/**
+ * Processes the provided function expression.
* @private
* @param {FunctionExpression | ArrowFunctionExpression} functionExpression function expression
* @param {(Expression | SpreadElement)[]} options options
@@ -3782,6 +3928,7 @@
*/
_walkIIFE(functionExpression, options, currentThis) {
/**
+ * Returns var info.
* @param {Expression | SpreadElement} argOrThis arg or this
* @returns {string | VariableInfo | undefined} var info
*/
@@ -3850,6 +3997,7 @@
}
/**
+ * Walk import expression.
* @param {ImportExpression} expression import expression
*/
walkImportExpression(expression) {
@@ -3860,10 +4008,12 @@
}
/**
+ * Walk call expression.
* @param {CallExpression} expression expression
*/
walkCallExpression(expression) {
/**
+ * Checks whether this javascript parser is simple function.
* @param {FunctionExpression | ArrowFunctionExpression} fn function
* @returns {boolean} true when simple function
*/
@@ -3979,6 +4129,7 @@
}
/**
+ * Walk member expression.
* @param {MemberExpression} expression member expression
*/
walkMemberExpression(expression) {
@@ -4045,6 +4196,7 @@
}
/**
+ * Walk member expression with expression name.
* @template R
* @param {MemberExpression} expression member expression
* @param {string} name name
@@ -4088,6 +4240,7 @@
}
/**
+ * Walk this expression.
* @param {ThisExpression} expression this expression
*/
walkThisExpression(expression) {
@@ -4095,6 +4248,7 @@
}
/**
+ * Processes the provided expression.
* @param {Identifier} expression identifier
*/
walkIdentifier(expression) {
@@ -4102,6 +4256,7 @@
}
/**
+ * Walk meta property.
* @param {MetaProperty} metaProperty meta property
*/
walkMetaProperty(metaProperty) {
@@ -4109,6 +4264,7 @@
}
/**
+ * Call hooks for expression.
* @template T
* @template R
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4127,6 +4283,7 @@
}
/**
+ * Call hooks for expression with fallback.
* @template T
* @template R
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4161,6 +4318,7 @@
}
/**
+ * Call hooks for name.
* @template T
* @template R
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4179,6 +4337,7 @@
}
/**
+ * Call hooks for info.
* @template T
* @template R
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks that should be called
@@ -4197,6 +4356,7 @@
}
/**
+ * Call hooks for info with fallback.
* @template T
* @template R
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4207,6 +4367,7 @@
* @returns {R | undefined} result of hook
*/
callHooksForInfoWithFallback(hookMap, info, fallback, defined, ...args) {
+ /** @type {string} */
let name;
if (typeof info === "string") {
name = info;
@@ -4234,7 +4395,7 @@
}
return;
}
- name = info.name;
+ name = /** @type {string} */ (info.name);
}
const hook = hookMap.get(name);
if (hook !== undefined) {
@@ -4242,11 +4403,12 @@
if (result !== undefined) return result;
}
if (fallback !== undefined) {
- return fallback(/** @type {string} */ (name));
+ return fallback(name);
}
}
/**
+ * Call hooks for name with fallback.
* @template T
* @template R
* @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4267,6 +4429,7 @@
}
/**
+ * Processes the provided param.
* @deprecated
* @param {(string | Pattern | Property)[]} params scope params
* @param {() => void} fn inner function
@@ -4297,6 +4460,7 @@
}
/**
+ * Processes the provided has thi.
* @param {boolean} hasThis true, when this is defined
* @param {Identifier[]} params scope params
* @param {() => void} fn inner function
@@ -4329,6 +4493,7 @@
}
/**
+ * Processes the provided has thi.
* @param {boolean} hasThis true, when this is defined
* @param {(Pattern | string)[]} params scope params
* @param {() => void} fn inner function
@@ -4361,6 +4526,7 @@
}
/**
+ * Processes the provided fn.
* @param {() => void} fn inner function
* @param {boolean} inExecutedPath executed state
* @returns {void}
@@ -4390,6 +4556,7 @@
}
/**
+ * Processes the provided statement.
* @param {(Directive | Statement | ModuleDeclaration)[]} statements statements
*/
detectMode(statements) {
@@ -4416,6 +4583,7 @@
}
/**
+ * Processes the provided pattern.
* @param {(string | Pattern | Property)[]} patterns patterns
* @param {OnIdentString} onIdent on ident callback
*/
@@ -4430,6 +4598,7 @@
}
/**
+ * Processes the provided pattern.
* @param {Pattern | Property} pattern pattern
* @param {OnIdent} onIdent on ident callback
*/
@@ -4464,6 +4633,7 @@
}
/**
+ * Processes the provided pattern.
* @param {Identifier} pattern identifier pattern
* @param {OnIdent} onIdent callback
*/
@@ -4474,6 +4644,7 @@
}
/**
+ * Enter object pattern.
* @param {ObjectPattern} pattern object pattern
* @param {OnIdent} onIdent callback
*/
@@ -4489,6 +4660,7 @@
}
/**
+ * Enter array pattern.
* @param {ArrayPattern} pattern object pattern
* @param {OnIdent} onIdent callback
*/
@@ -4507,6 +4679,7 @@
}
/**
+ * Enter rest element.
* @param {RestElement} pattern object pattern
* @param {OnIdent} onIdent callback
*/
@@ -4515,6 +4688,7 @@
}
/**
+ * Enter assignment pattern.
* @param {AssignmentPattern} pattern object pattern
* @param {OnIdent} onIdent callback
*/
@@ -4523,6 +4697,7 @@
}
/**
+ * Evaluate expression.
* @param {Expression | SpreadElement | PrivateIdentifier | Super} expression expression node
* @returns {BasicEvaluatedExpression} evaluation result
*/
@@ -4547,6 +4722,7 @@
}
/**
+ * Returns parsed string.
* @param {Expression} expression expression
* @returns {string} parsed string
*/
@@ -4571,6 +4747,7 @@
/** @typedef {{ range?: Range, value: string, code: boolean, conditional: false | CalculatedStringResult[] }} CalculatedStringResult */
/**
+ * Parses calculated string.
* @param {Expression} expression expression
* @returns {CalculatedStringResult} result
*/
@@ -4660,6 +4837,7 @@
}
/**
+ * Parses the provided source and updates the parser state.
* @param {string | Buffer | PreparsedAst} source the source to parse
* @param {ParserState} state the parser state
* @returns {ParserState} the parser state
@@ -4748,6 +4926,7 @@
}
/**
+ * Returns evaluation result.
* @param {string} source source code
* @returns {BasicEvaluatedExpression} evaluation result
*/
@@ -4764,6 +4943,7 @@
}
/**
+ * Checks whether this javascript parser is pure.
* @param {Expression | Declaration | PrivateIdentifier | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | null | undefined} expr an expression
* @param {number} commentsStartPos source position from which annotation comments are checked
* @returns {boolean} true, when the expression is pure
@@ -4827,13 +5007,15 @@
return true;
});
}
-
+ case "TemplateLiteral":
+ return expr.expressions.every((expr) =>
+ this.isPure(expr, /** @type {Range} */ (expr.range)[0])
+ );
case "FunctionDeclaration":
case "FunctionExpression":
case "ArrowFunctionExpression":
case "ThisExpression":
case "Literal":
- case "TemplateLiteral":
case "Identifier":
case "PrivateIdentifier":
return true;
@@ -4878,7 +5060,7 @@
]).some(
(comment) =>
comment.type === "Block" &&
- /^\s*(#|@)__PURE__\s*$/.test(comment.value)
+ /^\s*(?:#|@)__PURE__\s*$/.test(comment.value)
);
if (!pureFlag) return false;
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
@@ -4895,12 +5077,14 @@
}
/**
+ * Returns comments in the range.
* @param {Range} range range
* @returns {Comment[]} comments in the range
*/
getComments(range) {
const [rangeStart, rangeEnd] = range;
/**
+ * Returns compared.
* @param {Comment} comment comment
* @param {number} needle needle
* @returns {number} compared
@@ -4923,6 +5107,7 @@
}
/**
+ * Checks whether this javascript parser is asi position.
* @param {number} pos source code position
* @returns {boolean} true when a semicolon has been inserted before this position, false if not
*/
@@ -4953,6 +5138,7 @@
}
/**
+ * Updates asi position using the provided po.
* @param {number} pos source code position
* @returns {void}
*/
@@ -4961,6 +5147,7 @@
}
/**
+ * Unset asi position.
* @param {number} pos source code position
* @returns {void}
*/
@@ -4969,6 +5156,7 @@
}
/**
+ * Checks whether this javascript parser is statement level expression.
* @param {Expression} expr expression
* @returns {boolean} true, when the expression is a statement level expression
*/
@@ -4987,6 +5175,7 @@
}
/**
+ * Returns tag data.
* @param {string} name name
* @param {Tag} tag tag info
* @returns {TagData | undefined} tag data
@@ -5003,6 +5192,7 @@
}
/**
+ * Processes the provided name.
* @param {string} name name
* @param {Tag} tag tag info
* @param {TagData=} data data
@@ -5040,6 +5230,7 @@
}
/**
+ * Processes the provided name.
* @param {string} name variable name
*/
defineVariable(name) {
@@ -5055,6 +5246,7 @@
}
/**
+ * Processes the provided name.
* @param {string} name variable name
*/
undefineVariable(name) {
@@ -5062,6 +5254,7 @@
}
/**
+ * Checks whether this javascript parser is variable defined.
* @param {string} name variable name
* @returns {boolean} true, when variable is defined
*/
@@ -5075,6 +5268,7 @@
}
/**
+ * Gets variable info.
* @param {string} name variable name
* @returns {ExportedVariableInfo} info for this variable
*/
@@ -5087,6 +5281,7 @@
}
/**
+ * Updates variable using the provided name.
* @param {string} name variable name
* @param {ExportedVariableInfo} variableInfo new info for this variable
* @returns {void}
@@ -5112,6 +5307,7 @@
}
/**
+ * Evaluated variable.
* @param {TagInfo} tagInfo tag info
* @returns {VariableInfo} variable info
*/
@@ -5125,6 +5321,7 @@
}
/**
+ * Parses comment options.
* @param {Range} range range of the comment
* @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: Comment })[] | null }} result
*/
@@ -5133,7 +5330,7 @@
if (comments.length === 0) {
return EMPTY_COMMENT_OPTIONS;
}
- /** @type {Record<string, EXPECTED_ANY> } */
+ /** @type {Record<string, EXPECTED_ANY>} */
const options = {};
/** @type {(Error & { comment: Comment })[]} */
const errors = [];
@@ -5168,14 +5365,18 @@
}
/**
+ * Extract member expression chain.
* @param {Expression | Super} expression a member expression
* @returns {{ members: Members, object: Expression | Super, membersOptionals: MembersOptionals, memberRanges: MemberRanges }} member names (reverse order) and remaining object
*/
extractMemberExpressionChain(expression) {
/** @type {Node} */
let expr = expression;
+ /** @type {Members} */
const members = [];
+ /** @type {MembersOptionals} */
const membersOptionals = [];
+ /** @type {MemberRanges} */
const memberRanges = [];
while (expr.type === "MemberExpression") {
if (expr.computed) {
@@ -5200,11 +5401,13 @@
}
/**
+ * Gets free info from variable.
* @param {string} varName variable name
- * @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
+ * @returns {{ name: string, info: VariableInfo | string } | undefined} name of the free variable and variable info for that
*/
getFreeInfoFromVariable(varName) {
const info = this.getVariableInfo(varName);
+ /** @type {string} */
let name;
if (info instanceof VariableInfo && info.name) {
if (!info.isFree()) return;
@@ -5218,11 +5421,13 @@
}
/**
+ * Gets name info from variable.
* @param {string} varName variable name
- * @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
+ * @returns {{ name: string, info: VariableInfo | string } | undefined} name of the free variable and variable info for that
*/
getNameInfoFromVariable(varName) {
const info = this.getVariableInfo(varName);
+ /** @type {string} */
let name;
if (info instanceof VariableInfo && info.name) {
if (!info.isFree() && !info.isTagged()) return;
@@ -5235,10 +5440,11 @@
return { info, name };
}
- /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => CalleeMembers, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges}} CallExpressionInfo */
- /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges}} ExpressionExpressionInfo */
+ /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => CalleeMembers, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} CallExpressionInfo */
+ /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} ExpressionExpressionInfo */
/**
+ * Gets member expression info.
* @param {Expression | Super} expression a member expression
* @param {number} allowedTypes which types should be returned, presented in bit mask
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
@@ -5296,8 +5502,9 @@
}
/**
+ * Gets name for expression.
* @param {Expression} expression an expression
- * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members} | undefined} name info
+ * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members } | undefined} name info
*/
getNameForExpression(expression) {
return this.getMemberExpressionInfo(
@@ -5307,6 +5514,7 @@
}
/**
+ * Get module parse function.
* @param {Compilation} compilation compilation
* @param {Module} module module
* @returns {ParseFunction | undefined} parser
@@ -5327,6 +5535,7 @@
}
/**
+ * Returns parse result.
* @param {string} code source code
* @param {InternalParseOptions} options parsing options
* @param {ParseFunction=} customParse custom function to parse
@@ -5342,6 +5551,7 @@
sourceType: type === "auto" ? "module" : type
};
/**
+ * Returns parse result.
* @param {string} code source code
* @param {ParseOptions} options parsing options
* @returns {ParseResult} parse result
@@ -5410,6 +5620,7 @@
}
/**
+ * Returns parser.
* @param {((BaseParser: typeof AcornParser) => typeof AcornParser)[]} plugins parser plugin
* @returns {typeof JavascriptParser} parser
*/
--
Gitblit v1.9.3