More reliable mechanism for _this/_super simplification (#56130)

This commit is contained in:
Ron Buckton
2023-10-23 21:01:11 -04:00
committed by GitHub
parent e5e7cbba79
commit 8e37e4b853
38 changed files with 770 additions and 350 deletions
+22
View File
@@ -1,5 +1,6 @@
import {
__String,
AccessorDeclaration,
addRange,
append,
appendIfUnique,
@@ -1180,6 +1181,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
mergeLexicalEnvironment,
replaceModifiers,
replaceDecoratorsAndModifiers,
replacePropertyName,
};
forEach(nodeFactoryPatchers, fn => fn(factory));
@@ -7149,6 +7151,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
Debug.assertNever(node);
}
function replacePropertyName<T extends AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment>(node: T, name: T["name"]): T;
function replacePropertyName(node: AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment, name: PropertyName) {
switch (node.kind) {
case SyntaxKind.GetAccessor:
return updateGetAccessorDeclaration(node, node.modifiers, name, node.parameters, node.type, node.body);
case SyntaxKind.SetAccessor:
return updateSetAccessorDeclaration(node, node.modifiers, name, node.parameters, node.body);
case SyntaxKind.MethodDeclaration:
return updateMethodDeclaration(node, node.modifiers, node.asteriskToken, name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
case SyntaxKind.MethodSignature:
return updateMethodSignature(node, node.modifiers, name, node.questionToken, node.typeParameters, node.parameters, node.type);
case SyntaxKind.PropertyDeclaration:
return updatePropertyDeclaration(node, node.modifiers, name, node.questionToken ?? node.exclamationToken, node.type, node.initializer);
case SyntaxKind.PropertySignature:
return updatePropertySignature(node, node.modifiers, name, node.questionToken, node.type);
case SyntaxKind.PropertyAssignment:
return updatePropertyAssignment(node, name, node.initializer);
}
}
function asNodeArray<T extends Node>(array: readonly T[]): NodeArray<T>;
function asNodeArray<T extends Node>(array: readonly T[] | undefined): NodeArray<T> | undefined;
function asNodeArray<T extends Node>(array: readonly T[] | undefined): NodeArray<T> | undefined {
File diff suppressed because it is too large Load Diff
+4
View File
@@ -9080,6 +9080,10 @@ export interface NodeFactory {
* Updates a node that may contain decorators or modifiers, replacing only the decorators and modifiers of the node.
*/
replaceDecoratorsAndModifiers<T extends HasModifiers & HasDecorators>(node: T, modifiers: readonly ModifierLike[] | undefined): T;
/**
* Updates a node that contains a property name, replacing only the name of the node.
*/
replacePropertyName<T extends AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment>(node: T, name: T["name"]): T;
}
/** @internal */