TypeScript Version: typescript@4.0.0-dev.20200611 (also 3.9.5)
Search Terms: exported variable renamed
Code
// a.ts
let foo = 1
export { foo as fooValue }
export const testFoo = (val: number) => {
if (val <= ++foo) {
return val
}
return foo
}
And then run this in a terminal:
Expected behavior:
The command should output:
"use strict";
exports.__esModule = true;
exports.testFoo = exports.fooValue = void 0;
var foo = 1;
exports.fooValue = foo;
exports.testFoo = function (val) {
if (val <= (exports.fooValue = ++foo)) {
return val;
}
return foo;
};
Actual behavior:
The actual output is as the below, and require('./a.js') in Node.JS throws a SyntaxError
"use strict";
exports.__esModule = true;
exports.testFoo = exports.fooValue = void 0;
var foo = 1;
exports.fooValue = foo;
exports.testFoo = function (val) {
if (val <= exports.fooValue = ++foo) {
return val;
}
return foo;
};
If I run require("./a.js") in node, then it outputs:
Thrown:
R:\working\2\a.js:7
if (val <= exports.fooValue = ++foo) {
^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid left-hand side in assignment
Playground Link: https://www.staging-typescript.org/play?target=1&module=1#
Related Issues: None
TypeScript Version: typescript@4.0.0-dev.20200611 (also 3.9.5)
Search Terms: exported variable renamed
Code
And then run this in a terminal:
npx tsc a.ts && cat a.jsExpected behavior:
The command should output:
Actual behavior:
The actual output is as the below, and
require('./a.js')in Node.JS throws aSyntaxErrorIf I run
require("./a.js")innode, then it outputs:Playground Link: https://www.staging-typescript.org/play?target=1&module=1#
Related Issues: None