Skip to content

Commit 6ba0285

Browse files
committed
Merge pull request #7707 from Microsoft/transforms-unary-operators-system
fix emit for unary operators on exported variables in system modules
2 parents 5880029 + 8ebe081 commit 6ba0285

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

src/compiler/transformers/module/system.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,13 +1092,16 @@ namespace ts {
10921092
if (substitute) {
10931093
const exportDeclaration = resolver.getReferencedExportContainer(<Identifier>operand);
10941094
if (exportDeclaration) {
1095-
const expr = createPostfix(operand, node.operator, node);
1095+
const expr = createPrefix(node.operator, operand, node);
10961096
setNodeEmitFlags(expr, NodeEmitFlags.NoSubstitution);
10971097
const call = createExportExpression(<Identifier>operand, expr);
10981098
if (node.kind === SyntaxKind.PrefixUnaryExpression) {
10991099
return call;
11001100
}
11011101
else {
1102+
// export function returns the value that was passes as the second argument
1103+
// however for postfix unary expressions result value should be the value before modification.
1104+
// emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)'
11021105
return operator === SyntaxKind.PlusPlusToken
11031106
? createSubtract(call, createLiteral(1))
11041107
: createAdd(call, createLiteral(1));

tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ if (++y) {
3131
}
3232

3333
//// [prefixUnaryOperatorsOnExportedVariables.js]
34-
System.register([], function(exports_1, context_1) {
34+
System.register([], function (exports_1, context_1) {
3535
"use strict";
3636
var __moduleName = context_1 && context_1.id;
3737
var x, y;
3838
return {
39-
setters:[],
40-
execute: function() {
39+
setters: [],
40+
execute: function () {
4141
exports_1("x", x = false);
4242
exports_1("y", y = 1);
4343
if (!x) {
@@ -55,5 +55,5 @@ System.register([], function(exports_1, context_1) {
5555
if (exports_1("y", ++y)) {
5656
}
5757
}
58-
}
58+
};
5959
});

tests/baselines/reference/systemModule10.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export {n2}
1010
export {n2 as n3}
1111

1212
//// [systemModule10.js]
13-
System.register(['file1', 'file2'], function (exports_1, context_1) {
13+
System.register(["file1", "file2"], function (exports_1, context_1) {
1414
"use strict";
1515
var __moduleName = context_1 && context_1.id;
1616
var file1_1, n2;

tests/baselines/reference/systemModule10_ES5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export {n2}
1010
export {n2 as n3}
1111

1212
//// [systemModule10_ES5.js]
13-
System.register(['file1', 'file2'], function (exports_1, context_1) {
13+
System.register(["file1", "file2"], function (exports_1, context_1) {
1414
"use strict";
1515
var __moduleName = context_1 && context_1.id;
1616
var file1_1, n2;

tests/baselines/reference/systemModule17.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ System.register(["f1"], function (exports_1, context_1) {
6565
var x, N, IX, f1_1;
6666
return {
6767
setters: [
68-
function (_1) {
69-
f1_1 = _1;
68+
function (f1_1_1) {
69+
f1_1 = f1_1_1;
7070
}
7171
],
7272
execute: function () {

tests/baselines/reference/systemModule8.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ System.register([], function (exports_1, context_1) {
4242
setters: [],
4343
execute: function () {
4444
exports_1("x", x = 1);
45-
exports_1("x", x++) - 1;
46-
exports_1("x", x--) + 1;
47-
exports_1("x", x++);
48-
exports_1("x", x--);
45+
exports_1("x", ++x) - 1;
46+
exports_1("x", --x) + 1;
47+
exports_1("x", ++x);
48+
exports_1("x", --x);
4949
exports_1("x", x += 1);
5050
exports_1("x", x -= 1);
5151
exports_1("x", x *= 1);
@@ -56,10 +56,10 @@ System.register([], function (exports_1, context_1) {
5656
x - 1;
5757
x & 1;
5858
x | 1;
59-
for (exports_1("x", x = 5);; exports_1("x", x++) - 1) { }
60-
for (exports_1("x", x = 8);; exports_1("x", x--) + 1) { }
61-
for (exports_1("x", x = 15);; exports_1("x", x++)) { }
62-
for (exports_1("x", x = 18);; exports_1("x", x--)) { }
59+
for (exports_1("x", x = 5);; exports_1("x", ++x) - 1) { }
60+
for (exports_1("x", x = 8);; exports_1("x", --x) + 1) { }
61+
for (exports_1("x", x = 15);; exports_1("x", ++x)) { }
62+
for (exports_1("x", x = 18);; exports_1("x", --x)) { }
6363
for (x = 50;;) { }
6464
exports_1("y", y = [1][0]);
6565
_a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c);

0 commit comments

Comments
 (0)