@@ -54,6 +54,11 @@ namespace ts {
5454 const body = ( < ModuleDeclaration > node ) . body ;
5555 return body ? getModuleInstanceState ( body ) : ModuleInstanceState . Instantiated ;
5656 }
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+ }
5762 else {
5863 return ModuleInstanceState . Instantiated ;
5964 }
@@ -429,7 +434,11 @@ namespace ts {
429434 // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
430435 // and this case is specially handled. Module augmentations should only be merged with original module definition
431436 // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
432- if ( ! isAmbientModule ( node ) && ( hasExportModifier || container . flags & NodeFlags . ExportContext ) ) {
437+ const isJSDocTypedefInJSDocNamespace = node . kind === SyntaxKind . JSDocTypedefTag &&
438+ node . name &&
439+ node . name . kind === SyntaxKind . Identifier &&
440+ ( < Identifier > node . name ) . isInJSDocNamespace ;
441+ if ( ( ! isAmbientModule ( node ) && ( hasExportModifier || container . flags & NodeFlags . ExportContext ) ) || isJSDocTypedefInJSDocNamespace ) {
433442 const exportKind =
434443 ( symbolFlags & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ) |
435444 ( symbolFlags & SymbolFlags . Type ? SymbolFlags . ExportType : 0 ) |
@@ -1831,6 +1840,17 @@ namespace ts {
18311840 switch ( node . kind ) {
18321841 /* Strict mode checks */
18331842 case SyntaxKind . Identifier :
1843+ // for typedef type names with namespaces, bind the new jsdoc type symbol here
1844+ // because it requires all containing namespaces to be in effect, namely the
1845+ // current "blockScopeContainer" needs to be set to its immediate namespace parent.
1846+ if ( ( < Identifier > node ) . isInJSDocNamespace ) {
1847+ let parentNode = node . parent ;
1848+ while ( parentNode && parentNode . kind !== SyntaxKind . JSDocTypedefTag ) {
1849+ parentNode = parentNode . parent ;
1850+ }
1851+ bindBlockScopedDeclaration ( < Declaration > parentNode , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
1852+ break ;
1853+ }
18341854 case SyntaxKind . ThisKeyword :
18351855 if ( currentFlow && ( isExpression ( node ) || parent . kind === SyntaxKind . ShorthandPropertyAssignment ) ) {
18361856 node . flowNode = currentFlow ;
@@ -1955,6 +1975,10 @@ namespace ts {
19551975 case SyntaxKind . InterfaceDeclaration :
19561976 return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . Interface , SymbolFlags . InterfaceExcludes ) ;
19571977 case SyntaxKind . JSDocTypedefTag :
1978+ if ( ! ( < JSDocTypedefTag > node ) . fullName || ( < JSDocTypedefTag > node ) . fullName . kind === SyntaxKind . Identifier ) {
1979+ return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
1980+ }
1981+ break ;
19581982 case SyntaxKind . TypeAliasDeclaration :
19591983 return bindBlockScopedDeclaration ( < Declaration > node , SymbolFlags . TypeAlias , SymbolFlags . TypeAliasExcludes ) ;
19601984 case SyntaxKind . EnumDeclaration :
@@ -2514,7 +2538,7 @@ namespace ts {
25142538 && ( leftKind === SyntaxKind . ObjectLiteralExpression
25152539 || leftKind === SyntaxKind . ArrayLiteralExpression ) ) {
25162540 // Destructuring assignments are ES6 syntax.
2517- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . DestructuringAssignment ;
2541+ transformFlags |= TransformFlags . AssertES2015 | TransformFlags . AssertDestructuringAssignment ;
25182542 }
25192543 else if ( operatorTokenKind === SyntaxKind . AsteriskAsteriskToken
25202544 || operatorTokenKind === SyntaxKind . AsteriskAsteriskEqualsToken ) {
@@ -2595,9 +2619,9 @@ namespace ts {
25952619
25962620 // A class with a parameter property assignment, property initializer, or decorator is
25972621 // TypeScript syntax.
2598- // An exported declaration may be TypeScript syntax.
2622+ // An exported declaration may be TypeScript syntax, but is handled by the visitor
2623+ // for a namespace declaration.
25992624 if ( ( subtreeFlags & TransformFlags . TypeScriptClassSyntaxMask )
2600- || ( modifierFlags & ModifierFlags . Export )
26012625 || node . typeParameters ) {
26022626 transformFlags |= TransformFlags . AssertTypeScript ;
26032627 }
@@ -2767,11 +2791,6 @@ namespace ts {
27672791 else {
27682792 transformFlags = subtreeFlags | TransformFlags . ContainsHoistedDeclarationOrCompletion ;
27692793
2770- // If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
2771- if ( modifierFlags & ModifierFlags . Export ) {
2772- transformFlags |= TransformFlags . AssertTypeScript | TransformFlags . AssertES2015 ;
2773- }
2774-
27752794 // TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
27762795 // syntax.
27772796 if ( modifierFlags & ModifierFlags . TypeScriptModifier
@@ -2913,11 +2932,6 @@ namespace ts {
29132932 else {
29142933 transformFlags = subtreeFlags ;
29152934
2916- // If a VariableStatement is exported, then it is either ES6 or TypeScript syntax.
2917- if ( modifierFlags & ModifierFlags . Export ) {
2918- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . AssertTypeScript ;
2919- }
2920-
29212935 if ( declarationListTransformFlags & TransformFlags . ContainsBindingPattern ) {
29222936 transformFlags |= TransformFlags . AssertES2015 ;
29232937 }
@@ -3034,12 +3048,6 @@ namespace ts {
30343048 transformFlags |= TransformFlags . AssertJsx ;
30353049 break ;
30363050
3037- case SyntaxKind . ExportKeyword :
3038- // This node is both ES6 and TypeScript syntax.
3039- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . AssertTypeScript ;
3040- break ;
3041-
3042- case SyntaxKind . DefaultKeyword :
30433051 case SyntaxKind . NoSubstitutionTemplateLiteral :
30443052 case SyntaxKind . TemplateHead :
30453053 case SyntaxKind . TemplateMiddle :
@@ -3048,6 +3056,7 @@ namespace ts {
30483056 case SyntaxKind . TaggedTemplateExpression :
30493057 case SyntaxKind . ShorthandPropertyAssignment :
30503058 case SyntaxKind . ForOfStatement :
3059+ case SyntaxKind . StaticKeyword :
30513060 // These nodes are ES6 syntax.
30523061 transformFlags |= TransformFlags . AssertES2015 ;
30533062 break ;
0 commit comments