-
Notifications
You must be signed in to change notification settings - Fork 13k
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
TypeScript Version: [email protected] (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:
npx tsc a.ts && cat a.js
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
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone