@@ -16,52 +16,63 @@ namespace ts {
1616 referenced : boolean ;
1717 }
1818
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 {
2024 // 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 ;
4973 }
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 ;
6474 }
75+ return ModuleInstanceState . Instantiated ;
6576 }
6677
6778 const enum ContainerFlags {
@@ -1682,7 +1693,7 @@ namespace ts {
16821693
16831694 function bindAnonymousDeclaration ( node : Declaration , symbolFlags : SymbolFlags , name : __String ) {
16841695 const symbol = createSymbol ( symbolFlags , name ) ;
1685- if ( symbolFlags & SymbolFlags . EnumMember ) {
1696+ if ( symbolFlags & ( SymbolFlags . EnumMember | SymbolFlags . ClassMember ) ) {
16861697 symbol . parent = container . symbol ;
16871698 }
16881699 addDeclarationToSymbol ( symbol , node , symbolFlags ) ;
@@ -1837,7 +1848,7 @@ namespace ts {
18371848 }
18381849
18391850 function checkStrictModeNumericLiteral ( node : NumericLiteral ) {
1840- if ( inStrictMode && node . numericLiteralFlags & NumericLiteralFlags . Octal ) {
1851+ if ( inStrictMode && node . numericLiteralFlags & TokenFlags . Octal ) {
18411852 file . bindDiagnostics . push ( createDiagnosticForNode ( node , Diagnostics . Octal_literals_are_not_allowed_in_strict_mode ) ) ;
18421853 }
18431854 }
@@ -3321,7 +3332,7 @@ namespace ts {
33213332 break ;
33223333
33233334 case SyntaxKind . NumericLiteral :
3324- if ( ( < NumericLiteral > node ) . numericLiteralFlags & NumericLiteralFlags . BinaryOrOctalSpecifier ) {
3335+ if ( ( < NumericLiteral > node ) . numericLiteralFlags & TokenFlags . BinaryOrOctalSpecifier ) {
33253336 transformFlags |= TransformFlags . AssertES2015 ;
33263337 }
33273338 break ;
0 commit comments