Skip to content

Commit ce98da3

Browse files
Merge pull request microsoft#3085 from tinganho/nonInitExport
No emit on non initialized exports
2 parents 7dd1f3f + 60bf572 commit ce98da3

File tree

214 files changed

+1659
-1056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+1659
-1056
lines changed

src/compiler/emitter.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
139139
let exportEquals: ExportAssignment;
140140
let hasExportStars: boolean;
141141

142-
/** write emitted output to disk*/
142+
/** Write emitted output to disk */
143143
let writeEmittedFiles = writeJavaScriptFile;
144144

145145
let detachedCommentsInfo: { nodePos: number; detachedCommentEndPos: number }[];
@@ -3059,13 +3059,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
30593059
}
30603060

30613061
function emitVariableStatement(node: VariableStatement) {
3062-
let startIsEmitted = true;
3063-
if (!(node.flags & NodeFlags.Export)) {
3064-
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
3062+
let startIsEmitted = false;
3063+
if (node.flags & NodeFlags.Export) {
3064+
if (isES6ExportedDeclaration(node)) {
3065+
// Exported ES6 module member
3066+
write("export ");
3067+
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
3068+
}
30653069
}
3066-
else if (isES6ExportedDeclaration(node)) {
3067-
// Exported ES6 module member
3068-
write("export ");
3070+
else {
30693071
startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList);
30703072
}
30713073
if (startIsEmitted) {

tests/baselines/reference/ExportVariableOfGenericTypeWithInaccessibleTypeAsTypeArgument.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ var A;
1616
}
1717
return B;
1818
})();
19-
A.beez;
2019
A.beez2 = new Array();
2120
})(A || (A = {}));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
tests/cases/conformance/internalModules/exportDeclarations/NonInitializedExportInInternalModule.ts(3,8): error TS1123: Variable declaration list cannot be empty.
2+
tests/cases/conformance/internalModules/exportDeclarations/NonInitializedExportInInternalModule.ts(4,5): error TS2304: Cannot find name 'let'.
3+
tests/cases/conformance/internalModules/exportDeclarations/NonInitializedExportInInternalModule.ts(5,10): error TS1123: Variable declaration list cannot be empty.
4+
5+
6+
==== tests/cases/conformance/internalModules/exportDeclarations/NonInitializedExportInInternalModule.ts (3 errors) ====
7+
8+
module Inner {
9+
var;
10+
11+
!!! error TS1123: Variable declaration list cannot be empty.
12+
let;
13+
~~~
14+
!!! error TS2304: Cannot find name 'let'.
15+
const;
16+
17+
!!! error TS1123: Variable declaration list cannot be empty.
18+
19+
export var a;
20+
export let b;
21+
export var c: string;
22+
export let d: number;
23+
class A {}
24+
export var e: A;
25+
export let f: A;
26+
27+
namespace B {
28+
export let a = 1, b, c = 2;
29+
export let x, y, z;
30+
}
31+
32+
module C {
33+
export var a = 1, b, c = 2;
34+
export var x, y, z;
35+
}
36+
37+
// Shouldn't be filtered
38+
export var a1 = 1;
39+
export let b1 = 1;
40+
export var c1: string = 'a';
41+
export let d1: number = 1;
42+
class D {}
43+
export var e1 = new D;
44+
export let f1 = new D;
45+
export var g1: D = new D;
46+
export let h1: D = new D;
47+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//// [NonInitializedExportInInternalModule.ts]
2+
3+
module Inner {
4+
var;
5+
let;
6+
const;
7+
8+
export var a;
9+
export let b;
10+
export var c: string;
11+
export let d: number;
12+
class A {}
13+
export var e: A;
14+
export let f: A;
15+
16+
namespace B {
17+
export let a = 1, b, c = 2;
18+
export let x, y, z;
19+
}
20+
21+
module C {
22+
export var a = 1, b, c = 2;
23+
export var x, y, z;
24+
}
25+
26+
// Shouldn't be filtered
27+
export var a1 = 1;
28+
export let b1 = 1;
29+
export var c1: string = 'a';
30+
export let d1: number = 1;
31+
class D {}
32+
export var e1 = new D;
33+
export let f1 = new D;
34+
export var g1: D = new D;
35+
export let h1: D = new D;
36+
}
37+
38+
//// [NonInitializedExportInInternalModule.js]
39+
var Inner;
40+
(function (Inner) {
41+
var ;
42+
let;
43+
var ;
44+
var A = (function () {
45+
function A() {
46+
}
47+
return A;
48+
})();
49+
var B;
50+
(function (B) {
51+
B.a = 1, B.c = 2;
52+
})(B || (B = {}));
53+
var C;
54+
(function (C) {
55+
C.a = 1, C.c = 2;
56+
})(C || (C = {}));
57+
// Shouldn't be filtered
58+
Inner.a1 = 1;
59+
Inner.b1 = 1;
60+
Inner.c1 = 'a';
61+
Inner.d1 = 1;
62+
var D = (function () {
63+
function D() {
64+
}
65+
return D;
66+
})();
67+
Inner.e1 = new D;
68+
Inner.f1 = new D;
69+
Inner.g1 = new D;
70+
Inner.h1 = new D;
71+
})(Inner || (Inner = {}));

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ var A;
3939
(function (A) {
4040
var B;
4141
(function (B) {
42-
B.x;
4342
})(B = A.B || (A.B = {}));
4443
})(A || (A = {}));
4544
var A;
4645
(function (A) {
4746
var B;
4847
(function (B) {
49-
B.x;
5048
})(B || (B = {}));
5149
})(A || (A = {}));
5250
// ensure the right var decl is exported

tests/baselines/reference/additionOperatorWithAnyAndEveryType.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ var E;
5555
})(E || (E = {}));
5656
var M;
5757
(function (M) {
58-
M.a;
5958
})(M || (M = {}));
6059
var a;
6160
var b;

tests/baselines/reference/additionOperatorWithInvalidOperands.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ var E;
5656
})(E || (E = {}));
5757
var M;
5858
(function (M) {
59-
M.a;
6059
})(M || (M = {}));
6160
var a;
6261
var b;

tests/baselines/reference/aliasUsedAsNameValue.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export var a = function () {
1919

2020

2121
//// [aliasUsedAsNameValue_0.js]
22-
exports.id;
2322
//// [aliasUsedAsNameValue_1.js]
2423
function b(a) { return null; }
2524
exports.b = b;

tests/baselines/reference/assignmentCompatability2.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var __test1__;
1919
})(__test1__ || (__test1__ = {}));
2020
var __test2__;
2121
(function (__test2__) {
22-
__test2__.aa;
2322
;
2423
__test2__.__val__aa = __test2__.aa;
2524
})(__test2__ || (__test2__ = {}));

tests/baselines/reference/assignmentCompatability25.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var __test1__;
1919
})(__test1__ || (__test1__ = {}));
2020
var __test2__;
2121
(function (__test2__) {
22-
__test2__.aa;
2322
;
2423
__test2__.__val__aa = __test2__.aa;
2524
})(__test2__ || (__test2__ = {}));

0 commit comments

Comments
 (0)