mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Do not rename references to class inside of the class body function
This commit is contained in:
@@ -3780,7 +3780,7 @@ namespace ts {
|
||||
function substituteExpressionIdentifier(node: Identifier): Identifier {
|
||||
if (enabledSubstitutions & ES2015SubstitutionFlags.BlockScopedBindings && !isInternalName(node)) {
|
||||
const declaration = resolver.getReferencedDeclarationWithCollidingName(node);
|
||||
if (declaration) {
|
||||
if (declaration && !(isClassLike(declaration) && isPartOfClassBody(declaration, node))) {
|
||||
return setTextRange(getGeneratedNameForNode(declaration.name), node);
|
||||
}
|
||||
}
|
||||
@@ -3788,6 +3788,32 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
function isPartOfClassBody(declaration: ClassLikeDeclaration, node: Identifier) {
|
||||
let currentNode = getParseTreeNode(node);
|
||||
if (!currentNode || currentNode === declaration || currentNode.end <= declaration.pos || currentNode.pos >= declaration.end) {
|
||||
// if the node has no correlation to a parse tree node, its definitely not
|
||||
// part of the body.
|
||||
// if the node is outside of the document range of the declaration, its
|
||||
// definitely not part of the body.
|
||||
return false;
|
||||
}
|
||||
const blockScope = getEnclosingBlockScopeContainer(declaration);
|
||||
while (currentNode) {
|
||||
if (currentNode === blockScope || currentNode === declaration) {
|
||||
// if we are in the enclosing block scope of the declaration, we are definitely
|
||||
// not inside the class body.
|
||||
return false;
|
||||
}
|
||||
if (isClassElement(currentNode) && currentNode.parent === declaration) {
|
||||
// we are in the class body, but we treat static fields as outside of the class body
|
||||
return currentNode.kind !== SyntaxKind.PropertyDeclaration
|
||||
|| (getModifierFlags(currentNode) & ModifierFlags.Static) === 0;
|
||||
}
|
||||
currentNode = currentNode.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes `this` when contained within an arrow function.
|
||||
*
|
||||
@@ -3803,7 +3829,7 @@ namespace ts {
|
||||
|
||||
function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) {
|
||||
return hasModifier(member, ModifierFlags.Static)
|
||||
? getLocalName(node)
|
||||
? getInternalName(node)
|
||||
: createPropertyAccess(getInternalName(node), "prototype");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user