Skip to content

Commit 596e08a

Browse files
committed
Fix binding well-known symbols by element access
1 parent 98cf317 commit 596e08a

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/compiler/types.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,14 @@ namespace ts {
819819

820820
export type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName;
821821

822-
export type DeclarationName = Identifier | StringLiteralLike | NumericLiteral | ComputedPropertyName | ElementAccessExpression | BindingPattern;
822+
export type DeclarationName =
823+
| Identifier
824+
| StringLiteralLike
825+
| NumericLiteral
826+
| ComputedPropertyName
827+
| ElementAccessExpression
828+
| BindingPattern
829+
| WellKnownSymbolExpression;
823830

824831
export interface Declaration extends Node {
825832
_declarationBrand: any;
@@ -1884,13 +1891,17 @@ namespace ts {
18841891
| CallChainRoot
18851892
;
18861893

1894+
/** @internal */
1895+
export interface WellKnownSymbolExpression extends PropertyAccessExpression {
1896+
expression: Identifier & { escapedText: "Symbol" };
1897+
}
18871898
/** @internal */
18881899
export type BindableObjectDefinePropertyCall = CallExpression & { arguments: { 0: BindableStaticNameExpression, 1: StringLiteralLike | NumericLiteral, 2: ObjectLiteralExpression } };
18891900
/** @internal */
18901901
export type BindableStaticNameExpression = EntityNameExpression | BindableStaticElementAccessExpression;
18911902
/** @internal */
18921903
export type LiteralLikeElementAccessExpression = ElementAccessExpression & Declaration & {
1893-
argumentExpression: StringLiteralLike | NumericLiteral;
1904+
argumentExpression: StringLiteralLike | NumericLiteral | WellKnownSymbolExpression;
18941905
};
18951906
/** @internal */
18961907
export type BindableStaticElementAccessExpression = LiteralLikeElementAccessExpression & {

src/compiler/utilities.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,9 @@ namespace ts {
20682068
}
20692069

20702070
export function isLiteralLikeElementAccess(node: Node): node is LiteralLikeElementAccessExpression {
2071-
return isElementAccessExpression(node) && isStringOrNumericLiteralLike(node.argumentExpression);
2071+
return isElementAccessExpression(node) && (
2072+
isStringOrNumericLiteralLike(node.argumentExpression) ||
2073+
isWellKnownSymbolSyntactically(node.argumentExpression));
20722074
}
20732075

20742076
export function isBindableStaticAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticAccessExpression {
@@ -2898,7 +2900,7 @@ namespace ts {
28982900
* Symbol.name
28992901
* where Symbol is literally the word "Symbol", and name is any identifierName
29002902
*/
2901-
export function isWellKnownSymbolSyntactically(node: Expression): boolean {
2903+
export function isWellKnownSymbolSyntactically(node: Expression): node is WellKnownSymbolExpression {
29022904
return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression);
29032905
}
29042906

src/services/navigationBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace ts.NavigationBar {
136136
for (let i = 0; i < depth; i++) endNode();
137137
}
138138
function startNestedNodes(targetNode: Node, entityName: BindableStaticNameExpression) {
139-
const names: PropertyNameLiteral[] = [];
139+
const names: (PropertyNameLiteral | WellKnownSymbolExpression)[] = [];
140140
while (!isPropertyNameLiteral(entityName)) {
141141
const name = getNameOrArgument(entityName);
142142
const nameText = getElementOrPropertyAccessName(entityName);
@@ -334,7 +334,7 @@ namespace ts.NavigationBar {
334334
assignmentTarget;
335335

336336
let depth = 0;
337-
let className: PropertyNameLiteral;
337+
let className: PropertyNameLiteral | WellKnownSymbolExpression;
338338
// If we see a prototype assignment, start tracking the target as a class
339339
// This is only done for simple classes not nested assignments.
340340
if (isIdentifier(prototypeAccess.expression)) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @noEmit: true
2+
// @target: esnext
3+
4+
function f() {}
5+
f[Symbol.iterator] = function() {}

0 commit comments

Comments
 (0)