| | |
| | | /** @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 */ |
| | |
| | | /** @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 = []; |
| | |
| | | const importAssertions = (Parser) => |
| | | class extends Parser { |
| | | /** |
| | | * Parses with clause. |
| | | * @this {InstanceType<AcornParser>} |
| | | * @returns {ImportAttribute[]} import attributes |
| | | */ |
| | |
| | | /** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */ |
| | | |
| | | /** |
| | | * Gets import attributes. |
| | | * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions |
| | | * @returns {ImportAttributes | undefined} import attributes |
| | | */ |
| | |
| | | |
| | | 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this variable info is free. |
| | | * @returns {boolean} the variable is free or not |
| | | */ |
| | | isFree() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this variable info is tagged. |
| | | * @returns {boolean} the variable is tagged by tagVariable or not |
| | | */ |
| | | isTagged() { |
| | |
| | | /** @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 |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the parse result type used by this module. |
| | | * @typedef {object} ParseResult |
| | | * @property {Program} ast |
| | | * @property {Comment[]} comments |
| | |
| | | */ |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | 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 |
| | |
| | | /** @typedef {[number, number]} Range */ |
| | | |
| | | /** |
| | | * Defines the destructuring assignment property type used by this module. |
| | | * @typedef {object} DestructuringAssignmentProperty |
| | | * @property {string} id |
| | | * @property {Range} range |
| | |
| | | |
| | | class JavascriptParser extends Parser { |
| | | /** |
| | | * Creates an instance of JavascriptParser. |
| | | * @param {"module" | "script" | "auto"=} sourceType default source type |
| | | * @param {{ parse?: ParseFunction }=} options parser options |
| | | */ |
| | |
| | | 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", |
| | |
| | | |
| | | /** @type {ScopeInfo} */ |
| | | this.scope = /** @type {EXPECTED_ANY} */ (undefined); |
| | | /** @type {ParserState} */ |
| | | /** @type {JavascriptParserState} */ |
| | | this.state = /** @type {EXPECTED_ANY} */ (undefined); |
| | | /** @type {Comment[] | undefined} */ |
| | | this.comments = undefined; |
| | |
| | | return; |
| | | } |
| | | |
| | | /** @type {undefined | string} */ |
| | | let regExp; |
| | | const arg1 = expr.arguments[0]; |
| | | |
| | |
| | | ); |
| | | } |
| | | |
| | | /** @type {undefined | string} */ |
| | | let flags; |
| | | const arg2 = expr.arguments[1]; |
| | | |
| | |
| | | (a === true && b === false) || (a === false && b === true); |
| | | |
| | | /** |
| | | * Handle template string compare. |
| | | * @param {BasicEvaluatedExpression} left left |
| | | * @param {BasicEvaluatedExpression} right right |
| | | * @param {BasicEvaluatedExpression} res res |
| | |
| | | */ |
| | | const handleTemplateStringCompare = (left, right, res, eql) => { |
| | | /** |
| | | * Returns value. |
| | | * @param {BasicEvaluatedExpression[]} parts parts |
| | | * @returns {string} value |
| | | */ |
| | |
| | | return value; |
| | | }; |
| | | /** |
| | | * Returns value. |
| | | * @param {BasicEvaluatedExpression[]} parts parts |
| | | * @returns {string} value |
| | | */ |
| | |
| | | } |
| | | }); |
| | | /** |
| | | * Tap evaluate with variable info. |
| | | * @param {"Identifier" | "ThisExpression" | "MemberExpression"} exprType expression type name |
| | | * @param {(node: Expression | SpreadElement) => GetInfoResult | undefined} getInfo get info |
| | | * @returns {void} |
| | |
| | | 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; |
| | |
| | | .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) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | .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 = []; |
| | |
| | | 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()) { |
| | |
| | | |
| | | const condition = this.evaluateExpression(expr.test); |
| | | const conditionValue = condition.asBool(); |
| | | /** @type {BasicEvaluatedExpression} */ |
| | | let res; |
| | | if (conditionValue === undefined) { |
| | | const consequent = this.evaluateExpression(expr.consequent); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Destructuring assignment properties for. |
| | | * @param {Expression} node node |
| | | * @returns {DestructuringAssignmentProperties | undefined} destructured identifiers |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets rename identifier. |
| | | * @param {Expression | SpreadElement} expr expression |
| | | * @returns {string | VariableInfo | undefined} identifier |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided classy. |
| | | * @param {ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration} classy a class node |
| | | * @returns {void} |
| | | */ |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Block pre walk statement. |
| | | * @param {Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration} statement statement |
| | | */ |
| | | blockPreWalkStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided statement. |
| | | * @param {Statement | ModuleDeclaration | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} statement statement |
| | | */ |
| | | walkStatement(statement) { |
| | |
| | | |
| | | // Real Statements |
| | | /** |
| | | * Pre walk block statement. |
| | | * @param {BlockStatement} statement block statement |
| | | */ |
| | | preWalkBlockStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk block statement. |
| | | * @param {BlockStatement | StaticBlock} statement block statement |
| | | */ |
| | | walkBlockStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk expression statement. |
| | | * @param {ExpressionStatement} statement expression statement |
| | | */ |
| | | walkExpressionStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk if statement. |
| | | * @param {IfStatement} statement if statement |
| | | */ |
| | | preWalkIfStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided statement. |
| | | * @param {IfStatement} statement if statement |
| | | */ |
| | | walkIfStatement(statement) { |
| | | const result = this.hooks.statementIf.call(statement); |
| | | if (result === undefined) { |
| | | 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; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk labeled statement. |
| | | * @param {LabeledStatement} statement with statement |
| | | */ |
| | | preWalkLabeledStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk labeled statement. |
| | | * @param {LabeledStatement} statement with statement |
| | | */ |
| | | walkLabeledStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk with statement. |
| | | * @param {WithStatement} statement with statement |
| | | */ |
| | | preWalkWithStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk with statement. |
| | | * @param {WithStatement} statement with statement |
| | | */ |
| | | walkWithStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk switch statement. |
| | | * @param {SwitchStatement} statement switch statement |
| | | */ |
| | | preWalkSwitchStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk switch statement. |
| | | * @param {SwitchStatement} statement switch statement |
| | | */ |
| | | walkSwitchStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk terminating statement. |
| | | * @param {ReturnStatement | ThrowStatement} statement return or throw statement |
| | | */ |
| | | walkTerminatingStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk return statement. |
| | | * @param {ReturnStatement} statement return statement |
| | | */ |
| | | walkReturnStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk throw statement. |
| | | * @param {ThrowStatement} statement return statement |
| | | */ |
| | | walkThrowStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk try statement. |
| | | * @param {TryStatement} statement try statement |
| | | */ |
| | | preWalkTryStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk try statement. |
| | | * @param {TryStatement} statement try statement |
| | | */ |
| | | walkTryStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk while statement. |
| | | * @param {WhileStatement} statement while statement |
| | | */ |
| | | preWalkWhileStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk while statement. |
| | | * @param {WhileStatement} statement while statement |
| | | */ |
| | | walkWhileStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk do while statement. |
| | | * @param {DoWhileStatement} statement do while statement |
| | | */ |
| | | preWalkDoWhileStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk do while statement. |
| | | * @param {DoWhileStatement} statement do while statement |
| | | */ |
| | | walkDoWhileStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk for statement. |
| | | * @param {ForStatement} statement for statement |
| | | */ |
| | | preWalkForStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk for statement. |
| | | * @param {ForStatement} statement for statement |
| | | */ |
| | | walkForStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk for in statement. |
| | | * @param {ForInStatement} statement for statement |
| | | */ |
| | | preWalkForInStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk for in statement. |
| | | * @param {ForInStatement} statement for statement |
| | | */ |
| | | walkForInStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk for of statement. |
| | | * @param {ForOfStatement} statement statement |
| | | */ |
| | | preWalkForOfStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk for of statement. |
| | | * @param {ForOfStatement} statement for statement |
| | | */ |
| | | walkForOfStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk function declaration. |
| | | * @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration |
| | | */ |
| | | preWalkFunctionDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk function declaration. |
| | | * @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration |
| | | */ |
| | | walkFunctionDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Block pre walk expression statement. |
| | | * @param {ExpressionStatement} statement expression statement |
| | | */ |
| | | blockPreWalkExpressionStatement(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk assignment expression. |
| | | * @param {AssignmentExpression} expression assignment expression |
| | | */ |
| | | preWalkAssignmentExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Enter destructuring assignment. |
| | | * @param {Pattern} pattern pattern |
| | | * @param {Expression} expression assignment expression |
| | | * @returns {Expression | undefined} destructuring expression |
| | |
| | | } |
| | | |
| | | /** |
| | | * Module pre walk import declaration. |
| | | * @param {ImportDeclaration} statement statement |
| | | */ |
| | | modulePreWalkImportDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided declaration. |
| | | * @param {Declaration} declaration declaration |
| | | * @param {OnIdent} onIdent on ident callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Module pre walk export named declaration. |
| | | * @param {ExportNamedDeclaration} statement statement |
| | | */ |
| | | modulePreWalkExportNamedDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Block pre walk export named declaration. |
| | | * @param {ExportNamedDeclaration} statement statement |
| | | */ |
| | | blockPreWalkExportNamedDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk export named declaration. |
| | | * @param {ExportNamedDeclaration} statement the statement |
| | | */ |
| | | walkExportNamedDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Block pre walk export default declaration. |
| | | * @param {ExportDefaultDeclaration} statement statement |
| | | */ |
| | | blockPreWalkExportDefaultDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk export default declaration. |
| | | * @param {ExportDefaultDeclaration} statement statement |
| | | */ |
| | | walkExportDefaultDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Module pre walk export all declaration. |
| | | * @param {ExportAllDeclaration} statement statement |
| | | */ |
| | | modulePreWalkExportAllDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk variable declaration. |
| | | * @param {VariableDeclaration} statement variable declaration |
| | | */ |
| | | preWalkVariableDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Block pre walk variable declaration. |
| | | * @param {VariableDeclaration} statement variable declaration |
| | | */ |
| | | blockPreWalkVariableDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk variable declaration. |
| | | * @param {VariableDeclaration} statement variable declaration |
| | | * @param {HookMap<SyncBailHook<[Identifier], boolean | void>>} hookMap map of hooks |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk object pattern. |
| | | * @param {ObjectPattern} objectPattern object pattern |
| | | * @returns {DestructuringAssignmentProperties | undefined} set of names or undefined if not all keys are identifiers |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk array pattern. |
| | | * @param {ArrayPattern} arrayPattern array pattern |
| | | * @returns {Set<DestructuringAssignmentProperty> | undefined} set of names or undefined if not all keys are identifiers |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk variable declarator. |
| | | * @param {VariableDeclarator} declarator variable declarator |
| | | */ |
| | | preWalkVariableDeclarator(declarator) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk variable declaration. |
| | | * @param {VariableDeclaration} statement variable declaration |
| | | */ |
| | | walkVariableDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Block pre walk class declaration. |
| | | * @param {ClassDeclaration | MaybeNamedClassDeclaration} statement class declaration |
| | | */ |
| | | blockPreWalkClassDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk class declaration. |
| | | * @param {ClassDeclaration | MaybeNamedClassDeclaration} statement class declaration |
| | | */ |
| | | walkClassDeclaration(statement) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk switch cases. |
| | | * @param {SwitchCase[]} switchCases switch statement |
| | | */ |
| | | preWalkSwitchCases(switchCases) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided switch case. |
| | | * @param {SwitchCase[]} switchCases switch statement |
| | | */ |
| | | walkSwitchCases(switchCases) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Pre walk catch clause. |
| | | * @param {CatchClause} catchClause catch clause |
| | | */ |
| | | preWalkCatchClause(catchClause) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided catch clause. |
| | | * @param {CatchClause} catchClause catch clause |
| | | */ |
| | | walkCatchClause(catchClause) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided pattern. |
| | | * @param {Pattern} pattern pattern |
| | | */ |
| | | walkPattern(pattern) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk assignment pattern. |
| | | * @param {AssignmentPattern} pattern assignment pattern |
| | | */ |
| | | walkAssignmentPattern(pattern) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk object pattern. |
| | | * @param {ObjectPattern} pattern pattern |
| | | */ |
| | | walkObjectPattern(pattern) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk array pattern. |
| | | * @param {ArrayPattern} pattern array pattern |
| | | */ |
| | | walkArrayPattern(pattern) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided pattern. |
| | | * @param {RestElement} pattern rest element |
| | | */ |
| | | walkRestElement(pattern) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided expression. |
| | | * @param {(Expression | SpreadElement | null)[]} expressions expressions |
| | | */ |
| | | walkExpressions(expressions) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided expression. |
| | | * @param {Expression | SpreadElement | PrivateIdentifier | Super} expression expression |
| | | */ |
| | | walkExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk await expression. |
| | | * @param {AwaitExpression} expression await expression |
| | | */ |
| | | walkAwaitExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk array expression. |
| | | * @param {ArrayExpression} expression array expression |
| | | */ |
| | | walkArrayExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk spread element. |
| | | * @param {SpreadElement} expression spread element |
| | | */ |
| | | walkSpreadElement(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk object expression. |
| | | * @param {ObjectExpression} expression object expression |
| | | */ |
| | | walkObjectExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided prop. |
| | | * @param {Property | SpreadElement} prop property or spread element |
| | | */ |
| | | walkProperty(prop) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk function expression. |
| | | * @param {FunctionExpression} expression arrow function expression |
| | | */ |
| | | walkFunctionExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk arrow function expression. |
| | | * @param {ArrowFunctionExpression} expression arrow function expression |
| | | */ |
| | | walkArrowFunctionExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk sequence expression. |
| | | * @param {SequenceExpression} expression the sequence |
| | | */ |
| | | walkSequenceExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk update expression. |
| | | * @param {UpdateExpression} expression the update expression |
| | | */ |
| | | walkUpdateExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk unary expression. |
| | | * @param {UnaryExpression} expression the unary expression |
| | | */ |
| | | walkUnaryExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk left right expression. |
| | | * @param {LogicalExpression | BinaryExpression} expression the expression |
| | | */ |
| | | walkLeftRightExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk binary expression. |
| | | * @param {BinaryExpression} expression the binary expression |
| | | */ |
| | | walkBinaryExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk logical expression. |
| | | * @param {LogicalExpression} expression the logical expression |
| | | */ |
| | | walkLogicalExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk assignment expression. |
| | | * @param {AssignmentExpression} expression assignment expression |
| | | */ |
| | | walkAssignmentExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk conditional expression. |
| | | * @param {ConditionalExpression} expression conditional expression |
| | | */ |
| | | walkConditionalExpression(expression) { |
| | | const result = this.hooks.expressionConditionalOperator.call(expression); |
| | | if (result === undefined) { |
| | | 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); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk new expression. |
| | | * @param {NewExpression} expression new expression |
| | | */ |
| | | walkNewExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk yield expression. |
| | | * @param {YieldExpression} expression yield expression |
| | | */ |
| | | walkYieldExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk template literal. |
| | | * @param {TemplateLiteral} expression template literal |
| | | */ |
| | | walkTemplateLiteral(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk tagged template expression. |
| | | * @param {TaggedTemplateExpression} expression tagged template expression |
| | | */ |
| | | walkTaggedTemplateExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk class expression. |
| | | * @param {ClassExpression} expression the class expression |
| | | */ |
| | | walkClassExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk chain expression. |
| | | * @param {ChainExpression} expression expression |
| | | */ |
| | | walkChainExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided function expression. |
| | | * @private |
| | | * @param {FunctionExpression | ArrowFunctionExpression} functionExpression function expression |
| | | * @param {(Expression | SpreadElement)[]} options options |
| | |
| | | */ |
| | | _walkIIFE(functionExpression, options, currentThis) { |
| | | /** |
| | | * Returns var info. |
| | | * @param {Expression | SpreadElement} argOrThis arg or this |
| | | * @returns {string | VariableInfo | undefined} var info |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk import expression. |
| | | * @param {ImportExpression} expression import expression |
| | | */ |
| | | walkImportExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk member expression. |
| | | * @param {MemberExpression} expression member expression |
| | | */ |
| | | walkMemberExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk member expression with expression name. |
| | | * @template R |
| | | * @param {MemberExpression} expression member expression |
| | | * @param {string} name name |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk this expression. |
| | | * @param {ThisExpression} expression this expression |
| | | */ |
| | | walkThisExpression(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided expression. |
| | | * @param {Identifier} expression identifier |
| | | */ |
| | | walkIdentifier(expression) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Walk meta property. |
| | | * @param {MetaProperty} metaProperty meta property |
| | | */ |
| | | walkMetaProperty(metaProperty) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Call hooks for expression. |
| | | * @template T |
| | | * @template R |
| | | * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called |
| | |
| | | } |
| | | |
| | | /** |
| | | * Call hooks for expression with fallback. |
| | | * @template T |
| | | * @template R |
| | | * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called |
| | |
| | | } |
| | | |
| | | /** |
| | | * Call hooks for name. |
| | | * @template T |
| | | * @template R |
| | | * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called |
| | |
| | | } |
| | | |
| | | /** |
| | | * Call hooks for info. |
| | | * @template T |
| | | * @template R |
| | | * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks that should be called |
| | |
| | | } |
| | | |
| | | /** |
| | | * Call hooks for info with fallback. |
| | | * @template T |
| | | * @template R |
| | | * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called |
| | |
| | | * @returns {R | undefined} result of hook |
| | | */ |
| | | callHooksForInfoWithFallback(hookMap, info, fallback, defined, ...args) { |
| | | /** @type {string} */ |
| | | let name; |
| | | if (typeof info === "string") { |
| | | name = info; |
| | |
| | | } |
| | | return; |
| | | } |
| | | name = info.name; |
| | | name = /** @type {string} */ (info.name); |
| | | } |
| | | const hook = hookMap.get(name); |
| | | if (hook !== undefined) { |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided param. |
| | | * @deprecated |
| | | * @param {(string | Pattern | Property)[]} params scope params |
| | | * @param {() => void} fn inner function |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided has thi. |
| | | * @param {boolean} hasThis true, when this is defined |
| | | * @param {Identifier[]} params scope params |
| | | * @param {() => void} fn inner function |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided has thi. |
| | | * @param {boolean} hasThis true, when this is defined |
| | | * @param {(Pattern | string)[]} params scope params |
| | | * @param {() => void} fn inner function |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided fn. |
| | | * @param {() => void} fn inner function |
| | | * @param {boolean} inExecutedPath executed state |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided statement. |
| | | * @param {(Directive | Statement | ModuleDeclaration)[]} statements statements |
| | | */ |
| | | detectMode(statements) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided pattern. |
| | | * @param {(string | Pattern | Property)[]} patterns patterns |
| | | * @param {OnIdentString} onIdent on ident callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided pattern. |
| | | * @param {Pattern | Property} pattern pattern |
| | | * @param {OnIdent} onIdent on ident callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided pattern. |
| | | * @param {Identifier} pattern identifier pattern |
| | | * @param {OnIdent} onIdent callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Enter object pattern. |
| | | * @param {ObjectPattern} pattern object pattern |
| | | * @param {OnIdent} onIdent callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Enter array pattern. |
| | | * @param {ArrayPattern} pattern object pattern |
| | | * @param {OnIdent} onIdent callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Enter rest element. |
| | | * @param {RestElement} pattern object pattern |
| | | * @param {OnIdent} onIdent callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Enter assignment pattern. |
| | | * @param {AssignmentPattern} pattern object pattern |
| | | * @param {OnIdent} onIdent callback |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Evaluate expression. |
| | | * @param {Expression | SpreadElement | PrivateIdentifier | Super} expression expression node |
| | | * @returns {BasicEvaluatedExpression} evaluation result |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns parsed string. |
| | | * @param {Expression} expression expression |
| | | * @returns {string} parsed string |
| | | */ |
| | |
| | | /** @typedef {{ range?: Range, value: string, code: boolean, conditional: false | CalculatedStringResult[] }} CalculatedStringResult */ |
| | | |
| | | /** |
| | | * Parses calculated string. |
| | | * @param {Expression} expression expression |
| | | * @returns {CalculatedStringResult} result |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns evaluation result. |
| | | * @param {string} source source code |
| | | * @returns {BasicEvaluatedExpression} evaluation result |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | 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; |
| | |
| | | ]).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]; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates asi position using the provided po. |
| | | * @param {number} pos source code position |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Unset asi position. |
| | | * @param {number} pos source code position |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this javascript parser is statement level expression. |
| | | * @param {Expression} expr expression |
| | | * @returns {boolean} true, when the expression is a statement level expression |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns tag data. |
| | | * @param {string} name name |
| | | * @param {Tag} tag tag info |
| | | * @returns {TagData | undefined} tag data |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided name. |
| | | * @param {string} name name |
| | | * @param {Tag} tag tag info |
| | | * @param {TagData=} data data |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided name. |
| | | * @param {string} name variable name |
| | | */ |
| | | defineVariable(name) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided name. |
| | | * @param {string} name variable name |
| | | */ |
| | | undefineVariable(name) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this javascript parser is variable defined. |
| | | * @param {string} name variable name |
| | | * @returns {boolean} true, when variable is defined |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets variable info. |
| | | * @param {string} name variable name |
| | | * @returns {ExportedVariableInfo} info for this variable |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates variable using the provided name. |
| | | * @param {string} name variable name |
| | | * @param {ExportedVariableInfo} variableInfo new info for this variable |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Evaluated variable. |
| | | * @param {TagInfo} tagInfo tag info |
| | | * @returns {VariableInfo} variable info |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Parses comment options. |
| | | * @param {Range} range range of the comment |
| | | * @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: Comment })[] | null }} result |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | */ |
| | | getFreeInfoFromVariable(varName) { |
| | | const info = this.getVariableInfo(varName); |
| | | /** @type {string} */ |
| | | let name; |
| | | if (info instanceof VariableInfo && info.name) { |
| | | if (!info.isFree()) return; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | */ |
| | | getNameInfoFromVariable(varName) { |
| | | const info = this.getVariableInfo(varName); |
| | | /** @type {string} */ |
| | | let name; |
| | | if (info instanceof VariableInfo && info.name) { |
| | | if (!info.isFree() && !info.isTagged()) return; |
| | |
| | | /** @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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets name for expression. |
| | | * @param {Expression} expression an expression |
| | | * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members} | undefined} name info |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Get module parse function. |
| | | * @param {Compilation} compilation compilation |
| | | * @param {Module} module module |
| | | * @returns {ParseFunction | undefined} parser |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns parse result. |
| | | * @param {string} code source code |
| | | * @param {InternalParseOptions} options parsing options |
| | | * @param {ParseFunction=} customParse custom function to parse |
| | |
| | | sourceType: type === "auto" ? "module" : type |
| | | }; |
| | | /** |
| | | * Returns parse result. |
| | | * @param {string} code source code |
| | | * @param {ParseOptions} options parsing options |
| | | * @returns {ParseResult} parse result |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns parser. |
| | | * @param {((BaseParser: typeof AcornParser) => typeof AcornParser)[]} plugins parser plugin |
| | | * @returns {typeof JavascriptParser} parser |
| | | */ |