enhance reduce_vars (#1814)
- allow immediate assignment after declaration of variable - relax modification rule for immutable value - fix order of visit for TreeWalker - remove extraneous code
This commit is contained in:
@@ -1996,6 +1996,146 @@ catch_var: {
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
var_assign_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a;
|
||||
a = 2;
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
console.log(2);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "2"
|
||||
}
|
||||
|
||||
var_assign_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a;
|
||||
if (a = 2) console.log(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
if (2) console.log(2);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "2"
|
||||
}
|
||||
|
||||
var_assign_3: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a;
|
||||
while (a = 2);
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
var a;
|
||||
while (a = 2);
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
var_assign_4: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function a() {
|
||||
a = 2;
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function a() {
|
||||
a = 2,
|
||||
console.log(a);
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
var_assign_5: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a;
|
||||
!function(b) {
|
||||
a = 2;
|
||||
console.log(a, b);
|
||||
}(a);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
var a;
|
||||
!function(b) {
|
||||
a = 2,
|
||||
console.log(a, b);
|
||||
}(a);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "2 undefined"
|
||||
}
|
||||
|
||||
immutable: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
var a = "test";
|
||||
console.log(a.indexOf("e"));
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
console.log("test".indexOf("e"));
|
||||
}();
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_1814_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
|
||||
Reference in New Issue
Block a user