handle overlapped variable definitions (#1691)
Process variable definitions with or without assigned values against: - `arguments` - named function arguments - multiple definitions within same scope Essentially demote variable declarations with no value assignments. Also fixed invalid use of `AST_VarDef` over `arguments` - should use a member of `AST_SymbolDeclaration` instead.
This commit is contained in:
@@ -425,7 +425,7 @@ iife_new: {
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
multi_def: {
|
||||
multi_def_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
@@ -435,7 +435,7 @@ multi_def: {
|
||||
if (a)
|
||||
var b = 1;
|
||||
else
|
||||
var b = 2
|
||||
var b = 2;
|
||||
console.log(b + 1);
|
||||
}
|
||||
}
|
||||
@@ -444,7 +444,7 @@ multi_def: {
|
||||
if (a)
|
||||
var b = 1;
|
||||
else
|
||||
var b = 2
|
||||
var b = 2;
|
||||
console.log(b + 1);
|
||||
}
|
||||
}
|
||||
@@ -479,6 +479,33 @@ multi_def_2: {
|
||||
}
|
||||
}
|
||||
|
||||
multi_def_3: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b = 2;
|
||||
if (a)
|
||||
var b;
|
||||
else
|
||||
var b;
|
||||
console.log(b + 1);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b = 2;
|
||||
if (a)
|
||||
var b;
|
||||
else
|
||||
var b;
|
||||
console.log(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use_before_var: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
@@ -1571,3 +1598,259 @@ unary_delete: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
redefine_arguments_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
var arguments;
|
||||
return typeof arguments;
|
||||
}
|
||||
function g() {
|
||||
var arguments = 42;
|
||||
return typeof arguments;
|
||||
}
|
||||
function h(x) {
|
||||
var arguments = x;
|
||||
return typeof arguments;
|
||||
}
|
||||
console.log(f(), g(), h());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
var arguments;
|
||||
return typeof arguments;
|
||||
}
|
||||
function g() {
|
||||
return"number";
|
||||
}
|
||||
function h(x) {
|
||||
var arguments = x;
|
||||
return typeof arguments;
|
||||
}
|
||||
console.log(f(), g(), h());
|
||||
}
|
||||
expect_stdout: "object number undefined"
|
||||
}
|
||||
|
||||
redefine_arguments_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
var arguments;
|
||||
return typeof arguments;
|
||||
}
|
||||
function g() {
|
||||
var arguments = 42;
|
||||
return typeof arguments;
|
||||
}
|
||||
function h(x) {
|
||||
var arguments = x;
|
||||
return typeof arguments;
|
||||
}
|
||||
console.log(f(), g(), h());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var arguments;
|
||||
return typeof arguments;
|
||||
}(), function() {
|
||||
return"number";
|
||||
}(), function(x) {
|
||||
var arguments = x;
|
||||
return typeof arguments;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "object number undefined"
|
||||
}
|
||||
|
||||
redefine_arguments_3: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
var arguments;
|
||||
return typeof arguments;
|
||||
}
|
||||
function g() {
|
||||
var arguments = 42;
|
||||
return typeof arguments;
|
||||
}
|
||||
function h(x) {
|
||||
var arguments = x;
|
||||
return typeof arguments;
|
||||
}
|
||||
console.log(f(), g(), h());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var arguments;
|
||||
return typeof arguments;
|
||||
}(), "number", "undefined");
|
||||
}
|
||||
expect_stdout: "object number undefined"
|
||||
}
|
||||
|
||||
redefine_farg_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var a;
|
||||
return typeof a;
|
||||
}
|
||||
function g(a) {
|
||||
var a = 42;
|
||||
return typeof a;
|
||||
}
|
||||
function h(a, b) {
|
||||
var a = b;
|
||||
return typeof a;
|
||||
}
|
||||
console.log(f([]), g([]), h([]));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var a;
|
||||
return typeof a;
|
||||
}
|
||||
function g() {
|
||||
return"number";
|
||||
}
|
||||
function h(a, b) {
|
||||
var a = b;
|
||||
return typeof a;
|
||||
}
|
||||
console.log(f([]), g([]), h([]));
|
||||
}
|
||||
expect_stdout: "object number undefined"
|
||||
}
|
||||
|
||||
redefine_farg_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var a;
|
||||
return typeof a;
|
||||
}
|
||||
function g(a) {
|
||||
var a = 42;
|
||||
return typeof a;
|
||||
}
|
||||
function h(a, b) {
|
||||
var a = b;
|
||||
return typeof a;
|
||||
}
|
||||
console.log(f([]), g([]), h([]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
var a;
|
||||
return typeof a;
|
||||
}([]), function() {
|
||||
return "number";
|
||||
}(),function(a, b) {
|
||||
var a = b;
|
||||
return typeof a;
|
||||
}([]));
|
||||
}
|
||||
expect_stdout: "object number undefined"
|
||||
}
|
||||
|
||||
redefine_farg_3: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var a;
|
||||
return typeof a;
|
||||
}
|
||||
function g(a) {
|
||||
var a = 42;
|
||||
return typeof a;
|
||||
}
|
||||
function h(a, b) {
|
||||
var a = b;
|
||||
return typeof a;
|
||||
}
|
||||
console.log(f([]), g([]), h([]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
var a;
|
||||
return typeof a;
|
||||
}([]), "number", function(a) {
|
||||
var a = void 0;
|
||||
return typeof a;
|
||||
}([]));
|
||||
}
|
||||
expect_stdout: "object number undefined"
|
||||
}
|
||||
|
||||
delay_def: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
return a;
|
||||
var a;
|
||||
}
|
||||
function g() {
|
||||
return a;
|
||||
var a = 1;
|
||||
}
|
||||
console.log(f(), g());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
return a;
|
||||
var a;
|
||||
}
|
||||
function g() {
|
||||
return a;
|
||||
var a = 1;
|
||||
}
|
||||
console.log(f(), g());
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user