Skip to content

Commit 2aa1d71

Browse files
author
Andy
authored
Merge pull request #9348 from Microsoft/umd_exports
Fix bug where `exports.` was prepended to namespace export accesses
2 parents 5ce5b2d + a011b4d commit 2aa1d71

File tree

9 files changed

+18
-13
lines changed

9 files changed

+18
-13
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ namespace ts {
11251125
return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node);
11261126
}
11271127

1128-
function getTargetOfGlobalModuleExportDeclaration(node: NamespaceExportDeclaration): Symbol {
1128+
function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration): Symbol {
11291129
return resolveExternalModuleSymbol(node.parent.symbol);
11301130
}
11311131

@@ -1154,7 +1154,7 @@ namespace ts {
11541154
case SyntaxKind.ExportAssignment:
11551155
return getTargetOfExportAssignment(<ExportAssignment>node);
11561156
case SyntaxKind.NamespaceExportDeclaration:
1157-
return getTargetOfGlobalModuleExportDeclaration(<NamespaceExportDeclaration>node);
1157+
return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node);
11581158
}
11591159
}
11601160

@@ -17463,7 +17463,10 @@ namespace ts {
1746317463
const parentSymbol = getParentOfSymbol(symbol);
1746417464
if (parentSymbol) {
1746517465
if (parentSymbol.flags & SymbolFlags.ValueModule && parentSymbol.valueDeclaration.kind === SyntaxKind.SourceFile) {
17466-
return <SourceFile>parentSymbol.valueDeclaration;
17466+
// If `node` accesses an export and that export isn't in the same file, then symbol is a namespace export, so return undefined.
17467+
if (parentSymbol.valueDeclaration === getSourceFileOfNode(node)) {
17468+
return <SourceFile>parentSymbol.valueDeclaration;
17469+
}
1746717470
}
1746817471
for (let n = node.parent; n; n = n.parent) {
1746917472
if ((n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(n) === parentSymbol) {

src/compiler/emitter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
753753
return generateNameForExportDefault();
754754
case SyntaxKind.ClassExpression:
755755
return generateNameForClassExpression();
756+
default:
757+
Debug.fail();
756758
}
757759
}
758760

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,7 +4699,7 @@ namespace ts {
46994699
case SyntaxKind.EqualsToken:
47004700
return parseExportAssignment(fullStart, decorators, modifiers);
47014701
case SyntaxKind.AsKeyword:
4702-
return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers);
4702+
return parseNamespaceExportDeclaration(fullStart, decorators, modifiers);
47034703
default:
47044704
return parseExportDeclaration(fullStart, decorators, modifiers);
47054705
}
@@ -5378,7 +5378,7 @@ namespace ts {
53785378
return nextToken() === SyntaxKind.SlashToken;
53795379
}
53805380

5381-
function parseGlobalModuleExportDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): NamespaceExportDeclaration {
5381+
function parseNamespaceExportDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): NamespaceExportDeclaration {
53825382
const exportDeclaration = <NamespaceExportDeclaration>createNode(SyntaxKind.NamespaceExportDeclaration, fullStart);
53835383
exportDeclaration.decorators = decorators;
53845384
exportDeclaration.modifiers = modifiers;

tests/baselines/reference/umd-augmentation-2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ var t = p.x;
4242
//// [a.js]
4343
/// <reference path="node_modules/math2d/index.d.ts" />
4444
/// <reference path="math2d-augment.d.ts" />
45-
var v = new exports.Math2d.Vector(3, 2);
46-
var magnitude = exports.Math2d.getLength(v);
45+
var v = new Math2d.Vector(3, 2);
46+
var magnitude = Math2d.getLength(v);
4747
var p = v.translate(5, 5);
4848
p = v.reverse();
4949
var t = p.x;

tests/baselines/reference/umd-augmentation-4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ var t = p.x;
4848
//// [a.js]
4949
/// <reference path="node_modules/math2d/index.d.ts" />
5050
/// <reference path="math2d-augment.d.ts" />
51-
var v = new exports.Math2d.Vector(3, 2);
52-
var magnitude = exports.Math2d.getLength(v);
51+
var v = new Math2d.Vector(3, 2);
52+
var magnitude = Math2d.getLength(v);
5353
var p = v.translate(5, 5);
5454
p = v.reverse();
5555
var t = p.x;

tests/baselines/reference/umd1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ let y: number = x.n;
1616

1717
//// [a.js]
1818
/// <reference path="foo.d.ts" />
19-
exports.Foo.fn();
19+
Foo.fn();
2020
var x;
2121
var y = x.n;

tests/baselines/reference/umd5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Bar.fn();
2323
var x;
2424
var y = x.n;
2525
// should error
26-
var z = exports.Foo;
26+
var z = Foo;

tests/baselines/reference/umd6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ let y: number = Foo.fn();
1515

1616
//// [a.js]
1717
/// <reference path="foo.d.ts" />
18-
var y = exports.Foo.fn();
18+
var y = Foo.fn();

tests/baselines/reference/umd7.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ let y: number = Foo();
1313

1414
//// [a.js]
1515
/// <reference path="foo.d.ts" />
16-
var y = exports.Foo();
16+
var y = Foo();

0 commit comments

Comments
 (0)