Skip to content

Commit 4a919d4

Browse files
committed
exclude 'default' from star exports
1 parent 5f18d9b commit 4a919d4

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

src/compiler/emitter.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,11 +5047,11 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
50475047
writeLine();
50485048
write(` for(var n in m) {`);
50495049
writeLine();
5050-
write(` `);
5050+
write(` if (n !== "default"`);
50515051
if (localNames) {
5052-
write(`if (!${localNames}.hasOwnProperty(n)) `);
5052+
write(`&& !${localNames}.hasOwnProperty(n)`);
50535053
}
5054-
write(`${exportFunctionForFile}(n, m[n]);`);
5054+
write(`) ${exportFunctionForFile}(n, m[n]);`);
50555055
writeLine();
50565056
write(" }");
50575057
writeLine();
@@ -5061,6 +5061,10 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
50615061
}
50625062

50635063
function writeExportedName(node: Identifier | Declaration): void {
5064+
if (node.kind !== SyntaxKind.Identifier && node.flags & NodeFlags.Default) {
5065+
return;
5066+
}
5067+
50645068
if (started) {
50655069
write(",");
50665070
}
@@ -5073,9 +5077,6 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
50735077
if (node.kind === SyntaxKind.Identifier) {
50745078
emitNodeWithoutSourceMap(node);
50755079
}
5076-
else if (node.flags & NodeFlags.Default) {
5077-
write("default");
5078-
}
50795080
else {
50805081
emitDeclarationName(<Declaration>node);
50815082
}

tests/baselines/reference/systemModule11.errors.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/compiler/file1.ts(7,15): error TS2307: Cannot find module 'bar'.
22
tests/cases/compiler/file2.ts(7,15): error TS2307: Cannot find module 'bar'.
33
tests/cases/compiler/file3.ts(2,25): error TS2307: Cannot find module 'a'.
4-
tests/cases/compiler/file3.ts(3,15): error TS2307: Cannot find module 'bar'.
5-
tests/cases/compiler/file4.ts(8,27): error TS2307: Cannot find module 'a'.
4+
tests/cases/compiler/file3.ts(4,15): error TS2307: Cannot find module 'bar'.
5+
tests/cases/compiler/file4.ts(9,27): error TS2307: Cannot find module 'a'.
66
tests/cases/compiler/file5.ts(3,15): error TS2307: Cannot find module 'a'.
77

88

@@ -33,6 +33,7 @@ tests/cases/compiler/file5.ts(3,15): error TS2307: Cannot find module 'a'.
3333
export {x, y as z} from 'a';
3434
~~~
3535
!!! error TS2307: Cannot find module 'a'.
36+
export default function foo() {}
3637
export * from 'bar';
3738
~~~~~
3839
!!! error TS2307: Cannot find module 'bar'.
@@ -41,6 +42,7 @@ tests/cases/compiler/file5.ts(3,15): error TS2307: Cannot find module 'a'.
4142

4243
export var x;
4344
export function foo() {}
45+
export default function (){}
4446

4547
var z, z1;
4648
export {z, z1 as z2};

tests/baselines/reference/systemModule11.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export * from 'bar';
2121
//// [file3.ts]
2222

2323
export {x, y as z} from 'a';
24+
export default function foo() {}
2425
export * from 'bar';
2526

2627
//// [file4.ts]
2728

2829
export var x;
2930
export function foo() {}
31+
export default function (){}
3032

3133
var z, z1;
3234
export {z, z1 as z2};
@@ -50,7 +52,7 @@ System.register(['bar'], function(exports_1) {
5052
};
5153
function exportStar_1(m) {
5254
for(var n in m) {
53-
if (!exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
55+
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
5456
}
5557
}
5658
return {
@@ -72,7 +74,7 @@ System.register(['bar'], function(exports_1) {
7274
};
7375
function exportStar_1(m) {
7476
for(var n in m) {
75-
if (!exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
77+
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
7678
}
7779
}
7880
return {
@@ -88,13 +90,15 @@ System.register(['bar'], function(exports_1) {
8890
});
8991
//// [file3.js]
9092
System.register(['a', 'bar'], function(exports_1) {
93+
function foo() { }
94+
exports_1("default", foo);
9195
var exportedNames_1 = {
9296
'x': true,
9397
'z': true
9498
};
9599
function exportStar_1(m) {
96100
for(var n in m) {
97-
if (!exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
101+
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
98102
}
99103
}
100104
return {
@@ -115,6 +119,8 @@ System.register(['a'], function(exports_1) {
115119
var x, z, z1;
116120
function foo() { }
117121
exports_1("foo", foo);
122+
function default_1() { }
123+
exports_1("default", default_1);
118124
return {
119125
setters:[
120126
function (_a_1) {
@@ -133,7 +139,7 @@ System.register(['a'], function(exports_1) {
133139
function foo() { }
134140
function exportStar_1(m) {
135141
for(var n in m) {
136-
exports_1(n, m[n]);
142+
if (n !== "default") exports_1(n, m[n]);
137143
}
138144
}
139145
return {

tests/baselines/reference/systemModule9.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'],
3131
};
3232
function exportStar_1(m) {
3333
for(var n in m) {
34-
if (!exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
34+
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]);
3535
}
3636
}
3737
return {

tests/cases/compiler/systemModule11.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export * from 'bar';
2121
// @filename: file3.ts
2222

2323
export {x, y as z} from 'a';
24+
export default function foo() {}
2425
export * from 'bar';
2526

2627
// @filename: file4.ts
2728

2829
export var x;
2930
export function foo() {}
31+
export default function (){}
3032

3133
var z, z1;
3234
export {z, z1 as z2};

0 commit comments

Comments
 (0)