@@ -166,13 +166,12 @@ namespace ts {
166
166
return "__export" ;
167
167
case SyntaxKind . ExportAssignment :
168
168
return ( < ExportAssignment > node ) . isExportEquals ? "export=" : "default" ;
169
+ case SyntaxKind . BinaryExpression :
170
+ // Binary expression case is for JS module 'module.exports = expr'
171
+ return "export=" ;
169
172
case SyntaxKind . FunctionDeclaration :
170
173
case SyntaxKind . ClassDeclaration :
171
174
return node . flags & NodeFlags . Default ? "default" : undefined ;
172
-
173
- case SyntaxKind . BinaryExpression :
174
- Debug . assert ( isModuleExportsAssignment ( node ) ) ;
175
- return "__jsExports" ;
176
175
}
177
176
}
178
177
@@ -936,9 +935,7 @@ namespace ts {
936
935
return bindAnonymousDeclaration ( < FunctionExpression > node , SymbolFlags . Function , bindingName ) ;
937
936
938
937
case SyntaxKind . CallExpression :
939
- // We're only inspecting call expressions to detect CommonJS modules, so we can skip
940
- // this check if we've already seen the module indicator
941
- if ( isJavaScriptFile && ! file . commonJsModuleIndicator ) {
938
+ if ( isJavaScriptFile ) {
942
939
bindCallExpression ( < CallExpression > node ) ;
943
940
}
944
941
break ;
@@ -984,12 +981,13 @@ namespace ts {
984
981
bindAnonymousDeclaration ( file , SymbolFlags . ValueModule , `"${ removeFileExtension ( file . fileName ) } "` ) ;
985
982
}
986
983
987
- function bindExportAssignment ( node : ExportAssignment ) {
984
+ function bindExportAssignment ( node : ExportAssignment | BinaryExpression ) {
985
+ let boundExpression = node . kind === SyntaxKind . ExportAssignment ? ( < ExportAssignment > node ) . expression : ( < BinaryExpression > node ) . right ;
988
986
if ( ! container . symbol || ! container . symbol . exports ) {
989
987
// Export assignment in some sort of block construct
990
988
bindAnonymousDeclaration ( node , SymbolFlags . Alias , getDeclarationName ( node ) ) ;
991
989
}
992
- else if ( node . expression . kind === SyntaxKind . Identifier ) {
990
+ else if ( boundExpression . kind === SyntaxKind . Identifier ) {
993
991
// An export default clause with an identifier exports all meanings of that identifier
994
992
declareSymbol ( container . symbol . exports , container . symbol , node , SymbolFlags . Alias , SymbolFlags . PropertyExcludes | SymbolFlags . AliasExcludes ) ;
995
993
}
@@ -1033,11 +1031,13 @@ namespace ts {
1033
1031
function bindModuleExportsAssignment ( node : BinaryExpression ) {
1034
1032
// 'module.exports = expr' assignment
1035
1033
setCommonJsModuleIndicator ( node ) ;
1036
- declareSymbol ( file . symbol . exports , file . symbol , node , SymbolFlags . None , SymbolFlags . None ) ;
1034
+ bindExportAssignment ( node ) ;
1037
1035
}
1038
1036
1039
1037
function bindCallExpression ( node : CallExpression ) {
1040
- if ( isRequireCall ( node ) ) {
1038
+ // We're only inspecting call expressions to detect CommonJS modules, so we can skip
1039
+ // this check if we've already seen the module indicator
1040
+ if ( ! file . commonJsModuleIndicator && isRequireCall ( node ) ) {
1041
1041
setCommonJsModuleIndicator ( node ) ;
1042
1042
}
1043
1043
}
0 commit comments