Skip to content

Commit 9c99870

Browse files
authored
Support element access aliases: exports["x"] = x (microsoft#40514)
1 parent eee799f commit 9c99870

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ namespace ts {
24082408
|| node.kind === SyntaxKind.ExportSpecifier
24092409
|| node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(<ExportAssignment>node)
24102410
|| isBinaryExpression(node) && getAssignmentDeclarationKind(node) === AssignmentDeclarationKind.ModuleExports && exportAssignmentIsAlias(node)
2411-
|| isPropertyAccessExpression(node)
2411+
|| isAccessExpression(node)
24122412
&& isBinaryExpression(node.parent)
24132413
&& node.parent.left === node
24142414
&& node.parent.operatorToken.kind === SyntaxKind.EqualsToken
@@ -2803,7 +2803,7 @@ namespace ts {
28032803
return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve);
28042804
}
28052805

2806-
function getTargetOfPropertyAccessExpression(node: PropertyAccessExpression, dontRecursivelyResolve: boolean): Symbol | undefined {
2806+
function getTargetOfAccessExpression(node: AccessExpression, dontRecursivelyResolve: boolean): Symbol | undefined {
28072807
if (!(isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === SyntaxKind.EqualsToken)) {
28082808
return undefined;
28092809
}
@@ -2836,8 +2836,9 @@ namespace ts {
28362836
return resolveEntityName((node as ShorthandPropertyAssignment).name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ true, dontRecursivelyResolve);
28372837
case SyntaxKind.PropertyAssignment:
28382838
return getTargetOfPropertyAssignment(node as PropertyAssignment, dontRecursivelyResolve);
2839+
case SyntaxKind.ElementAccessExpression:
28392840
case SyntaxKind.PropertyAccessExpression:
2840-
return getTargetOfPropertyAccessExpression(node as PropertyAccessExpression, dontRecursivelyResolve);
2841+
return getTargetOfAccessExpression(node as AccessExpression, dontRecursivelyResolve);
28412842
default:
28422843
return Debug.fail();
28432844
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/conformance/salsa/moduleExportAliasElementAccessExpression.js ===
2+
function D () { }
3+
>D : Symbol(D, Decl(moduleExportAliasElementAccessExpression.js, 0, 0))
4+
5+
exports["D"] = D;
6+
>exports : Symbol("tests/cases/conformance/salsa/moduleExportAliasElementAccessExpression", Decl(moduleExportAliasElementAccessExpression.js, 0, 0))
7+
>"D" : Symbol("D", Decl(moduleExportAliasElementAccessExpression.js, 0, 17))
8+
>D : Symbol(D, Decl(moduleExportAliasElementAccessExpression.js, 0, 0))
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/conformance/salsa/moduleExportAliasElementAccessExpression.js ===
2+
function D () { }
3+
>D : () => void
4+
5+
exports["D"] = D;
6+
>exports["D"] = D : () => void
7+
>exports["D"] : () => void
8+
>exports : typeof import("tests/cases/conformance/salsa/moduleExportAliasElementAccessExpression")
9+
>"D" : "D"
10+
>D : () => void
11+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @noEmit: true
2+
// @checkJs: true
3+
// @filename: moduleExportAliasElementAccessExpression.js
4+
5+
function D () { }
6+
exports["D"] = D;

0 commit comments

Comments
 (0)