Skip to content

Commit ae65a41

Browse files
author
Andy Hanson
committed
A shorthand ambient module should be considered as possibly exporting a value.
1 parent ccca525 commit ae65a41

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/compiler/checker.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ namespace ts {
10431043
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
10441044

10451045
if (moduleSymbol) {
1046-
const exportDefaultSymbol = isShorthandAmbientModule(moduleSymbol.valueDeclaration) ?
1046+
const exportDefaultSymbol = isShorthandAmbientModuleSymbol(moduleSymbol) ?
10471047
moduleSymbol :
10481048
moduleSymbol.exports["export="] ?
10491049
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1119,7 +1119,7 @@ namespace ts {
11191119
if (targetSymbol) {
11201120
const name = specifier.propertyName || specifier.name;
11211121
if (name.text) {
1122-
if (isShorthandAmbientModule(moduleSymbol.valueDeclaration)) {
1122+
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
11231123
return moduleSymbol;
11241124
}
11251125

@@ -3381,7 +3381,7 @@ namespace ts {
33813381
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
33823382
const links = getSymbolLinks(symbol);
33833383
if (!links.type) {
3384-
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration>symbol.valueDeclaration)) {
3384+
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol(symbol)) {
33853385
links.type = anyType;
33863386
}
33873387
else {
@@ -18365,8 +18365,8 @@ namespace ts {
1836518365

1836618366
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
1836718367
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
18368-
if (!moduleSymbol) {
18369-
// module not found - be conservative
18368+
if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) {
18369+
// If the module is not found or is shorthand, assume that it may export a value.
1837018370
return true;
1837118371
}
1837218372

src/compiler/utilities.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ namespace ts {
414414
((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(<ModuleDeclaration>node));
415415
}
416416

417-
export function isShorthandAmbientModule(node: Node): boolean {
417+
export function isShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean {
418+
return isShorthandAmbientModule(moduleSymbol.valueDeclaration);
419+
}
420+
421+
function isShorthandAmbientModule(node: Node): boolean {
418422
// The only kind of module that can be missing a body is a shorthand ambient module.
419423
return node.kind === SyntaxKind.ModuleDeclaration && (!(<ModuleDeclaration>node).body);
420424
}

tests/baselines/reference/ambientShorthand_reExport.js

+4
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)