mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Nested assignment to a require alias isn't a declaration (#40186)
This is not something we can type correctly, and doesn't work in Typescript either. Better to ignore it in JS.
This commit is contained in:
committed by
GitHub
parent
5fd5a758a3
commit
378083fcec
@@ -2974,6 +2974,10 @@ namespace ts {
|
||||
if (!isInJSFile(node) && !isFunctionSymbol(parentSymbol)) {
|
||||
return;
|
||||
}
|
||||
const rootExpr = getLeftmostAccessExpression(node.left);
|
||||
if (isIdentifier(rootExpr) && lookupSymbolForName(container, rootExpr.escapedText)!?.flags & SymbolFlags.Alias) {
|
||||
return;
|
||||
}
|
||||
// Fix up parent pointers since we're going to use these nodes before we bind into them
|
||||
setParent(node.left, node);
|
||||
setParent(node.right, node);
|
||||
|
||||
@@ -2416,7 +2416,7 @@ namespace ts {
|
||||
|
||||
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration | VariableDeclaration, dontResolveAlias: boolean): Symbol | undefined {
|
||||
if (isVariableDeclaration(node) && node.initializer && isPropertyAccessExpression(node.initializer)) {
|
||||
const name = (getLeftmostPropertyAccessExpression(node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
|
||||
const name = (getLeftmostAccessExpression(node.initializer.expression) as CallExpression).arguments[0] as StringLiteral;
|
||||
return isIdentifier(node.initializer.name)
|
||||
? resolveSymbol(getPropertyOfType(resolveExternalModuleTypeByLiteral(name), node.initializer.name.escapedText))
|
||||
: undefined;
|
||||
|
||||
@@ -1869,7 +1869,7 @@ namespace ts {
|
||||
|
||||
export function getExternalModuleRequireArgument(node: Node) {
|
||||
return isRequireVariableDeclaration(node, /*requireStringLiteralLikeArgument*/ true)
|
||||
&& (getLeftmostPropertyAccessExpression(node.initializer) as CallExpression).arguments[0] as StringLiteral;
|
||||
&& (getLeftmostAccessExpression(node.initializer) as CallExpression).arguments[0] as StringLiteral;
|
||||
}
|
||||
|
||||
export function isInternalModuleImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration {
|
||||
@@ -1940,7 +1940,7 @@ namespace ts {
|
||||
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: boolean): node is VariableDeclaration;
|
||||
export function isRequireVariableDeclaration(node: Node, requireStringLiteralLikeArgument: boolean): node is VariableDeclaration {
|
||||
node = getRootDeclaration(node);
|
||||
return isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostPropertyAccessExpression(node.initializer), requireStringLiteralLikeArgument);
|
||||
return isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), requireStringLiteralLikeArgument);
|
||||
}
|
||||
|
||||
export function isRequireVariableStatement(node: Node, requireStringLiteralLikeArgument = true): node is RequireVariableStatement {
|
||||
@@ -5463,8 +5463,8 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.NamedImports || node.kind === SyntaxKind.NamedExports;
|
||||
}
|
||||
|
||||
export function getLeftmostPropertyAccessExpression(expr: Expression): Expression {
|
||||
while (isPropertyAccessExpression(expr)) {
|
||||
export function getLeftmostAccessExpression(expr: Expression): Expression {
|
||||
while (isAccessExpression(expr)) {
|
||||
expr = expr.expression;
|
||||
}
|
||||
return expr;
|
||||
|
||||
Reference in New Issue
Block a user