mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-02 14:48:32 -05:00
Merge pull request #15741 from Microsoft/import_propertyName_isWriteAccess
isDeclarationName: Return false for LHS of `import { x as y }` and `e…
This commit is contained in:
@@ -22254,7 +22254,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isDeclarationName(node)) {
|
||||
if (isDeclarationNameOrImportPropertyName(node)) {
|
||||
// This is a declaration, call getSymbolOfNode
|
||||
return getSymbolOfNode(node.parent);
|
||||
}
|
||||
@@ -22401,7 +22401,7 @@ namespace ts {
|
||||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
|
||||
if (isDeclarationName(node)) {
|
||||
if (isDeclarationNameOrImportPropertyName(node)) {
|
||||
const symbol = getSymbolAtLocation(node);
|
||||
return symbol && getTypeOfSymbol(symbol);
|
||||
}
|
||||
@@ -24430,4 +24430,19 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */
|
||||
function isDeclarationNameOrImportPropertyName(name: Node): boolean {
|
||||
switch (name.parent.kind) {
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
if ((name.parent as ImportOrExportSpecifier).propertyName) {
|
||||
return true;
|
||||
}
|
||||
// falls through
|
||||
default:
|
||||
return isDeclarationName(name);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1758,22 +1758,14 @@ namespace ts {
|
||||
|
||||
// True if the given identifier, string literal, or number literal is the name of a declaration node
|
||||
export function isDeclarationName(name: Node): boolean {
|
||||
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) {
|
||||
return false;
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
return isDeclaration(name.parent) && name.parent.name === name;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
const parent = name.parent;
|
||||
if (parent.kind === SyntaxKind.ImportSpecifier || parent.kind === SyntaxKind.ExportSpecifier) {
|
||||
if ((<ImportOrExportSpecifier>parent).propertyName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDeclaration(parent)) {
|
||||
return parent.name === name;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getNameOfDeclaration(declaration: Declaration): DeclarationName {
|
||||
|
||||
Reference in New Issue
Block a user