Skip to content

Commit 545d7e5

Browse files
author
Andy Hanson
committed
A shorthand ambient module should be considered as possibly exporting a value
1 parent 11e9f50 commit 545d7e5

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ namespace ts {
10391039
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
10401040

10411041
if (moduleSymbol) {
1042-
const exportDefaultSymbol = isShorthandAmbientModule(moduleSymbol.valueDeclaration) ?
1042+
const exportDefaultSymbol = isShorthandAmbientModuleSymbol(moduleSymbol) ?
10431043
moduleSymbol :
10441044
moduleSymbol.exports["export="] ?
10451045
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1115,7 +1115,7 @@ namespace ts {
11151115
if (targetSymbol) {
11161116
const name = specifier.propertyName || specifier.name;
11171117
if (name.text) {
1118-
if (isShorthandAmbientModule(moduleSymbol.valueDeclaration)) {
1118+
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
11191119
return moduleSymbol;
11201120
}
11211121

@@ -3369,7 +3369,7 @@ namespace ts {
33693369
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
33703370
const links = getSymbolLinks(symbol);
33713371
if (!links.type) {
3372-
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration>symbol.valueDeclaration)) {
3372+
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol(symbol)) {
33733373
links.type = anyType;
33743374
}
33753375
else {
@@ -18292,8 +18292,8 @@ namespace ts {
1829218292

1829318293
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
1829418294
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
18295-
if (!moduleSymbol) {
18296-
// module not found - be conservative
18295+
if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) {
18296+
// If the module is not found or is shorthand, assume that it may export a value.
1829718297
return true;
1829818298
}
1829918299

src/compiler/utilities.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ namespace ts {
360360
((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(<ModuleDeclaration>node));
361361
}
362362

363-
export function isShorthandAmbientModule(node: Node): boolean {
363+
export function isShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean {
364+
return isShorthandAmbientModule(moduleSymbol.valueDeclaration);
365+
}
366+
367+
function isShorthandAmbientModule(node: Node): boolean {
364368
// The only kind of module that can be missing a body is a shorthand ambient module.
365369
return node.kind === SyntaxKind.ModuleDeclaration && (!(<ModuleDeclaration>node).body);
366370
}

tests/baselines/reference/ambientShorthand_reExport.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ var jquery_1 = require("jquery");
2222
exports.x = jquery_1.x;
2323
//// [reExportAll.js]
2424
"use strict";
25+
function __export(m) {
26+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
27+
}
28+
__export(require("jquery"));
2529
//// [reExportUser.js]
2630
"use strict";
2731
var reExportX_1 = require("./reExportX");

0 commit comments

Comments
 (0)