-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make getNameOfDeclaration public #15958
Changes from 1 commit
8db58bb
6c4e747
c70fa1e
3c6393a
fea8561
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1776,36 +1776,6 @@ namespace ts { | |
} | ||
} | ||
|
||
export function getNameOfDeclaration(declaration: Declaration): DeclarationName { | ||
if (!declaration) { | ||
return undefined; | ||
} | ||
if (declaration.kind === SyntaxKind.BinaryExpression) { | ||
const kind = getSpecialPropertyAssignmentKind(declaration as BinaryExpression); | ||
const lhs = (declaration as BinaryExpression).left; | ||
switch (kind) { | ||
case SpecialPropertyAssignmentKind.None: | ||
case SpecialPropertyAssignmentKind.ModuleExports: | ||
return undefined; | ||
case SpecialPropertyAssignmentKind.ExportsProperty: | ||
if (lhs.kind === SyntaxKind.Identifier) { | ||
return (lhs as PropertyAccessExpression).name; | ||
} | ||
else { | ||
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; | ||
} | ||
case SpecialPropertyAssignmentKind.ThisProperty: | ||
case SpecialPropertyAssignmentKind.Property: | ||
return (lhs as PropertyAccessExpression).name; | ||
case SpecialPropertyAssignmentKind.PrototypeProperty: | ||
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; | ||
} | ||
} | ||
else { | ||
return (declaration as NamedDeclaration).name; | ||
} | ||
} | ||
|
||
export function isLiteralComputedPropertyDeclarationName(node: Node) { | ||
return (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) && | ||
node.parent.kind === SyntaxKind.ComputedPropertyName && | ||
|
@@ -4729,4 +4699,34 @@ namespace ts { | |
export function unescapeIdentifier(identifier: string): string { | ||
return identifier.length >= 3 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ && identifier.charCodeAt(2) === CharacterCodes._ ? identifier.substr(1) : identifier; | ||
} | ||
|
||
export function getNameOfDeclaration(declaration: Declaration): DeclarationName { | ||
if (!declaration) { | ||
return undefined; | ||
} | ||
if (declaration.kind === SyntaxKind.BinaryExpression) { | ||
const kind = getSpecialPropertyAssignmentKind(declaration as BinaryExpression); | ||
const lhs = (declaration as BinaryExpression).left; | ||
switch (kind) { | ||
case SpecialPropertyAssignmentKind.None: | ||
case SpecialPropertyAssignmentKind.ModuleExports: | ||
return undefined; | ||
case SpecialPropertyAssignmentKind.ExportsProperty: | ||
if (lhs.kind === SyntaxKind.Identifier) { | ||
return (lhs as PropertyAccessExpression).name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The answer to both your comments is that this code is closely couple to the result of In this case, the code is wrong and should be checking |
||
} | ||
else { | ||
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the special property assignment kind is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Furthermore, in the case that So actually this code is wrong too. Changing it doesn't break any tests either, which is very suspicious. I don't think our checkJs coverage is very good. |
||
} | ||
case SpecialPropertyAssignmentKind.ThisProperty: | ||
case SpecialPropertyAssignmentKind.Property: | ||
return (lhs as PropertyAccessExpression).name; | ||
case SpecialPropertyAssignmentKind.PrototypeProperty: | ||
return ((lhs as PropertyAccessExpression).expression as PropertyAccessExpression).name; | ||
} | ||
} | ||
else { | ||
return (declaration as NamedDeclaration).name; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark return type as
DeclarationName | undefined
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done