@@ -1005,6 +1005,13 @@ namespace ts {
10051005 return getTargetOfExportSpecifier(<ExportSpecifier>node);
10061006 case SyntaxKind.ExportAssignment:
10071007 return getTargetOfExportAssignment(<ExportAssignment>node);
1008+ case SyntaxKind.BinaryExpression:
1009+ // module.exports = ...
1010+ const targetExpr = (node as BinaryExpression).right;
1011+ if (targetExpr.kind === SyntaxKind.Identifier) {
1012+ return resolveName(node, (targetExpr as Identifier).text, SymbolFlags.Value, Diagnostics.Cannot_find_name_0, (targetExpr as Identifier));
1013+ }
1014+ return getSymbolOfNode((node as BinaryExpression).right);
10081015 }
10091016 }
10101017
@@ -1197,6 +1204,12 @@ namespace ts {
11971204 // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
11981205 function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol {
11991206 let symbol = resolveExternalModuleSymbol(moduleSymbol);
1207+
1208+ if (moduleSymbol && moduleSymbol.valueDeclaration && (<SourceFile>moduleSymbol.valueDeclaration).commonJsModuleIndicator) {
1209+ // CommonJS module could module.export nearly any value. TODO(billti): Should check for some valid value?
1210+ return symbol;
1211+ }
1212+
12001213 if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
12011214 error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
12021215 symbol = undefined;
@@ -2973,6 +2986,14 @@ namespace ts {
29732986 return links.type;
29742987 }
29752988
2989+ function getTypeOfObjectLiteralSymbol(symbol: Symbol): Type {
2990+ const links = getSymbolLinks(symbol);
2991+ if (!links.type) {
2992+ links.type = checkObjectLiteral(symbol.declarations[0] as ObjectLiteralExpression);
2993+ }
2994+ return links.type;
2995+ }
2996+
29762997 function getTypeOfSymbol(symbol: Symbol): Type {
29772998 if (symbol.flags & SymbolFlags.Instantiated) {
29782999 return getTypeOfInstantiatedSymbol(symbol);
@@ -2992,6 +3013,9 @@ namespace ts {
29923013 if (symbol.flags & SymbolFlags.Alias) {
29933014 return getTypeOfAlias(symbol);
29943015 }
3016+ if (symbol.flags & SymbolFlags.ObjectLiteral) {
3017+ return getTypeOfObjectLiteralSymbol(symbol);
3018+ }
29953019 return unknownType;
29963020 }
29973021
0 commit comments