@@ -814,6 +814,10 @@ module ts {
814
814
return createNode ( SyntaxKind . Missing ) ;
815
815
}
816
816
817
+ function internIdentifier ( text : string ) : string {
818
+ return hasProperty ( identifiers , text ) ? identifiers [ text ] : ( identifiers [ text ] = text ) ;
819
+ }
820
+
817
821
// An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues
818
822
// with magic property names like '__proto__'. The 'identifiers' object is used to share a single string instance for
819
823
// each identifier in order to reduce memory consumption.
@@ -822,7 +826,7 @@ module ts {
822
826
if ( isIdentifier ) {
823
827
var node = < Identifier > createNode ( SyntaxKind . Identifier ) ;
824
828
var text = escapeIdentifier ( scanner . getTokenValue ( ) ) ;
825
- node . text = hasProperty ( identifiers , text ) ? identifiers [ text ] : ( identifiers [ text ] = text ) ;
829
+ node . text = internIdentifier ( text ) ;
826
830
nextToken ( ) ;
827
831
return finishNode ( node ) ;
828
832
}
@@ -844,7 +848,7 @@ module ts {
844
848
845
849
function parsePropertyName ( ) : Identifier {
846
850
if ( token === SyntaxKind . StringLiteral || token === SyntaxKind . NumericLiteral ) {
847
- return < LiteralExpression > parsePrimaryExpression ( ) ;
851
+ return parseLiteralNode ( /*internName:*/ true ) ;
848
852
}
849
853
return parseIdentifierName ( ) ;
850
854
}
@@ -1125,9 +1129,11 @@ module ts {
1125
1129
return finishNode ( node ) ;
1126
1130
}
1127
1131
1128
- function parseLiteralNode ( ) : LiteralExpression {
1132
+ function parseLiteralNode ( internName ?: boolean ) : LiteralExpression {
1129
1133
var node = < LiteralExpression > createNode ( token ) ;
1130
- node . text = scanner . getTokenValue ( ) ;
1134
+ var text = scanner . getTokenValue ( ) ;
1135
+ node . text = internName ? internIdentifier ( text ) : text ;
1136
+
1131
1137
var tokenPos = scanner . getTokenPos ( ) ;
1132
1138
nextToken ( ) ;
1133
1139
finishNode ( node ) ;
@@ -1154,7 +1160,7 @@ module ts {
1154
1160
}
1155
1161
1156
1162
function parseStringLiteral ( ) : LiteralExpression {
1157
- if ( token === SyntaxKind . StringLiteral ) return parseLiteralNode ( ) ;
1163
+ if ( token === SyntaxKind . StringLiteral ) return parseLiteralNode ( /*internName:*/ true ) ;
1158
1164
error ( Diagnostics . String_literal_expected ) ;
1159
1165
return < LiteralExpression > createMissingNode ( ) ;
1160
1166
}
@@ -2058,6 +2064,10 @@ module ts {
2058
2064
}
2059
2065
else {
2060
2066
indexedAccess . index = parseExpression ( ) ;
2067
+ if ( indexedAccess . index . kind === SyntaxKind . StringLiteral || indexedAccess . index . kind === SyntaxKind . NumericLiteral ) {
2068
+ var literal = < LiteralExpression > indexedAccess . index ;
2069
+ literal . text = internIdentifier ( literal . text ) ;
2070
+ }
2061
2071
parseExpected ( SyntaxKind . CloseBracketToken ) ;
2062
2072
}
2063
2073
@@ -3611,6 +3621,7 @@ module ts {
3611
3621
file . version = version ;
3612
3622
file . isOpen = isOpen ;
3613
3623
file . languageVersion = languageVersion ;
3624
+ file . identifiers = identifiers ;
3614
3625
return file ;
3615
3626
}
3616
3627
0 commit comments