@@ -9347,7 +9347,7 @@ Compressor.prototype.compress = function(node) {
|
|||||||
return !same_scope(def) || may_overlap(compressor, def);
|
return !same_scope(def) || may_overlap(compressor, def);
|
||||||
}
|
}
|
||||||
}, true)) {
|
}, true)) {
|
||||||
self.init = to_var(self.init);
|
self.init = to_var(self.init, self.resolve());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -10161,14 +10161,13 @@ Compressor.prototype.compress = function(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function to_var(stat) {
|
function to_var(stat, scope) {
|
||||||
return make_node(AST_Var, stat, {
|
return make_node(AST_Var, stat, {
|
||||||
definitions: stat.definitions.map(function(defn) {
|
definitions: stat.definitions.map(function(defn) {
|
||||||
return make_node(AST_VarDef, defn, {
|
return make_node(AST_VarDef, defn, {
|
||||||
name: defn.name.convert_symbol(AST_SymbolVar, function(name, node) {
|
name: defn.name.convert_symbol(AST_SymbolVar, function(name, node) {
|
||||||
var def = name.definition();
|
var def = name.definition();
|
||||||
def.orig[def.orig.indexOf(node)] = name;
|
def.orig[def.orig.indexOf(node)] = name;
|
||||||
var scope = def.scope.resolve();
|
|
||||||
if (def.scope === scope) return;
|
if (def.scope === scope) return;
|
||||||
def.scope = scope;
|
def.scope = scope;
|
||||||
scope.variables.set(def.name, def);
|
scope.variables.set(def.name, def);
|
||||||
@@ -10194,7 +10193,7 @@ Compressor.prototype.compress = function(node) {
|
|||||||
return !defn.name.match_symbol(function(node) {
|
return !defn.name.match_symbol(function(node) {
|
||||||
if (node instanceof AST_SymbolDeclaration) return !can_varify(compressor, node);
|
if (node instanceof AST_SymbolDeclaration) return !can_varify(compressor, node);
|
||||||
}, true);
|
}, true);
|
||||||
}) ? to_var(self) : self;
|
}) ? to_var(self, compressor.find_parent(AST_Scope)) : self;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPT(AST_Const, varify);
|
OPT(AST_Const, varify);
|
||||||
|
|||||||
@@ -682,3 +682,165 @@ issue_5516: {
|
|||||||
expect_stdout: "function"
|
expect_stdout: "function"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5697_1: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
varify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
f();
|
||||||
|
return typeof a;
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
const a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
var a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5697_2: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
varify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function() {
|
||||||
|
f();
|
||||||
|
return typeof a;
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
let a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
var a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5697_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
varify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
f();
|
||||||
|
return typeof a;
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
const a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
var a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5697_4: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
varify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function() {
|
||||||
|
f();
|
||||||
|
return typeof a;
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
let a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function() {
|
||||||
|
(function() {
|
||||||
|
for (var k in { foo: 42 }) {
|
||||||
|
var a = k;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user