Skip to content

Commit b5d2707

Browse files
author
Andy
authored
Merge pull request #10789 from Microsoft/re_export_shorthand
A shorthand ambient module should be considered as possibly exporting a value
2 parents 6b25dab + ae65a41 commit b5d2707

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

@@ -3382,7 +3382,7 @@ namespace ts {
33823382
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
33833383
const links = getSymbolLinks(symbol);
33843384
if (!links.type) {
3385-
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration>symbol.valueDeclaration)) {
3385+
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol(symbol)) {
33863386
links.type = anyType;
33873387
}
33883388
else {
@@ -18371,8 +18371,8 @@ namespace ts {
1837118371

1837218372
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
1837318373
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
18374-
if (!moduleSymbol) {
18375-
// module not found - be conservative
18374+
if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) {
18375+
// If the module is not found or is shorthand, assume that it may export a value.
1837618376
return true;
1837718377
}
1837818378

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)