8000 Address CR feedback · sweshgit/TypeScript@2f7719b · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 2f7719b

Browse files
committed
Address CR feedback
1 parent 1a36fce commit 2f7719b

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

src/compiler/binder.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,12 @@ namespace ts {
166166
return "__export";
167167
case SyntaxKind.ExportAssignment:
168168
return (<ExportAssignment>node).isExportEquals ? "export=" : "default";
169+
case SyntaxKind.BinaryExpression:
170+
// Binary expression case is for JS module 'module.exports = expr'
171+
return "export=";
169172
case SyntaxKind.FunctionDeclaration:
170173
case SyntaxKind.ClassDeclaration:
171174
return node.flags & NodeFlags.Default ? "default" : undefined;
172-
173-
case SyntaxKind.BinaryExpression:
174-
Debug.assert(isModuleExportsAssignment(node));
175-
return "__jsExports";
176175
}
177176
}
178177

@@ -936,9 +935,7 @@ namespace ts {
936935
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, bindingName);
937936

938937
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) {
942939
bindCallExpression(<CallExpression>node);
943940
}
944941
break;
@@ -984,12 +981,13 @@ namespace ts {
984981
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName) }"`);
985982
}
986983

987-
function bindExportAssignment(node: ExportAssignment) {
984+
function bindExportAssignment(node: ExportAssignment|BinaryExpression) {
985+
let boundExpression = node.kind === SyntaxKind.ExportAssignment ? (<ExportAssignment>node).expression : (<BinaryExpression>node).right;
988986
if (!container.symbol || !container.symbol.exports) {
989987
// Export assignment in some sort of block construct
990988
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
991989
}
992-
else if (node.expression.kind === SyntaxKind.Identifier) {
990+
else if (boundExpression.kind === SyntaxKind.Identifier) {
993991
// An export default clause with an identifier exports all meanings of that identifier
994992
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
995993
}
@@ -1033,11 +1031,13 @@ namespace ts {
10331031
function bindModuleExportsAssignment(node: BinaryExpression) {
10341032
// 'module.exports = expr' assignment
10351033
setCommonJsModuleIndicator(node);
1036-
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.None, SymbolFlags.None);
1034+
bindExportAssignment(node);
10371035
}
10381036

10391037
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)) {
10411041
setCommonJsModuleIndicator(node);
10421042
}
10431043
}

src/compiler/checker.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,20 +1087,6 @@ namespace ts {
10871087
visit(resolveExternalModuleName(node, (<ExportDeclaration>node).moduleSpecifier));
10881088
}
10891089
}
1090-
1091-
// CommonJS 'module.exports = expr' assignments
1092-
let commonJsModuleExports = symbol.exports["__jsExports"];
1093-
if (commonJsModuleExports) {
1094-
for (var i = 0; i < commonJsModuleExports.declarations.length; i++) {
1095-
let properties = getPropertiesOfType(checkExpression((<BinaryExpression>commonJsModuleExports.declarations[i]).right));
1096-
if (i === 0) {
1097-
result = createSymbolTable(properties);
1098-
}
1099-
else {
1100-
mergeSymbolTable(result, createSymbolTable(properties));
1101-
}
1102-
}
1103-
}
11041090
}
11051091
}
11061092
}
@@ -2586,6 +2572,10 @@ namespace ts {
25862572
if (declaration.kind === SyntaxKind.ExportAssignment) {
25872573
return links.type = checkExpression((<ExportAssignment>declaration).expression);
25882574
}
2575+
// Handle module.exports = expr
2576+
if (declaration.kind === SyntaxKind.BinaryExpression) {
2577+
return links.type = checkExpression((<BinaryExpression>declaration).right);
2578+
}
25892579
// Handle exports.p = expr
25902580
if (declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) {
25912581
return checkExpressionCached((<BinaryExpression>declaration.parent).right);
@@ -3839,9 +3829,9 @@ namespace ts {
38393829
function resolveExternalModuleTypeByLiteral(name: StringLiteral) {
38403830
let moduleSym = resolveExternalModuleName(name, name);
38413831
if (moduleSym) {
3842-
let moduleSymSym = resolveExternalModuleSymbol(moduleSym);
3843-
if (moduleSymSym) {
3844-
return getTypeOfSymbol(moduleSymSym);
3832+
let resolvedModuleSymbol = resolveExternalModuleSymbol(moduleSym);
3833+
if (resolvedModuleSymbol) {
3834+
return getTypeOfSymbol(resolvedModuleSymbol);
38453835
}
38463836
}
38473837

tests/cases/fourslash/javaScriptModules13.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// @Filename: myMod.js
77
//// if (true) {
88
//// module.exports = { a: 10 };
9-
//// } else {
10-
//// module.exports = { b: 10 };
119
//// }
1210
//// var invisible = true;
1311

@@ -26,4 +24,3 @@ verify.not.completionListContains('invisible');
2624

2725
edit.insert('x.');
2826
verify.completionListContains('a');
29-
verify.completionListContains('b');

0 commit comments

Comments
 (0)
0