@@ -234,13 +234,17 @@ namespace ts {
234
234
}
235
235
236
236
if ( symbolFlags & SymbolFlags . Value ) {
237
- const { valueDeclaration } = symbol ;
238
- if ( ! valueDeclaration ||
239
- ( isAssignmentDeclaration ( valueDeclaration ) && ! isAssignmentDeclaration ( node ) ) ||
240
- ( valueDeclaration . kind !== node . kind && isEffectiveModuleDeclaration ( valueDeclaration ) ) ) {
241
- // other kinds of value declarations take precedence over modules and assignment declarations
242
- symbol . valueDeclaration = node ;
243
- }
237
+ setValueDeclaration ( symbol , node ) ;
238
+ }
239
+ }
240
+
241
+ function setValueDeclaration ( symbol : Symbol , node : Declaration ) : void {
242
+ const { valueDeclaration } = symbol ;
243
+ if ( ! valueDeclaration ||
244
+ ( isAssignmentDeclaration ( valueDeclaration ) && ! isAssignmentDeclaration ( node ) ) ||
245
+ ( valueDeclaration . kind !== node . kind && isEffectiveModuleDeclaration ( valueDeclaration ) ) ) {
246
+ // other kinds of value declarations take precedence over modules and assignment declarations
247
+ symbol . valueDeclaration = node ;
244
248
}
245
249
}
246
250
@@ -288,7 +292,7 @@ namespace ts {
288
292
// module.exports = ...
289
293
return InternalSymbolName . ExportEquals ;
290
294
case SyntaxKind . BinaryExpression :
291
- if ( getSpecialPropertyAssignmentKind ( node as BinaryExpression ) === SpecialPropertyAssignmentKind . ModuleExports ) {
295
+ if ( getAssignmentDeclarationKind ( node as BinaryExpression ) === AssignmentDeclarationKind . ModuleExports ) {
292
296
// module.exports = ...
293
297
return InternalSymbolName . ExportEquals ;
294
298
}
@@ -374,8 +378,8 @@ namespace ts {
374
378
// prototype symbols like methods.
375
379
symbolTable . set ( name , symbol = createSymbol ( SymbolFlags . None , name ) ) ;
376
380
}
377
- else if ( ! ( includes & SymbolFlags . Variable && symbol . flags & SymbolFlags . JSContainer ) ) {
378
- // JSContainers are allowed to merge with variables, no matter what other flags they have.
381
+ else if ( ! ( includes & SymbolFlags . Variable && symbol . flags & SymbolFlags . Assignment ) ) {
382
+ // Assignment declarations are allowed to merge with variables, no matter what other flags they have.
379
383
if ( isNamedDeclaration ( node ) ) {
380
384
node . name . parent = node ;
381
385
}
@@ -461,7 +465,7 @@ namespace ts {
461
465
// during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
462
466
// and this case is specially handled. Module augmentations should only be merged with original module definition
463
467
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
464
- if ( isJSDocTypeAlias ( node ) ) Debug . assert ( isInJavaScriptFile ( node ) ) ; // We shouldn't add symbols for JSDoc nodes if not in a JS file.
468
+ if ( isJSDocTypeAlias ( node ) ) Debug . assert ( isInJSFile ( node ) ) ; // We shouldn't add symbols for JSDoc nodes if not in a JS file.
465
469
if ( ( ! isAmbientModule ( node ) && ( hasExportModifier || container . flags & NodeFlags . ExportContext ) ) || isJSDocTypeAlias ( node ) ) {
466
470
if ( hasModifier ( node , ModifierFlags . Default ) && ! getDeclarationName ( node ) ) {
467
471
return declareSymbol ( container . symbol . exports ! , container . symbol , node , symbolFlags , symbolExcludes ) ; // No local symbol for an unnamed default!
@@ -2009,7 +2013,7 @@ namespace ts {
2009
2013
2010
2014
function bindJSDoc ( node : Node ) {
2011
2015
if ( hasJSDocNodes ( node ) ) {
2012
- if ( isInJavaScriptFile ( node ) ) {
2016
+ if ( isInJSFile ( node ) ) {
2013
2017
for ( const j of node . jsDoc ! ) {
2014
2018
bind ( j ) ;
2015
2019
}
@@ -2075,7 +2079,7 @@ namespace ts {
2075
2079
if ( isSpecialPropertyDeclaration ( node as PropertyAccessExpression ) ) {
2076
2080
bindSpecialPropertyDeclaration ( node as PropertyAccessExpression ) ;
2077
2081
}
2078
- if ( isInJavaScriptFile ( node ) &&
2082
+ if ( isInJSFile ( node ) &&
2079
2083
file . commonJsModuleIndicator &&
2080
2084
isModuleExportsPropertyAccessExpression ( node as PropertyAccessExpression ) &&
2081
2085
! lookupSymbolForNameWorker ( blockScopeContainer , "module" as __String ) ) {
@@ -2084,27 +2088,27 @@ namespace ts {
2084
2088
}
2085
2089
break ;
2086
2090
case SyntaxKind . BinaryExpression :
2087
- const specialKind = getSpecialPropertyAssignmentKind ( node as BinaryExpression ) ;
2091
+ const specialKind = getAssignmentDeclarationKind ( node as BinaryExpression ) ;
2088
2092
switch ( specialKind ) {
2089
- case SpecialPropertyAssignmentKind . ExportsProperty :
2093
+ case AssignmentDeclarationKind . ExportsProperty :
2090
2094
bindExportsPropertyAssignment ( node as BinaryExpression ) ;
2091
2095
break ;
2092
- case SpecialPropertyAssignmentKind . ModuleExports :
2096
+ case AssignmentDeclarationKind . ModuleExports :
2093
2097
bindModuleExportsAssignment ( node as BinaryExpression ) ;
2094
2098
break ;
2095
- case SpecialPropertyAssignmentKind . PrototypeProperty :
2099
+ case AssignmentDeclarationKind . PrototypeProperty :
2096
2100
bindPrototypePropertyAssignment ( ( node as BinaryExpression ) . left as PropertyAccessEntityNameExpression , node ) ;
2097
2101
break ;
2098
- case SpecialPropertyAssignmentKind . Prototype :
2102
+ case AssignmentDeclarationKind . Prototype :
2099
2103
bindPrototypeAssignment ( node as BinaryExpression ) ;
2100
2104
break ;
2101
- case SpecialPropertyAssignmentKind . ThisProperty :
2105
+ case AssignmentDeclarationKind . ThisProperty :
2102
2106
bindThisPropertyAssignment ( node as BinaryExpression ) ;
2103
2107
break ;
2104
- case SpecialPropertyAssignmentKind . Property :
2108
+ case AssignmentDeclarationKind . Property :
2105
2109
bindSpecialPropertyAssignment ( node as BinaryExpression ) ;
2106
2110
break ;
2107
- case SpecialPropertyAssignmentKind . None :
2111
+ case AssignmentDeclarationKind . None :
2108
2112
// Nothing to do
2109
2113
break ;
2110
2114
default :
@@ -2184,7 +2188,7 @@ namespace ts {
2184
2188
return bindFunctionExpression ( < FunctionExpression > node ) ;
2185
2189
2186
2190
case SyntaxKind . CallExpression :
2187
- if ( isInJavaScriptFile ( node ) ) {
2191
+ if ( isInJSFile ( node ) ) {
2188
2192
bindCallExpression ( < CallExpression > node ) ;
2189
2193
}
2190
2194
break ;
@@ -2286,14 +2290,19 @@ namespace ts {
2286
2290
bindAnonymousDeclaration ( node , SymbolFlags . Alias , getDeclarationName ( node ) ! ) ;
2287
2291
}
2288
2292
else {
2289
- const flags = node . kind === SyntaxKind . ExportAssignment && exportAssignmentIsAlias ( node )
2293
+ const flags = exportAssignmentIsAlias ( node )
2290
2294
// An export default clause with an EntityNameExpression or a class expression exports all meanings of that identifier or expression;
2291
2295
? SymbolFlags . Alias
2292
2296
// An export default clause with any other expression exports a value
2293
2297
: SymbolFlags . Property ;
2294
2298
// If there is an `export default x;` alias declaration, can't `export default` anything else.
2295
2299
// (In contrast, you can still have `export default function f() {}` and `export default interface I {}`.)
2296
- declareSymbol ( container . symbol . exports , container . symbol , node , flags , SymbolFlags . All ) ;
2300
+ const symbol = declareSymbol ( container . symbol . exports , container . symbol , node , flags , SymbolFlags . All ) ;
2301
+
2302
+ if ( node . isExportEquals ) {
2303
+ // Will be an error later, since the module already has other exports. Just make sure this has a valueDeclaration set.
2304
+ setValueDeclaration ( symbol , node ) ;
2305
+ }
2297
2306
}
2298
2307
}
2299
2308
@@ -2361,7 +2370,7 @@ namespace ts {
2361
2370
const lhs = node . left as PropertyAccessEntityNameExpression ;
2362
2371
const symbol = forEachIdentifierInEntityName ( lhs . expression , /*parent*/ undefined , ( id , symbol ) => {
2363
2372
if ( symbol ) {
2364
- addDeclarationToSymbol ( symbol , id , SymbolFlags . Module | SymbolFlags . JSContainer ) ;
2373
+ addDeclarationToSymbol ( symbol , id , SymbolFlags . Module | SymbolFlags . Assignment ) ;
2365
2374
}
2366
2375
return symbol ;
2367
2376
} ) ;
@@ -2394,7 +2403,7 @@ namespace ts {
2394
2403
}
2395
2404
2396
2405
function bindThisPropertyAssignment ( node : BinaryExpression | PropertyAccessExpression ) {
2397
- Debug . assert ( isInJavaScriptFile ( node ) ) ;
2406
+ Debug . assert ( isInJSFile ( node ) ) ;
2398
2407
const thisContainer = getThisContainer ( node , /*includeArrowFunctions*/ false ) ;
2399
2408
switch ( thisContainer . kind ) {
2400
2409
case SyntaxKind . FunctionDeclaration :
@@ -2482,7 +2491,7 @@ namespace ts {
2482
2491
const lhs = node . left as PropertyAccessEntityNameExpression ;
2483
2492
// Class declarations in Typescript do not allow property declarations
2484
2493
const parentSymbol = lookupSymbolForPropertyAccess ( lhs . expression ) ;
2485
- if ( ! isInJavaScriptFile ( node ) && ! isFunctionSymbol ( parentSymbol ) ) {
2494
+ if ( ! isInJSFile ( node ) && ! isFunctionSymbol ( parentSymbol ) ) {
2486
2495
return ;
2487
2496
}
2488
2497
// Fix up parent pointers since we're going to use these nodes before we bind into them
@@ -2515,8 +2524,8 @@ namespace ts {
2515
2524
: propertyAccess . parent . parent . kind === SyntaxKind . SourceFile ;
2516
2525
if ( ! isPrototypeProperty && ( ! namespaceSymbol || ! ( namespaceSymbol . flags & SymbolFlags . Namespace ) ) && isToplevel ) {
2517
2526
// make symbols or add declarations for intermediate containers
2518
- const flags = SymbolFlags . Module | SymbolFlags . JSContainer ;
2519
- const excludeFlags = SymbolFlags . ValueModuleExcludes & ~ SymbolFlags . JSContainer ;
2527
+ const flags = SymbolFlags . Module | SymbolFlags . Assignment ;
2528
+ const excludeFlags = SymbolFlags . ValueModuleExcludes & ~ SymbolFlags . Assignment ;
2520
2529
namespaceSymbol = forEachIdentifierInEntityName ( propertyAccess . expression , namespaceSymbol , ( id , symbol , parent ) => {
2521
2530
if ( symbol ) {
2522
2531
addDeclarationToSymbol ( symbol , id , flags ) ;
@@ -2527,7 +2536,7 @@ namespace ts {
2527
2536
}
2528
2537
} ) ;
2529
2538
}
2530
- if ( ! namespaceSymbol || ! isJavascriptContainer ( namespaceSymbol ) ) {
2539
+ if ( ! namespaceSymbol || ! isExpandoSymbol ( namespaceSymbol ) ) {
2531
2540
return ;
2532
2541
}
2533
2542
@@ -2536,14 +2545,14 @@ namespace ts {
2536
2545
( namespaceSymbol . members || ( namespaceSymbol . members = createSymbolTable ( ) ) ) :
2537
2546
( namespaceSymbol . exports || ( namespaceSymbol . exports = createSymbolTable ( ) ) ) ;
2538
2547
2539
- const isMethod = isFunctionLikeDeclaration ( getAssignedJavascriptInitializer ( propertyAccess ) ! ) ;
2548
+ const isMethod = isFunctionLikeDeclaration ( getAssignedExpandoInitializer ( propertyAccess ) ! ) ;
2540
2549
const includes = isMethod ? SymbolFlags . Method : SymbolFlags . Property ;
2541
2550
const excludes = isMethod ? SymbolFlags . MethodExcludes : SymbolFlags . PropertyExcludes ;
2542
- declareSymbol ( symbolTable , namespaceSymbol , propertyAccess , includes | SymbolFlags . JSContainer , excludes & ~ SymbolFlags . JSContainer ) ;
2551
+ declareSymbol ( symbolTable , namespaceSymbol , propertyAccess , includes | SymbolFlags . Assignment , excludes & ~ SymbolFlags . Assignment ) ;
2543
2552
}
2544
2553
2545
2554
/**
2546
- * Javascript containers are:
2555
+ * Javascript expando values are:
2547
2556
* - Functions
2548
2557
* - classes
2549
2558
* - namespaces
@@ -2552,7 +2561,7 @@ namespace ts {
2552
2561
* - with empty object literals
2553
2562
* - with non-empty object literals if assigned to the prototype property
2554
2563
*/
2555
- function isJavascriptContainer ( symbol : Symbol ) : boolean {
2564
+ function isExpandoSymbol ( symbol : Symbol ) : boolean {
2556
2565
if ( symbol . flags & ( SymbolFlags . Function | SymbolFlags . Class | SymbolFlags . NamespaceModule ) ) {
2557
2566
return true ;
2558
2567
}
@@ -2565,7 +2574,7 @@ namespace ts {
2565
2574
init = init && getRightMostAssignedExpression ( init ) ;
2566
2575
if ( init ) {
2567
2576
const isPrototypeAssignment = isPrototypeAccess ( isVariableDeclaration ( node ) ? node . name : isBinaryExpression ( node ) ? node . left : node ) ;
2568
- return ! ! getJavascriptInitializer ( isBinaryExpression ( init ) && init . operatorToken . kind === SyntaxKind . BarBarToken ? init . right : init , isPrototypeAssignment ) ;
2577
+ return ! ! getExpandoInitializer ( isBinaryExpression ( init ) && init . operatorToken . kind === SyntaxKind . BarBarToken ? init . right : init , isPrototypeAssignment ) ;
2569
2578
}
2570
2579
return false ;
2571
2580
}
@@ -2657,7 +2666,7 @@ namespace ts {
2657
2666
}
2658
2667
2659
2668
if ( ! isBindingPattern ( node . name ) ) {
2660
- const isEnum = ! ! getJSDocEnumTag ( node ) ;
2669
+ const isEnum = isInJSFile ( node ) && ! ! getJSDocEnumTag ( node ) ;
2661
2670
const enumFlags = ( isEnum ? SymbolFlags . RegularEnum : SymbolFlags . None ) ;
2662
2671
const enumExcludes = ( isEnum ? SymbolFlags . RegularEnumExcludes : SymbolFlags . None ) ;
2663
2672
if ( isBlockOrCatchScoped ( node ) ) {
0 commit comments