fix invalid transform on const (#1919)

- preserve (re)assignment to `const` for runtime error
- suppress `cascade` on `const`, as runtime behaviour is ill-defined
This commit is contained in:
Alex Lam S.L
2017-05-12 04:51:44 +08:00
committed by GitHub
parent 2b44f4ae30
commit 1d407e761e
4 changed files with 107 additions and 2 deletions

View File

@@ -2186,3 +2186,49 @@ compound_assignment: {
}
expect_stdout: "4"
}
reassign_const_1: {
options = {
collapse_vars: true,
}
input: {
function f() {
const a = 1;
a = 2;
return a;
}
console.log(f());
}
expect: {
function f() {
const a = 1;
a = 2;
return a;
}
console.log(f());
}
expect_stdout: true
}
reassign_const_2: {
options = {
collapse_vars: true,
}
input: {
function f() {
const a = 1;
++a;
return a;
}
console.log(f());
}
expect: {
function f() {
const a = 1;
++a;
return a;
}
console.log(f());
}
expect_stdout: true
}