only '++' and '--' unary operators can change exports

This commit is contained in:
Vladimir Matveev 2015-12-18 11:21:31 -08:00
parent 22856de23a
commit a8f87bb2ca
5 changed files with 185 additions and 1 deletions

View File

@ -2445,7 +2445,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
const exportChanged = (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) &&
isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand);
if (exportChanged) {
// emit

View File

@ -0,0 +1,58 @@
//// [prefixUnaryOperatorsOnExportedVariables.ts]
export var x = false;
export var y = 1;
if (!x) {
}
if (+x) {
}
if (-x) {
}
if (~x) {
}
if (void x) {
}
if (typeof x) {
}
if (++y) {
}
//// [prefixUnaryOperatorsOnExportedVariables.js]
System.register([], function(exports_1) {
"use strict";
var x, y;
return {
setters:[],
execute: function() {
exports_1("x", x = false);
exports_1("y", y = 1);
if (!x) {
}
if (+x) {
}
if (-x) {
}
if (~x) {
}
if (void x) {
}
if (typeof x) {
}
if (exports_1("y", ++y)) {
}
}
}
});

View File

@ -0,0 +1,42 @@
=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts ===
export var x = false;
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
export var y = 1;
>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10))
if (!x) {
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
}
if (+x) {
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
}
if (-x) {
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
}
if (~x) {
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
}
if (void x) {
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
}
if (typeof x) {
>x : Symbol(x, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 1, 10))
}
if (++y) {
>y : Symbol(y, Decl(prefixUnaryOperatorsOnExportedVariables.ts, 2, 10))
}

View File

@ -0,0 +1,51 @@
=== tests/cases/compiler/prefixUnaryOperatorsOnExportedVariables.ts ===
export var x = false;
>x : boolean
>false : boolean
export var y = 1;
>y : number
>1 : number
if (!x) {
>!x : boolean
>x : boolean
}
if (+x) {
>+x : number
>x : boolean
}
if (-x) {
>-x : number
>x : boolean
}
if (~x) {
>~x : number
>x : boolean
}
if (void x) {
>void x : undefined
>x : boolean
}
if (typeof x) {
>typeof x : string
>x : boolean
}
if (++y) {
>++y : number
>y : number
}

View File

@ -0,0 +1,32 @@
// @target: ES5
// @module: system
export var x = false;
export var y = 1;
if (!x) {
}
if (+x) {
}
if (-x) {
}
if (~x) {
}
if (void x) {
}
if (typeof x) {
}
if (++y) {
}