@@ -234,13 +234,17 @@ namespace ts {
234234 }
235235
236236 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 ;
244248 }
245249 }
246250
@@ -288,7 +292,7 @@ namespace ts {
288292 // module.exports = ...
289293 return InternalSymbolName . ExportEquals ;
290294 case SyntaxKind . BinaryExpression :
291- if ( getSpecialPropertyAssignmentKind ( node as BinaryExpression ) === SpecialPropertyAssignmentKind . ModuleExports ) {
295+ if ( getAssignmentDeclarationKind ( node as BinaryExpression ) === AssignmentDeclarationKind . ModuleExports ) {
292296 // module.exports = ...
293297 return InternalSymbolName . ExportEquals ;
294298 }
@@ -374,8 +378,8 @@ namespace ts {
374378 // prototype symbols like methods.
375379 symbolTable . set ( name , symbol = createSymbol ( SymbolFlags . None , name ) ) ;
376380 }
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.
379383 if ( isNamedDeclaration ( node ) ) {
380384 node . name . parent = node ;
381385 }
@@ -461,7 +465,7 @@ namespace ts {
461465 // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
462466 // and this case is specially handled. Module augmentations should only be merged with original module definition
463467 // 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.
465469 if ( ( ! isAmbientModule ( node ) && ( hasExportModifier || container . flags & NodeFlags . ExportContext ) ) || isJSDocTypeAlias ( node ) ) {
466470 if ( hasModifier ( node , ModifierFlags . Default ) && ! getDeclarationName ( node ) ) {
467471 return declareSymbol ( container . symbol . exports ! , container . symbol , node , symbolFlags , symbolExcludes ) ; // No local symbol for an unnamed default!
@@ -2009,7 +2013,7 @@ namespace ts {
20092013
20102014 function bindJSDoc ( node : Node ) {
20112015 if ( hasJSDocNodes ( node ) ) {
2012- if ( isInJavaScriptFile ( node ) ) {
2016+ if ( isInJSFile ( node ) ) {
20132017 for ( const j of node . jsDoc ! ) {
20142018 bind ( j ) ;
20152019 }
@@ -2075,7 +2079,7 @@ namespace ts {
20752079 if ( isSpecialPropertyDeclaration ( node as PropertyAccessExpression ) ) {
20762080 bindSpecialPropertyDeclaration ( node as PropertyAccessExpression ) ;
20772081 }
2078- if ( isInJavaScriptFile ( node ) &&
2082+ if ( isInJSFile ( node ) &&
20792083 file . commonJsModuleIndicator &&
20802084 isModuleExportsPropertyAccessExpression ( node as PropertyAccessExpression ) &&
20812085 ! lookupSymbolForNameWorker ( blockScopeContainer , "module" as __String ) ) {
@@ -2084,27 +2088,27 @@ namespace ts {
20842088 }
20852089 break ;
20862090 case SyntaxKind . BinaryExpression :
2087- const specialKind = getSpecialPropertyAssignmentKind ( node as BinaryExpression ) ;
2091+ const specialKind = getAssignmentDeclarationKind ( node as BinaryExpression ) ;
20882092 switch ( specialKind ) {
2089- case SpecialPropertyAssignmentKind . ExportsProperty :
2093+ case AssignmentDeclarationKind . ExportsProperty :
20902094 bindExportsPropertyAssignment ( node as BinaryExpression ) ;
20912095 break ;
2092- case SpecialPropertyAssignmentKind . ModuleExports :
2096+ case AssignmentDeclarationKind . ModuleExports :
20932097 bindModuleExportsAssignment ( node as BinaryExpression ) ;
20942098 break ;
2095- case SpecialPropertyAssignmentKind . PrototypeProperty :
2099+ case AssignmentDeclarationKind . PrototypeProperty :
20962100 bindPrototypePropertyAssignment ( ( node as BinaryExpression ) . left as PropertyAccessEntityNameExpression , node ) ;
20972101 break ;
2098- case SpecialPropertyAssignmentKind . Prototype :
2102+ case AssignmentDeclarationKind . Prototype :
20992103 bindPrototypeAssignment ( node as BinaryExpression ) ;
21002104 break ;
2101- case SpecialPropertyAssignmentKind . ThisProperty :
2105+ case AssignmentDeclarationKind . ThisProperty :
21022106 bindThisPropertyAssignment ( node as BinaryExpression ) ;
21032107 break ;
2104- case SpecialPropertyAssignmentKind . Property :
2108+ case AssignmentDeclarationKind . Property :
21052109 bindSpecialPropertyAssignment ( node as BinaryExpression ) ;
21062110 break ;
2107- case SpecialPropertyAssignmentKind . None :
2111+ case AssignmentDeclarationKind . None :
21082112 // Nothing to do
21092113 break ;
21102114 default :
@@ -2184,7 +2188,7 @@ namespace ts {
21842188 return bindFunctionExpression ( < FunctionExpression > node ) ;
21852189
21862190 case SyntaxKind . CallExpression :
2187- if ( isInJavaScriptFile ( node ) ) {
2191+ if ( isInJSFile ( node ) ) {
21882192 bindCallExpression ( < CallExpression > node ) ;
21892193 }
21902194 break ;
@@ -2286,14 +2290,19 @@ namespace ts {
22862290 bindAnonymousDeclaration ( node , SymbolFlags . Alias , getDeclarationName ( node ) ! ) ;
22872291 }
22882292 else {
2289- const flags = node . kind === SyntaxKind . ExportAssignment && exportAssignmentIsAlias ( node )
2293+ const flags = exportAssignmentIsAlias ( node )
22902294 // An export default clause with an EntityNameExpression or a class expression exports all meanings of that identifier or expression;
22912295 ? SymbolFlags . Alias
22922296 // An export default clause with any other expression exports a value
22932297 : SymbolFlags . Property ;
22942298 // If there is an `export default x;` alias declaration, can't `export default` anything else.
22952299 // (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+ }
22972306 }
22982307 }
22992308
@@ -2361,7 +2370,7 @@ namespace ts {
23612370 const lhs = node . left as PropertyAccessEntityNameExpression ;
23622371 const symbol = forEachIdentifierInEntityName ( lhs . expression , /*parent*/ undefined , ( id , symbol ) => {
23632372 if ( symbol ) {
2364- addDeclarationToSymbol ( symbol , id , SymbolFlags . Module | SymbolFlags . JSContainer ) ;
2373+ addDeclarationToSymbol ( symbol , id , SymbolFlags . Module | SymbolFlags . Assignment ) ;
23652374 }
23662375 return symbol ;
23672376 } ) ;
@@ -2394,7 +2403,7 @@ namespace ts {
23942403 }
23952404
23962405 function bindThisPropertyAssignment ( node : BinaryExpression | PropertyAccessExpression ) {
2397- Debug . assert ( isInJavaScriptFile ( node ) ) ;
2406+ Debug . assert ( isInJSFile ( node ) ) ;
23982407 const thisContainer = getThisContainer ( node , /*includeArrowFunctions*/ false ) ;
23992408 switch ( thisContainer . kind ) {
24002409 case SyntaxKind . FunctionDeclaration :
@@ -2482,7 +2491,7 @@ namespace ts {
24822491 const lhs = node . left as PropertyAccessEntityNameExpression ;
24832492 // Class declarations in Typescript do not allow property declarations
24842493 const parentSymbol = lookupSymbolForPropertyAccess ( lhs . expression ) ;
2485- if ( ! isInJavaScriptFile ( node ) && ! isFunctionSymbol ( parentSymbol ) ) {
2494+ if ( ! isInJSFile ( node ) && ! isFunctionSymbol ( parentSymbol ) ) {
24862495 return ;
24872496 }
24882497 // Fix up parent pointers since we're going to use these nodes before we bind into them
@@ -2515,8 +2524,8 @@ namespace ts {
25152524 : propertyAccess . parent . parent . kind === SyntaxKind . SourceFile ;
25162525 if ( ! isPrototypeProperty && ( ! namespaceSymbol || ! ( namespaceSymbol . flags & SymbolFlags . Namespace ) ) && isToplevel ) {
25172526 // 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 ;
25202529 namespaceSymbol = forEachIdentifierInEntityName ( propertyAccess . expression , namespaceSymbol , ( id , symbol , parent ) => {
25212530 if ( symbol ) {
25222531 addDeclarationToSymbol ( symbol , id , flags ) ;
@@ -2527,7 +2536,7 @@ namespace ts {
25272536 }
25282537 } ) ;
25292538 }
2530- if ( ! namespaceSymbol || ! isJavascriptContainer ( namespaceSymbol ) ) {
2539+ if ( ! namespaceSymbol || ! isExpandoSymbol ( namespaceSymbol ) ) {
25312540 return ;
25322541 }
25332542
@@ -2536,14 +2545,14 @@ namespace ts {
25362545 ( namespaceSymbol . members || ( namespaceSymbol . members = createSymbolTable ( ) ) ) :
25372546 ( namespaceSymbol . exports || ( namespaceSymbol . exports = createSymbolTable ( ) ) ) ;
25382547
2539- const isMethod = isFunctionLikeDeclaration ( getAssignedJavascriptInitializer ( propertyAccess ) ! ) ;
2548+ const isMethod = isFunctionLikeDeclaration ( getAssignedExpandoInitializer ( propertyAccess ) ! ) ;
25402549 const includes = isMethod ? SymbolFlags . Method : SymbolFlags . Property ;
25412550 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 ) ;
25432552 }
25442553
25452554 /**
2546- * Javascript containers are:
2555+ * Javascript expando values are:
25472556 * - Functions
25482557 * - classes
25492558 * - namespaces
@@ -2552,7 +2561,7 @@ namespace ts {
25522561 * - with empty object literals
25532562 * - with non-empty object literals if assigned to the prototype property
25542563 */
2555- function isJavascriptContainer ( symbol : Symbol ) : boolean {
2564+ function isExpandoSymbol ( symbol : Symbol ) : boolean {
25562565 if ( symbol . flags & ( SymbolFlags . Function | SymbolFlags . Class | SymbolFlags . NamespaceModule ) ) {
25572566 return true ;
25582567 }
@@ -2565,7 +2574,7 @@ namespace ts {
25652574 init = init && getRightMostAssignedExpression ( init ) ;
25662575 if ( init ) {
25672576 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 ) ;
25692578 }
25702579 return false ;
25712580 }
@@ -2657,7 +2666,7 @@ namespace ts {
26572666 }
26582667
26592668 if ( ! isBindingPattern ( node . name ) ) {
2660- const isEnum = ! ! getJSDocEnumTag ( node ) ;
2669+ const isEnum = isInJSFile ( node ) && ! ! getJSDocEnumTag ( node ) ;
26612670 const enumFlags = ( isEnum ? SymbolFlags . RegularEnum : SymbolFlags . None ) ;
26622671 const enumExcludes = ( isEnum ? SymbolFlags . RegularEnumExcludes : SymbolFlags . None ) ;
26632672 if ( isBlockOrCatchScoped ( node ) ) {
0 commit comments