@@ -16,52 +16,63 @@ namespace ts {
16
16
referenced : boolean ;
17
17
}
18
18
19
- export function getModuleInstanceState ( node : Node ) : ModuleInstanceState {
19
+ export function getModuleInstanceState ( node : ModuleDeclaration ) : ModuleInstanceState {
20
+ return node . body ? getModuleInstanceStateWorker ( node . body ) : ModuleInstanceState . Instantiated ;
21
+ }
22
+
23
+ function getModuleInstanceStateWorker ( node : Node ) : ModuleInstanceState {
20
24
// A module is uninstantiated if it contains only
21
- // 1. interface declarations, type alias declarations
22
- if ( node . kind === SyntaxKind . InterfaceDeclaration || node . kind === SyntaxKind . TypeAliasDeclaration ) {
23
- return ModuleInstanceState . NonInstantiated ;
24
- }
25
- // 2. const enum declarations
26
- else if ( isConstEnumDeclaration ( node ) ) {
27
- return ModuleInstanceState . ConstEnumOnly ;
28
- }
29
- // 3. non-exported import declarations
30
- else if ( ( node . kind === SyntaxKind . ImportDeclaration || node . kind === SyntaxKind . ImportEqualsDeclaration ) && ! ( hasModifier ( node , ModifierFlags . Export ) ) ) {
31
- return ModuleInstanceState . NonInstantiated ;
32
- }
33
- // 4. other uninstantiated module declarations.
34
- else if ( node . kind === SyntaxKind . ModuleBlock ) {
35
- let state = ModuleInstanceState . NonInstantiated ;
36
- forEachChild ( node , n => {
37
- switch ( getModuleInstanceState ( n ) ) {
38
- case ModuleInstanceState . NonInstantiated :
39
- // child is non-instantiated - continue searching
40
- return false ;
41
- case ModuleInstanceState . ConstEnumOnly :
42
- // child is const enum only - record state and continue searching
43
- state = ModuleInstanceState . ConstEnumOnly ;
44
- return false ;
45
- case ModuleInstanceState . Instantiated :
46
- // child is instantiated - record state and stop
47
- state = ModuleInstanceState . Instantiated ;
48
- return true ;
25
+ switch ( node . kind ) {
26
+ // 1. interface declarations, type alias declarations
27
+ case SyntaxKind . InterfaceDeclaration :
28
+ case SyntaxKind . TypeAliasDeclaration :
29
+ return ModuleInstanceState . NonInstantiated ;
30
+ // 2. const enum declarations
31
+ case SyntaxKind . EnumDeclaration :
32
+ if ( isConst ( node ) ) {
33
+ return ModuleInstanceState . ConstEnumOnly ;
34
+ }
35
+ break ;
36
+ // 3. non-exported import declarations
37
+ case SyntaxKind . ImportDeclaration :
38
+ case SyntaxKind . ImportEqualsDeclaration :
39
+ if ( ! ( hasModifier ( node , ModifierFlags . Export ) ) ) {
40
+ return ModuleInstanceState . NonInstantiated ;
41
+ }
42
+ break ;
43
+ // 4. other uninstantiated module declarations.
44
+ case SyntaxKind . ModuleBlock : {
45
+ let state = ModuleInstanceState . NonInstantiated ;
46
+ forEachChild ( node , n => {
47
+ const childState = getModuleInstanceStateWorker ( n ) ;
48
+ switch ( childState ) {
49
+ case ModuleInstanceState . NonInstantiated :
50
+ // child is non-instantiated - continue searching
51
+ return ;
52
+ case ModuleInstanceState . ConstEnumOnly :
53
+ // child is const enum only - record state and continue searching
54
+ state = ModuleInstanceState . ConstEnumOnly ;
55
+ return ;
56
+ case ModuleInstanceState . Instantiated :
57
+ // child is instantiated - record state and stop
58
+ state = ModuleInstanceState . Instantiated ;
59
+ return true ;
60
+ default :
61
+ Debug . assertNever ( childState ) ;
62
+ }
63
+ } ) ;
64
+ return state ;
65
+ }
66
+ case SyntaxKind . ModuleDeclaration :
67
+ return getModuleInstanceState ( node as ModuleDeclaration ) ;
68
+ case SyntaxKind . Identifier :
69
+ // Only jsdoc typedef definition can exist in jsdoc namespace, and it should
70
+ // be considered the same as type alias
71
+ if ( ( < Identifier > node ) . isInJSDocNamespace ) {
72
+ return ModuleInstanceState . NonInstantiated ;
49
73
}
50
- } ) ;
51
- return state ;
52
- }
53
- else if ( node . kind === SyntaxKind . ModuleDeclaration ) {
54
- const body = ( < ModuleDeclaration > node ) . body ;
55
- return body ? getModuleInstanceState ( body ) : ModuleInstanceState . Instantiated ;
56
- }
57
- // Only jsdoc typedef definition can exist in jsdoc namespace, and it should
58
- // be considered the same as type alias
59
- else if ( node . kind === SyntaxKind . Identifier && ( < Identifier > node ) . isInJSDocNamespace ) {
60
- return ModuleInstanceState . NonInstantiated ;
61
- }
62
- else {
63
- return ModuleInstanceState . Instantiated ;
64
74
}
75
+ return ModuleInstanceState . Instantiated ;
65
76
}
66
77
67
78
const enum ContainerFlags {
@@ -1680,7 +1691,7 @@ namespace ts {
1680
1691
1681
1692
function bindAnonymousDeclaration ( node : Declaration , symbolFlags : SymbolFlags , name : __String ) {
1682
1693
const symbol = createSymbol ( symbolFlags , name ) ;
1683
- if ( symbolFlags & SymbolFlags . EnumMember ) {
1694
+ if ( symbolFlags & ( SymbolFlags . EnumMember | SymbolFlags . ClassMember ) ) {
1684
1695
symbol . parent = container . symbol ;
1685
1696
}
1686
1697
addDeclarationToSymbol ( symbol , node , symbolFlags ) ;
@@ -1835,7 +1846,7 @@ namespace ts {
1835
1846
}
1836
1847
1837
1848
function checkStrictModeNumericLiteral ( node : NumericLiteral ) {
1838
- if ( inStrictMode && node . numericLiteralFlags & NumericLiteralFlags . Octal ) {
1849
+ if ( inStrictMode && node . numericLiteralFlags & TokenFlags . Octal ) {
1839
1850
file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Octal_literals_are_not_allowed_in_strict_mode ) ) ;
1840
1851
}
1841
1852
}
@@ -3319,7 +3330,7 @@ namespace ts {
3319
3330
break ;
3320
3331
3321
3332
case SyntaxKind . NumericLiteral :
3322
- if ( ( < NumericLiteral > node ) . numericLiteralFlags & NumericLiteralFlags . BinaryOrOctalSpecifier ) {
3333
+ if ( ( < NumericLiteral > node ) . numericLiteralFlags & TokenFlags . BinaryOrOctalSpecifier ) {
3323
3334
transformFlags |= TransformFlags . AssertES2015 ;
3324
3335
}
3325
3336
break ;
0 commit comments