@@ -91,7 +91,7 @@ namespace ts {
91
91
92
92
// If this file is an external module, then it is automatically in strict-mode according to
93
93
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
94
- // not depending on if we see "use strict" in certain places.
94
+ // not depending on if we see "use strict" in certain places (or if we hit a class/namespace) .
95
95
let inStrictMode = ! ! file . externalModuleIndicator ;
96
96
97
97
let symbolCount = 0 ;
@@ -538,10 +538,13 @@ namespace ts {
538
538
}
539
539
540
540
function bindObjectLiteralExpression ( node : ObjectLiteralExpression ) {
541
+ const enum ElementKind {
542
+ Property = 1 ,
543
+ Accessor = 2
544
+ }
545
+
541
546
if ( inStrictMode ) {
542
- let seen : Map < number > = { } ;
543
- const Property = 1 ;
544
- const NonProperty = 2 ;
547
+ let seen : Map < ElementKind > = { } ;
545
548
546
549
for ( let prop of node . properties ) {
547
550
if ( prop . name . kind !== SyntaxKind . Identifier ) {
@@ -559,16 +562,16 @@ namespace ts {
559
562
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
560
563
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
561
564
let currentKind = prop . kind === SyntaxKind . PropertyAssignment || prop . kind === SyntaxKind . ShorthandPropertyAssignment || prop . kind === SyntaxKind . MethodDeclaration
562
- ? Property
563
- : NonProperty ;
565
+ ? ElementKind . Property
566
+ : ElementKind . Accessor ;
564
567
565
568
let existingKind = seen [ identifier . text ] ;
566
569
if ( ! existingKind ) {
567
570
seen [ identifier . text ] = currentKind ;
568
571
continue ;
569
572
}
570
573
571
- if ( currentKind === Property && existingKind === Property ) {
574
+ if ( currentKind === ElementKind . Property && existingKind === ElementKind . Property ) {
572
575
let span = getErrorSpanForNode ( file , identifier ) ;
573
576
file . bindDiagnostics . push ( createFileDiagnostic ( file , span . start , span . length ,
574
577
Diagnostics . An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode ) ) ;
@@ -798,17 +801,16 @@ namespace ts {
798
801
return ;
799
802
}
800
803
801
- if ( isUseStrictPrologueDirective ( statement ) ) {
804
+ if ( isUseStrictPrologueDirective ( < ExpressionStatement > statement ) ) {
802
805
inStrictMode = true ;
803
806
return ;
804
807
}
805
808
}
806
809
}
807
810
808
811
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
809
- function isUseStrictPrologueDirective ( node : Node ) : boolean {
810
- Debug . assert ( isPrologueDirective ( node ) ) ;
811
- let nodeText = getTextOfNodeFromSourceText ( file . text , ( < ExpressionStatement > node ) . expression ) ;
812
+ function isUseStrictPrologueDirective ( node : ExpressionStatement ) : boolean {
813
+ let nodeText = getTextOfNodeFromSourceText ( file . text , node . expression ) ;
812
814
813
815
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
814
816
// string to contain unicode escapes (as per ES5).
@@ -838,9 +840,9 @@ namespace ts {
838
840
return declareSymbolAndAddToSymbolTable ( < Declaration > node , SymbolFlags . TypeParameter , SymbolFlags . TypeParameterExcludes ) ;
839
841
case SyntaxKind . Parameter :
840
842
return bindParameter ( < ParameterDeclaration > node ) ;
841
- case SyntaxKind . BindingElement :
842
843
case SyntaxKind . VariableDeclaration :
843
- return bindVariableDeclarationOrBindingElement ( < BindingElement | VariableDeclaration > node ) ;
844
+ case SyntaxKind . BindingElement :
845
+ return bindVariableDeclarationOrBindingElement ( < VariableDeclaration | BindingElement > node ) ;
844
846
case SyntaxKind . PropertyDeclaration :
845
847
case SyntaxKind . PropertySignature :
846
848
return bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property | ( ( < PropertyDeclaration > node ) . questionToken ? SymbolFlags . Optional : SymbolFlags . None ) , SymbolFlags . PropertyExcludes ) ;
0 commit comments