mirror of https://github.com/webpack/webpack.git
				
				
				
			refactor: types more
This commit is contained in:
		
							parent
							
								
									e719e60340
								
							
						
					
					
						commit
						30390058ef
					
				|  | @ -16,11 +16,10 @@ const memoize = require("../util/memoize"); | |||
| const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | ||||
| 
 | ||||
| /** @typedef {import("acorn").Options} AcornOptions */ | ||||
| /** @typedef {import("estree").ArrayExpression} ArrayExpressionNode */ | ||||
| /** @typedef {import("estree").AssignmentExpression} AssignmentExpression */ | ||||
| /** @typedef {import("estree").BinaryExpression} BinaryExpressionNode */ | ||||
| /** @typedef {import("estree").BinaryExpression} BinaryExpression */ | ||||
| /** @typedef {import("estree").BlockStatement} BlockStatementNode */ | ||||
| /** @typedef {import("estree").SequenceExpression} SequenceExpressionNode */ | ||||
| /** @typedef {import("estree").SequenceExpression} SequenceExpression */ | ||||
| /** @typedef {import("estree").CallExpression} CallExpressionNode */ | ||||
| /** @typedef {import("estree").BaseCallExpression} BaseCallExpression */ | ||||
| /** @typedef {import("estree").StaticBlock} StaticBlock */ | ||||
|  | @ -31,20 +30,34 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | |||
| /** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */ | ||||
| /** @typedef {import("estree").ClassExpression} ClassExpression */ | ||||
| /** @typedef {import("estree").Comment} CommentNode */ | ||||
| /** @typedef {import("estree").ConditionalExpression} ConditionalExpressionNode */ | ||||
| /** @typedef {import("estree").ConditionalExpression} ConditionalExpression */ | ||||
| /** @typedef {import("estree").Declaration} DeclarationNode */ | ||||
| /** @typedef {import("estree").PrivateIdentifier} PrivateIdentifierNode */ | ||||
| /** @typedef {import("estree").PrivateIdentifier} PrivateIdentifier */ | ||||
| /** @typedef {import("estree").PropertyDefinition} PropertyDefinition */ | ||||
| /** @typedef {import("estree").Expression} ExpressionNode */ | ||||
| /** @typedef {import("estree").Identifier} IdentifierNode */ | ||||
| /** @typedef {import("estree").Identifier} Identifier */ | ||||
| /** @typedef {import("estree").VariableDeclaration} VariableDeclaration */ | ||||
| /** @typedef {import("estree").IfStatement} IfStatement */ | ||||
| /** @typedef {import("estree").LabeledStatement} LabeledStatement */ | ||||
| /** @typedef {import("estree").Literal} LiteralNode */ | ||||
| /** @typedef {import("estree").LogicalExpression} LogicalExpressionNode */ | ||||
| /** @typedef {import("estree").LogicalExpression} LogicalExpression */ | ||||
| /** @typedef {import("estree").ChainExpression} ChainExpressionNode */ | ||||
| /** @typedef {import("estree").MemberExpression} MemberExpressionNode */ | ||||
| /** @typedef {import("estree").MetaProperty} MetaPropertyNode */ | ||||
| /** @typedef {import("estree").Property} Property */ | ||||
| /** @typedef {import("estree").AssignmentPattern} AssignmentPattern */ | ||||
| /** @typedef {import("estree").UpdateExpression} UpdateExpression */ | ||||
| /** @typedef {import("estree").ObjectExpression} ObjectExpression */ | ||||
| /** @typedef {import("estree").UnaryExpression} UnaryExpression */ | ||||
| /** @typedef {import("estree").ArrayExpression} ArrayExpression */ | ||||
| /** @typedef {import("estree").BlockStatement} BlockStatement */ | ||||
| /** @typedef {import("estree").ArrayPattern} ArrayPattern */ | ||||
| /** @typedef {import("estree").AwaitExpression} AwaitExpression */ | ||||
| /** @typedef {import("estree").ThisExpression} ThisExpression */ | ||||
| /** @typedef {import("estree").RestElement} RestElement */ | ||||
| /** @typedef {import("estree").ObjectPattern} ObjectPattern */ | ||||
| /** @typedef {import("estree").SwitchCase} SwitchCase */ | ||||
| /** @typedef {import("estree").CatchClause} CatchClause */ | ||||
| /** @typedef {import("estree").VariableDeclarator} VariableDeclarator */ | ||||
| /** @typedef {import("estree").ForInStatement} ForInStatement */ | ||||
| /** @typedef {import("estree").ForOfStatement} ForOfStatement */ | ||||
|  | @ -52,8 +65,9 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | |||
| /** @typedef {import("estree").WithStatement} WithStatement */ | ||||
| /** @typedef {import("estree").ThrowStatement} ThrowStatement */ | ||||
| /** @typedef {import("estree").MethodDefinition} MethodDefinition */ | ||||
| /** @typedef {import("estree").ModuleDeclaration} ModuleDeclarationNode */ | ||||
| /** @typedef {import("estree").NewExpression} NewExpressionNode */ | ||||
| /** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */ | ||||
| /** @typedef {import("estree").NewExpression} NewExpression */ | ||||
| /** @typedef {import("estree").SpreadElement} SpreadElement */ | ||||
| /** @typedef {import("estree").WhileStatement} WhileStatement */ | ||||
| /** @typedef {import("estree").ExpressionStatement} ExpressionStatement */ | ||||
| /** @typedef {import("estree").FunctionDeclaration} FunctionDeclaration */ | ||||
|  | @ -62,12 +76,12 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | |||
| /** @typedef {import("estree").Node} AnyNode */ | ||||
| /** @typedef {import("estree").Program} ProgramNode */ | ||||
| /** @typedef {import("estree").Statement} StatementNode */ | ||||
| /** @typedef {import("estree").ImportDeclaration} ImportDeclarationNode */ | ||||
| /** @typedef {import("estree").ImportDeclaration} ImportDeclaration */ | ||||
| /** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclaration */ | ||||
| /** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclarationNode */ | ||||
| /** @typedef {import("estree").Super} SuperNode */ | ||||
| /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpressionNode */ | ||||
| /** @typedef {import("estree").TemplateLiteral} TemplateLiteralNode */ | ||||
| /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */ | ||||
| /** @typedef {import("estree").TemplateLiteral} TemplateLiteral */ | ||||
| /** @typedef {import("estree").ThisExpression} ThisExpressionNode */ | ||||
| /** @typedef {import("estree").UnaryExpression} UnaryExpressionNode */ | ||||
| /** @typedef {import("estree").VariableDeclarator} VariableDeclaratorNode */ | ||||
|  | @ -115,7 +129,7 @@ class VariableInfo { | |||
|  * @typedef {Object} ScopeInfo | ||||
|  * @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions | ||||
|  * @property {boolean | "arrow"} topLevelScope | ||||
|  * @property {boolean} inShorthand | ||||
|  * @property {boolean | string} inShorthand | ||||
|  * @property {boolean} isStrict | ||||
|  * @property {boolean} isAsmJs | ||||
|  * @property {boolean} inTry | ||||
|  | @ -224,13 +238,13 @@ class JavascriptParser extends Parser { | |||
| 			evaluateTypeof: new HookMap(() => new SyncBailHook(["expression"])), | ||||
| 			/** @type {HookMap<SyncBailHook<[ExpressionNode], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			evaluate: new HookMap(() => new SyncBailHook(["expression"])), | ||||
| 			/** @type {HookMap<SyncBailHook<[IdentifierNode | ThisExpressionNode | MemberExpressionNode | MetaPropertyNode], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			/** @type {HookMap<SyncBailHook<[Identifier | ThisExpressionNode | MemberExpressionNode | MetaPropertyNode], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			evaluateIdentifier: new HookMap(() => new SyncBailHook(["expression"])), | ||||
| 			/** @type {HookMap<SyncBailHook<[IdentifierNode | ThisExpressionNode | MemberExpressionNode], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			/** @type {HookMap<SyncBailHook<[Identifier | ThisExpressionNode | MemberExpressionNode], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			evaluateDefinedIdentifier: new HookMap( | ||||
| 				() => new SyncBailHook(["expression"]) | ||||
| 			), | ||||
| 			/** @type {HookMap<SyncBailHook<[NewExpressionNode], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			/** @type {HookMap<SyncBailHook<[NewExpression], BasicEvaluatedExpression | undefined | null>>} */ | ||||
| 			evaluateNewExpression: new HookMap( | ||||
| 				() => new SyncBailHook(["expression"]) | ||||
| 			), | ||||
|  | @ -242,16 +256,16 @@ class JavascriptParser extends Parser { | |||
| 			evaluateCallExpressionMember: new HookMap( | ||||
| 				() => new SyncBailHook(["expression", "param"]) | ||||
| 			), | ||||
| 			/** @type {HookMap<SyncBailHook<[ExpressionNode | DeclarationNode | PrivateIdentifierNode, number], boolean | void>>} */ | ||||
| 			/** @type {HookMap<SyncBailHook<[ExpressionNode | DeclarationNode | PrivateIdentifier, number], boolean | void>>} */ | ||||
| 			isPure: new HookMap( | ||||
| 				() => new SyncBailHook(["expression", "commentsStartPosition"]) | ||||
| 			), | ||||
| 			/** @type {SyncBailHook<[StatementNode | ModuleDeclarationNode], boolean | void>} */ | ||||
| 			/** @type {SyncBailHook<[StatementNode | ModuleDeclaration], boolean | void>} */ | ||||
| 			preStatement: new SyncBailHook(["statement"]), | ||||
| 
 | ||||
| 			/** @type {SyncBailHook<[StatementNode | ModuleDeclarationNode], boolean | void>} */ | ||||
| 			/** @type {SyncBailHook<[StatementNode | ModuleDeclaration], boolean | void>} */ | ||||
| 			blockPreStatement: new SyncBailHook(["declaration"]), | ||||
| 			/** @type {SyncBailHook<[StatementNode | ModuleDeclarationNode], boolean | void>} */ | ||||
| 			/** @type {SyncBailHook<[StatementNode | ModuleDeclaration], boolean | void>} */ | ||||
| 			statement: new SyncBailHook(["statement"]), | ||||
| 			/** @type {SyncBailHook<[IfStatement], boolean | void>} */ | ||||
| 			statementIf: new SyncBailHook(["statement"]), | ||||
|  | @ -270,9 +284,9 @@ class JavascriptParser extends Parser { | |||
| 			]), | ||||
| 			/** @type {HookMap<SyncBailHook<[LabeledStatement], boolean | void>>} */ | ||||
| 			label: new HookMap(() => new SyncBailHook(["statement"])), | ||||
| 			/** @type {SyncBailHook<[ImportDeclarationNode, ImportSource], boolean | void>} */ | ||||
| 			/** @type {SyncBailHook<[ImportDeclaration, ImportSource], boolean | void>} */ | ||||
| 			import: new SyncBailHook(["statement", "source"]), | ||||
| 			/** @type {SyncBailHook<[ImportDeclarationNode, ImportSource, string, string], boolean | void>} */ | ||||
| 			/** @type {SyncBailHook<[ImportDeclaration, ImportSource, string, string], boolean | void>} */ | ||||
| 			importSpecifier: new SyncBailHook([ | ||||
| 				"statement", | ||||
| 				"source", | ||||
|  | @ -314,7 +328,7 @@ class JavascriptParser extends Parser { | |||
| 			varDeclarationConst: new HookMap(() => new SyncBailHook(["declaration"])), | ||||
| 			/** @type {HookMap<SyncBailHook<[DeclarationNode], boolean | void>>} */ | ||||
| 			varDeclarationVar: new HookMap(() => new SyncBailHook(["declaration"])), | ||||
| 			/** @type {HookMap<SyncBailHook<[IdentifierNode], boolean | void>>} */ | ||||
| 			/** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */ | ||||
| 			pattern: new HookMap(() => new SyncBailHook(["pattern"])), | ||||
| 			/** @type {HookMap<SyncBailHook<[ExpressionNode], boolean | void>>} */ | ||||
| 			canRename: new HookMap(() => new SyncBailHook(["initExpression"])), | ||||
|  | @ -363,9 +377,9 @@ class JavascriptParser extends Parser { | |||
| 			), | ||||
| 			/** @type {SyncBailHook<[ChainExpressionNode], boolean | void>} */ | ||||
| 			optionalChaining: new SyncBailHook(["optionalChaining"]), | ||||
| 			/** @type {HookMap<SyncBailHook<[NewExpressionNode], boolean | void>>} */ | ||||
| 			/** @type {HookMap<SyncBailHook<[NewExpression], boolean | void>>} */ | ||||
| 			new: new HookMap(() => new SyncBailHook(["expression"])), | ||||
| 			/** @type {SyncBailHook<[BinaryExpressionNode], boolean | void>} */ | ||||
| 			/** @type {SyncBailHook<[BinaryExpression], boolean | void>} */ | ||||
| 			binaryExpression: new SyncBailHook(["binaryExpression"]), | ||||
| 			/** @type {HookMap<SyncBailHook<[ExpressionNode], boolean | void>>} */ | ||||
| 			expression: new HookMap(() => new SyncBailHook(["expression"])), | ||||
|  | @ -434,7 +448,7 @@ class JavascriptParser extends Parser { | |||
| 			} | ||||
| 		}); | ||||
| 		this.hooks.evaluate.for("NewExpression").tap("JavascriptParser", _expr => { | ||||
| 			const expr = /** @type {NewExpressionNode} */ (_expr); | ||||
| 			const expr = /** @type {NewExpression} */ (_expr); | ||||
| 			const callee = expr.callee; | ||||
| 			if (callee.type !== "Identifier") return; | ||||
| 			if (callee.name !== "RegExp") { | ||||
|  | @ -495,7 +509,7 @@ class JavascriptParser extends Parser { | |||
| 		this.hooks.evaluate | ||||
| 			.for("LogicalExpression") | ||||
| 			.tap("JavascriptParser", _expr => { | ||||
| 				const expr = /** @type {LogicalExpressionNode} */ (_expr); | ||||
| 				const expr = /** @type {LogicalExpression} */ (_expr); | ||||
| 
 | ||||
| 				const left = this.evaluateExpression(expr.left); | ||||
| 				let returnRight = false; | ||||
|  | @ -554,13 +568,13 @@ class JavascriptParser extends Parser { | |||
| 		 * import("./" + foo + bar); // webpack will auto evaluate this into import("./foobar")
 | ||||
| 		 * ``` | ||||
| 		 * @param {boolean | number | BigInt | string} value the value to convert to an expression | ||||
| 		 * @param {BinaryExpressionNode | UnaryExpressionNode} expr the expression being evaluated | ||||
| 		 * @param {BinaryExpression | UnaryExpressionNode} expr the expression being evaluated | ||||
| 		 * @param {boolean} sideEffects whether the expression has side effects | ||||
| 		 * @returns {BasicEvaluatedExpression} the evaluated expression | ||||
| 		 * @example | ||||
| 		 * | ||||
| 		 * ```js
 | ||||
| 		 * const binaryExpr = new BinaryExpressionNode("+", | ||||
| 		 * const binaryExpr = new BinaryExpression("+", | ||||
| 		 * 	{ type: "Literal", value: 2 }, | ||||
| 		 * 	{ type: "Literal", value: 3 } | ||||
| 		 * ); | ||||
|  | @ -605,7 +619,7 @@ class JavascriptParser extends Parser { | |||
| 		this.hooks.evaluate | ||||
| 			.for("BinaryExpression") | ||||
| 			.tap("JavascriptParser", _expr => { | ||||
| 				const expr = /** @type {BinaryExpressionNode} */ (_expr); | ||||
| 				const expr = /** @type {BinaryExpression} */ (_expr); | ||||
| 
 | ||||
| 				/** | ||||
| 				 * Evaluates a binary expression if and only if it is a const operation (e.g. 1 + 2, "a" + "b", etc.). | ||||
|  | @ -1086,7 +1100,7 @@ class JavascriptParser extends Parser { | |||
| 				.setRange(expr.range); | ||||
| 		}); | ||||
| 		this.hooks.evaluate.for("Identifier").tap("JavascriptParser", expr => { | ||||
| 			if (/** @type {IdentifierNode} */ (expr).name === "undefined") { | ||||
| 			if (/** @type {Identifier} */ (expr).name === "undefined") { | ||||
| 				return new BasicEvaluatedExpression() | ||||
| 					.setUndefined() | ||||
| 					.setRange(expr.range); | ||||
|  | @ -1145,9 +1159,7 @@ class JavascriptParser extends Parser { | |||
| 			}); | ||||
| 		}; | ||||
| 		tapEvaluateWithVariableInfo("Identifier", expr => { | ||||
| 			const info = this.getVariableInfo( | ||||
| 				/** @type {IdentifierNode} */ (expr).name | ||||
| 			); | ||||
| 			const info = this.getVariableInfo(/** @type {Identifier} */ (expr).name); | ||||
| 			if ( | ||||
| 				typeof info === "string" || | ||||
| 				(info instanceof VariableInfo && typeof info.freeName === "string") | ||||
|  | @ -1297,7 +1309,7 @@ class JavascriptParser extends Parser { | |||
| 
 | ||||
| 		/** | ||||
| 		 * @param {"cooked" | "raw"} kind kind of values to get | ||||
| 		 * @param {TemplateLiteralNode} templateLiteralExpr TemplateLiteral expr | ||||
| 		 * @param {TemplateLiteral} templateLiteralExpr TemplateLiteral expr | ||||
| 		 * @returns {{quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[]}} Simplified template | ||||
| 		 */ | ||||
| 		const getSimplifiedTemplateResult = (kind, templateLiteralExpr) => { | ||||
|  | @ -1348,7 +1360,7 @@ class JavascriptParser extends Parser { | |||
| 		this.hooks.evaluate | ||||
| 			.for("TemplateLiteral") | ||||
| 			.tap("JavascriptParser", _node => { | ||||
| 				const node = /** @type {TemplateLiteralNode} */ (_node); | ||||
| 				const node = /** @type {TemplateLiteral} */ (_node); | ||||
| 
 | ||||
| 				const { quasis, parts } = getSimplifiedTemplateResult("cooked", node); | ||||
| 				if (parts.length === 1) { | ||||
|  | @ -1361,7 +1373,7 @@ class JavascriptParser extends Parser { | |||
| 		this.hooks.evaluate | ||||
| 			.for("TaggedTemplateExpression") | ||||
| 			.tap("JavascriptParser", _node => { | ||||
| 				const node = /** @type {TaggedTemplateExpressionNode} */ (_node); | ||||
| 				const node = /** @type {TaggedTemplateExpression} */ (_node); | ||||
| 				const tag = this.evaluateExpression(node.tag); | ||||
| 
 | ||||
| 				if (tag.isIdentifier() && tag.identifier === "String.raw") { | ||||
|  | @ -1466,7 +1478,7 @@ class JavascriptParser extends Parser { | |||
| 		this.hooks.evaluate | ||||
| 			.for("ConditionalExpression") | ||||
| 			.tap("JavascriptParser", _expr => { | ||||
| 				const expr = /** @type {ConditionalExpressionNode} */ (_expr); | ||||
| 				const expr = /** @type {ConditionalExpression} */ (_expr); | ||||
| 
 | ||||
| 				const condition = this.evaluateExpression(expr.test); | ||||
| 				const conditionValue = condition.asBool(); | ||||
|  | @ -1497,7 +1509,7 @@ class JavascriptParser extends Parser { | |||
| 		this.hooks.evaluate | ||||
| 			.for("ArrayExpression") | ||||
| 			.tap("JavascriptParser", _expr => { | ||||
| 				const expr = /** @type {ArrayExpressionNode} */ (_expr); | ||||
| 				const expr = /** @type {ArrayExpression} */ (_expr); | ||||
| 
 | ||||
| 				const items = expr.elements.map(element => { | ||||
| 					return ( | ||||
|  | @ -1564,6 +1576,10 @@ class JavascriptParser extends Parser { | |||
| 		return this.destructuringAssignmentProperties.get(node); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ExpressionNode} expr expression | ||||
| 	 * @returns {string | VariableInfoInterface | undefined} identifier | ||||
| 	 */ | ||||
| 	getRenameIdentifier(expr) { | ||||
| 		const result = this.evaluateExpression(expr); | ||||
| 		if (result.isIdentifier()) { | ||||
|  | @ -1797,10 +1813,16 @@ class JavascriptParser extends Parser { | |||
| 	} | ||||
| 
 | ||||
| 	// Real Statements
 | ||||
| 	/** | ||||
| 	 * @param {BlockStatement} statement block statement | ||||
| 	 */ | ||||
| 	preWalkBlockStatement(statement) { | ||||
| 		this.preWalkStatements(statement.body); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {BlockStatement} statement block statement | ||||
| 	 */ | ||||
| 	walkBlockStatement(statement) { | ||||
| 		this.inBlockScope(() => { | ||||
| 			const body = statement.body; | ||||
|  | @ -1811,6 +1833,9 @@ class JavascriptParser extends Parser { | |||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ExpressionStatement} statement expression statement | ||||
| 	 */ | ||||
| 	walkExpressionStatement(statement) { | ||||
| 		this.walkExpression(statement.expression); | ||||
| 	} | ||||
|  | @ -2435,6 +2460,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {VariableDeclaration} statement variable declaration | ||||
| 	 */ | ||||
| 	walkVariableDeclaration(statement) { | ||||
| 		for (const declarator of statement.declarations) { | ||||
| 			switch (declarator.type) { | ||||
|  | @ -2462,16 +2490,25 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ClassDeclaration} statement class declaration | ||||
| 	 */ | ||||
| 	blockPreWalkClassDeclaration(statement) { | ||||
| 		if (statement.id) { | ||||
| 			this.defineVariable(statement.id.name); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ClassDeclaration} statement class declaration | ||||
| 	 */ | ||||
| 	walkClassDeclaration(statement) { | ||||
| 		this.walkClass(statement); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {SwitchCase[]} switchCases switch statement | ||||
| 	 */ | ||||
| 	preWalkSwitchCases(switchCases) { | ||||
| 		for (let index = 0, len = switchCases.length; index < len; index++) { | ||||
| 			const switchCase = switchCases[index]; | ||||
|  | @ -2479,6 +2516,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {SwitchCase[]} switchCases switch statement | ||||
| 	 */ | ||||
| 	walkSwitchCases(switchCases) { | ||||
| 		this.inBlockScope(() => { | ||||
| 			const len = switchCases.length; | ||||
|  | @ -2514,10 +2554,16 @@ class JavascriptParser extends Parser { | |||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {CatchClause} catchClause catch clause | ||||
| 	 */ | ||||
| 	preWalkCatchClause(catchClause) { | ||||
| 		this.preWalkStatement(catchClause.body); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {CatchClause} catchClause catch clause | ||||
| 	 */ | ||||
| 	walkCatchClause(catchClause) { | ||||
| 		this.inBlockScope(() => { | ||||
| 			// Error binding is optional in catch clause since ECMAScript 2019
 | ||||
|  | @ -2554,6 +2600,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {AssignmentPattern} pattern assignment pattern | ||||
| 	 */ | ||||
| 	walkAssignmentPattern(pattern) { | ||||
| 		this.walkExpression(pattern.right); | ||||
| 		this.walkPattern(pattern.left); | ||||
|  | @ -2569,6 +2618,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ArrayPattern} pattern array pattern | ||||
| 	 */ | ||||
| 	walkArrayPattern(pattern) { | ||||
| 		for (let i = 0, len = pattern.elements.length; i < len; i++) { | ||||
| 			const element = pattern.elements[i]; | ||||
|  | @ -2576,6 +2628,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {RestElement} pattern rest element | ||||
| 	 */ | ||||
| 	walkRestElement(pattern) { | ||||
| 		this.walkPattern(pattern.argument); | ||||
| 	} | ||||
|  | @ -2668,12 +2723,18 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {AwaitExpression} expression await expression | ||||
| 	 */ | ||||
| 	walkAwaitExpression(expression) { | ||||
| 		if (this.scope.topLevelScope === true) | ||||
| 			this.hooks.topLevelAwait.call(expression); | ||||
| 		this.walkExpression(expression.argument); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ArrayExpression} expression array expression | ||||
| 	 */ | ||||
| 	walkArrayExpression(expression) { | ||||
| 		if (expression.elements) { | ||||
| 			this.walkExpressions(expression.elements); | ||||
|  | @ -2686,6 +2747,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ObjectExpression} expression object expression | ||||
| 	 */ | ||||
| 	walkObjectExpression(expression) { | ||||
| 		for ( | ||||
| 			let propIndex = 0, len = expression.properties.length; | ||||
|  | @ -2697,6 +2761,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {Property | SpreadElement} prop property or spread element | ||||
| 	 */ | ||||
| 	walkProperty(prop) { | ||||
| 		if (prop.type === "SpreadElement") { | ||||
| 			this.walkExpression(prop.argument); | ||||
|  | @ -2762,7 +2829,7 @@ class JavascriptParser extends Parser { | |||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {SequenceExpressionNode} expression the sequence | ||||
| 	 * @param {SequenceExpression} expression the sequence | ||||
| 	 */ | ||||
| 	walkSequenceExpression(expression) { | ||||
| 		if (!expression.expressions) return; | ||||
|  | @ -2786,10 +2853,16 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {UpdateExpression} expression the update expression | ||||
| 	 */ | ||||
| 	walkUpdateExpression(expression) { | ||||
| 		this.walkExpression(expression.argument); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {UnaryExpression} expression the unary expression | ||||
| 	 */ | ||||
| 	walkUnaryExpression(expression) { | ||||
| 		if (expression.operator === "typeof") { | ||||
| 			const result = this.callHooksForExpression( | ||||
|  | @ -2815,12 +2888,18 @@ class JavascriptParser extends Parser { | |||
| 		this.walkExpression(expression.right); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {BinaryExpression} expression the binary expression | ||||
| 	 */ | ||||
| 	walkBinaryExpression(expression) { | ||||
| 		if (this.hooks.binaryExpression.call(expression) === undefined) { | ||||
| 			this.walkLeftRightExpression(expression); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {LogicalExpression} expression the logical expression | ||||
| 	 */ | ||||
| 	walkLogicalExpression(expression) { | ||||
| 		const result = this.hooks.expressionLogicalOperator.call(expression); | ||||
| 		if (result === undefined) { | ||||
|  | @ -2832,6 +2911,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {AssignmentExpression} expression assignment expression | ||||
| 	 */ | ||||
| 	walkAssignmentExpression(expression) { | ||||
| 		if (expression.left.type === "Identifier") { | ||||
| 			const renameIdentifier = this.getRenameIdentifier(expression.right); | ||||
|  | @ -2902,6 +2984,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ConditionalExpression} expression conditional expression | ||||
| 	 */ | ||||
| 	walkConditionalExpression(expression) { | ||||
| 		const result = this.hooks.expressionConditionalOperator.call(expression); | ||||
| 		if (result === undefined) { | ||||
|  | @ -2919,6 +3004,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {NewExpression} expression new expression | ||||
| 	 */ | ||||
| 	walkNewExpression(expression) { | ||||
| 		const result = this.callHooksForExpression( | ||||
| 			this.hooks.new, | ||||
|  | @ -2944,6 +3032,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {TaggedTemplateExpression} expression tagged template expression | ||||
| 	 */ | ||||
| 	walkTaggedTemplateExpression(expression) { | ||||
| 		if (expression.tag) { | ||||
| 			this.walkExpression(expression.tag); | ||||
|  | @ -2953,6 +3044,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ClassExpression} expression the class expression | ||||
| 	 */ | ||||
| 	walkClassExpression(expression) { | ||||
| 		this.walkClass(expression); | ||||
| 	} | ||||
|  | @ -3123,6 +3217,9 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {MemberExpressionNode} expression member expression | ||||
| 	 */ | ||||
| 	walkMemberExpression(expression) { | ||||
| 		const exprInfo = this.getMemberExpressionInfo( | ||||
| 			expression, | ||||
|  | @ -3216,10 +3313,16 @@ class JavascriptParser extends Parser { | |||
| 		if (expression.computed === true) this.walkExpression(expression.property); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ThisExpression} expression this expression | ||||
| 	 */ | ||||
| 	walkThisExpression(expression) { | ||||
| 		this.callHooksForName(this.hooks.expression, "this", expression); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {Identifier} expression identifier | ||||
| 	 */ | ||||
| 	walkIdentifier(expression) { | ||||
| 		this.callHooksForName(this.hooks.expression, expression.name, expression); | ||||
| 	} | ||||
|  | @ -3741,7 +3844,7 @@ class JavascriptParser extends Parser { | |||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {ExpressionNode | DeclarationNode | PrivateIdentifierNode | null | undefined} expr an expression | ||||
| 	 * @param {ExpressionNode | DeclarationNode | PrivateIdentifier | null | undefined} expr an expression | ||||
| 	 * @param {number} commentsStartPos source position from which annotation comments are checked | ||||
| 	 * @returns {boolean} true, when the expression is pure | ||||
| 	 */ | ||||
|  | @ -3978,6 +4081,10 @@ class JavascriptParser extends Parser { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param {TagInfo} tagInfo tag info | ||||
| 	 * @returns {VariableInfo} variable info | ||||
| 	 */ | ||||
| 	evaluatedVariable(tagInfo) { | ||||
| 		return new VariableInfo(this.scope, undefined, tagInfo); | ||||
| 	} | ||||
|  |  | |||
|  | @ -5375,7 +5375,9 @@ declare class JavascriptParser extends Parser { | |||
| 	destructuringAssignmentPropertiesFor( | ||||
| 		node: Expression | ||||
| 	): undefined | Set<string>; | ||||
| 	getRenameIdentifier(expr?: any): undefined | string | VariableInfoInterface; | ||||
| 	getRenameIdentifier( | ||||
| 		expr: Expression | ||||
| 	): undefined | string | VariableInfoInterface; | ||||
| 	walkClass(classy: ClassExpression | ClassDeclaration): void; | ||||
| 	preWalkStatements(statements?: any): void; | ||||
| 	blockPreWalkStatements(statements?: any): void; | ||||
|  | @ -5390,9 +5392,9 @@ declare class JavascriptParser extends Parser { | |||
| 	 * This enforces the nested statement to never be in ASI position. | ||||
| 	 */ | ||||
| 	walkNestedStatement(statement: Statement): void; | ||||
| 	preWalkBlockStatement(statement?: any): void; | ||||
| 	walkBlockStatement(statement?: any): void; | ||||
| 	walkExpressionStatement(statement?: any): void; | ||||
| 	preWalkBlockStatement(statement: BlockStatement): void; | ||||
| 	walkBlockStatement(statement: BlockStatement): void; | ||||
| 	walkExpressionStatement(statement: ExpressionStatement): void; | ||||
| 	preWalkIfStatement(statement: IfStatement): void; | ||||
| 	walkIfStatement(statement: IfStatement): void; | ||||
| 	preWalkLabeledStatement(statement: LabeledStatement): void; | ||||
|  | @ -5430,44 +5432,44 @@ declare class JavascriptParser extends Parser { | |||
| 	preWalkVariableDeclaration(statement: VariableDeclaration): void; | ||||
| 	blockPreWalkVariableDeclaration(statement: VariableDeclaration): void; | ||||
| 	preWalkVariableDeclarator(declarator: VariableDeclarator): void; | ||||
| 	walkVariableDeclaration(statement?: any): void; | ||||
| 	blockPreWalkClassDeclaration(statement?: any): void; | ||||
| 	walkClassDeclaration(statement?: any): void; | ||||
| 	preWalkSwitchCases(switchCases?: any): void; | ||||
| 	walkSwitchCases(switchCases?: any): void; | ||||
| 	preWalkCatchClause(catchClause?: any): void; | ||||
| 	walkCatchClause(catchClause?: any): void; | ||||
| 	walkVariableDeclaration(statement: VariableDeclaration): void; | ||||
| 	blockPreWalkClassDeclaration(statement: ClassDeclaration): void; | ||||
| 	walkClassDeclaration(statement: ClassDeclaration): void; | ||||
| 	preWalkSwitchCases(switchCases: SwitchCase[]): void; | ||||
| 	walkSwitchCases(switchCases: SwitchCase[]): void; | ||||
| 	preWalkCatchClause(catchClause: CatchClause): void; | ||||
| 	walkCatchClause(catchClause: CatchClause): void; | ||||
| 	walkPattern(pattern?: any): void; | ||||
| 	walkAssignmentPattern(pattern?: any): void; | ||||
| 	walkAssignmentPattern(pattern: AssignmentPattern): void; | ||||
| 	walkObjectPattern(pattern?: any): void; | ||||
| 	walkArrayPattern(pattern?: any): void; | ||||
| 	walkRestElement(pattern?: any): void; | ||||
| 	walkArrayPattern(pattern: ArrayPattern): void; | ||||
| 	walkRestElement(pattern: RestElement): void; | ||||
| 	walkExpressions(expressions?: any): void; | ||||
| 	walkExpression(expression?: any): void; | ||||
| 	walkAwaitExpression(expression?: any): void; | ||||
| 	walkArrayExpression(expression?: any): void; | ||||
| 	walkAwaitExpression(expression: AwaitExpression): void; | ||||
| 	walkArrayExpression(expression: ArrayExpression): void; | ||||
| 	walkSpreadElement(expression?: any): void; | ||||
| 	walkObjectExpression(expression?: any): void; | ||||
| 	walkProperty(prop?: any): void; | ||||
| 	walkObjectExpression(expression: ObjectExpression): void; | ||||
| 	walkProperty(prop: Property | SpreadElement): void; | ||||
| 	walkFunctionExpression(expression?: any): void; | ||||
| 	walkArrowFunctionExpression(expression?: any): void; | ||||
| 	walkSequenceExpression(expression: SequenceExpression): void; | ||||
| 	walkUpdateExpression(expression?: any): void; | ||||
| 	walkUnaryExpression(expression?: any): void; | ||||
| 	walkUpdateExpression(expression: UpdateExpression): void; | ||||
| 	walkUnaryExpression(expression: UnaryExpression): void; | ||||
| 	walkLeftRightExpression(expression?: any): void; | ||||
| 	walkBinaryExpression(expression?: any): void; | ||||
| 	walkLogicalExpression(expression?: any): void; | ||||
| 	walkAssignmentExpression(expression?: any): void; | ||||
| 	walkConditionalExpression(expression?: any): void; | ||||
| 	walkNewExpression(expression?: any): void; | ||||
| 	walkBinaryExpression(expression: BinaryExpression): void; | ||||
| 	walkLogicalExpression(expression: LogicalExpression): void; | ||||
| 	walkAssignmentExpression(expression: AssignmentExpression): void; | ||||
| 	walkConditionalExpression(expression: ConditionalExpression): void; | ||||
| 	walkNewExpression(expression: NewExpression): void; | ||||
| 	walkYieldExpression(expression?: any): void; | ||||
| 	walkTemplateLiteral(expression?: any): void; | ||||
| 	walkTaggedTemplateExpression(expression?: any): void; | ||||
| 	walkClassExpression(expression?: any): void; | ||||
| 	walkTaggedTemplateExpression(expression: TaggedTemplateExpression): void; | ||||
| 	walkClassExpression(expression: ClassExpression): void; | ||||
| 	walkChainExpression(expression: ChainExpression): void; | ||||
| 	walkImportExpression(expression: ImportExpression): void; | ||||
| 	walkCallExpression(expression?: any): void; | ||||
| 	walkMemberExpression(expression?: any): void; | ||||
| 	walkMemberExpression(expression: MemberExpression): void; | ||||
| 	walkMemberExpressionWithExpressionName( | ||||
| 		expression?: any, | ||||
| 		name?: any, | ||||
|  | @ -5475,8 +5477,8 @@ declare class JavascriptParser extends Parser { | |||
| 		members?: any, | ||||
| 		onUnhandled?: any | ||||
| 	): void; | ||||
| 	walkThisExpression(expression?: any): void; | ||||
| 	walkIdentifier(expression?: any): void; | ||||
| 	walkThisExpression(expression: ThisExpression): void; | ||||
| 	walkIdentifier(expression: Identifier): void; | ||||
| 	walkMetaProperty(metaProperty: MetaProperty): void; | ||||
| 	callHooksForExpression(hookMap: any, expr: any, ...args: any[]): any; | ||||
| 	callHooksForExpressionWithFallback<T, R>( | ||||
|  | @ -5577,7 +5579,7 @@ declare class JavascriptParser extends Parser { | |||
| 	isVariableDefined(name: string): boolean; | ||||
| 	getVariableInfo(name: string): ExportedVariableInfo; | ||||
| 	setVariable(name: string, variableInfo: ExportedVariableInfo): void; | ||||
| 	evaluatedVariable(tagInfo?: any): VariableInfo; | ||||
| 	evaluatedVariable(tagInfo: TagInfo): VariableInfo; | ||||
| 	parseCommentOptions(range: [number, number]): any; | ||||
| 	extractMemberExpressionChain(expression: MemberExpression): { | ||||
| 		members: string[]; | ||||
|  | @ -7761,21 +7763,21 @@ type NodeEstreeIndex = | |||
| 	| PropertyDefinition | ||||
| 	| VariableDeclarator | ||||
| 	| Program | ||||
| 	| AssignmentProperty | ||||
| 	| Property | ||||
| 	| SwitchCase | ||||
| 	| CatchClause | ||||
| 	| AssignmentPattern | ||||
| 	| ArrayPattern | ||||
| 	| RestElement | ||||
| 	| Property | ||||
| 	| SpreadElement | ||||
| 	| AssignmentProperty | ||||
| 	| ClassBody | ||||
| 	| ImportSpecifier | ||||
| 	| ImportDefaultSpecifier | ||||
| 	| ImportNamespaceSpecifier | ||||
| 	| ExportSpecifier | ||||
| 	| ObjectPattern | ||||
| 	| ArrayPattern | ||||
| 	| RestElement | ||||
| 	| AssignmentPattern | ||||
| 	| SpreadElement | ||||
| 	| Super | ||||
| 	| SwitchCase | ||||
| 	| TemplateElement; | ||||
| 
 | ||||
| /** | ||||
|  | @ -11079,7 +11081,7 @@ declare interface RuntimeValueOptions { | |||
| declare interface ScopeInfo { | ||||
| 	definitions: StackedMap<string, ScopeInfo | VariableInfo>; | ||||
| 	topLevelScope: boolean | "arrow"; | ||||
| 	inShorthand: boolean; | ||||
| 	inShorthand: string | boolean; | ||||
| 	isStrict: boolean; | ||||
| 	isAsmJs: boolean; | ||||
| 	inTry: boolean; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue