Skip to content

Commit 1e64f16

Browse files
committed
Merge pull request microsoft#6157 from Microsoft/wrongExportInSystem
only '++' and '--' unary operators can change exports
2 parents 22856de + a8f87bb commit 1e64f16

5 files changed

+185
-1
lines changed

src/compiler/emitter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
24452445
}
24462446

24472447
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
2448-
const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
2448+
const exportChanged = (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) &&
2449+
isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
24492450

24502451
if (exportChanged) {
24512452
// emit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//// [prefixUnaryOperatorsOnExportedVariables.ts]
2+
3+
export var x = false;
4+
export var y = 1;
5+
if (!x) {
6+
7+
}
8+
9+
if (+x) {
10+
11+
}
12+
13+
if (-x) {
14+
15+
}
16+
17+
if (~x) {
18+
19+
}
20+
21+
if (void x) {
22+
23+
}
24+
25+
if (typeof x) {
26+
27+
}
28+
29+
if (++y) {
30+
31+
}
32+
33+
//// [prefixUnaryOperatorsOnExportedVariables.js]
34+
System.register([], function(exports_1) {
35+
"use strict";
36+
var x, y;
37+
return {
38+
setters:[],
39+
execute: function() {
40+
exports_1("x", x = false);
41+
exports_1("y", y = 1);
42+
if (!x) {
43+
}
44+
if (+x) {
45+
}
46+
if (-x) {
47+
}
48+
if (~x) {
49+
}
50+
if (void x) {
51+
}
52+
if (typeof x) {
53+
}
54+
if (exports_1("y", ++y)) {
55+
}
56+
}
57+
}
58+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts ===
2+
3+
export var x = false;
4+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
5+
6+
export var y = 1;
7+
>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10))
8+
9+
if (!x) {
10+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
11+
12+
}
13+
14+
if (+x) {
15+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
16+
17+
}
18+
19+
if (-x) {
20+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
21+
22+
}
23+
24+
if (~x) {
25+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
26+
27+
}
28+
29+
if (void x) {
30+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
31+
32+
}
33+
34+
if (typeof x) {
35+
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
36+
37+
}
38+
39+
if (++y) {
40+
>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10))
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts ===
2+
3+
export var x = false;
4+
>x : boolean
5+
>false : boolean
6+
7+
export var y = 1;
8+
>y : number
9+
>1 : number
10+
11+
if (!x) {
12+
>!x : boolean
13+
>x : boolean
14+
15+
}
16+
17+
if (+x) {
18+
>+x : number
19+
>x : boolean
20+
21+
}
22+
23+
if (-x) {
24+
>-x : number
25+
>x : boolean
26+
27+
}
28+
29+
if (~x) {
30+
>~x : number
31+
>x : boolean
32+
33+
}
34+
35+
if (void x) {
36+
>void x : undefined
37+
>x : boolean
38+
39+
}
40+
41+
if (typeof x) {
42+
>typeof x : string
43+
>x : boolean
44+
45+
}
46+
47+
if (++y) {
48+
>++y : number
49+
>y : number
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @target: ES5
2+
// @module: system
3+
4+
export var x = false;
5+
export var y = 1;
6+
if (!x) {
7+
8+
}
9+
10+
if (+x) {
11+
12+
}
13+
14+
if (-x) {
15+
16+
}
17+
18+
if (~x) {
19+
20+
}
21+
22+
if (void x) {
23+
24+
}
25+
26+
if (typeof x) {
27+
28+
}
29+
30+
if (++y) {
31+
32+
}

0 commit comments

Comments
 (0)