@@ -1127,6 +1127,9 @@ merge(Compressor.prototype, {
|
|||||||
def(AST_SymbolCatch, function() {
|
def(AST_SymbolCatch, function() {
|
||||||
this.definition().fixed = false;
|
this.definition().fixed = false;
|
||||||
});
|
});
|
||||||
|
def(AST_SymbolImport, function() {
|
||||||
|
this.definition().fixed = false;
|
||||||
|
});
|
||||||
def(AST_SymbolRef, function(tw, descend, compressor) {
|
def(AST_SymbolRef, function(tw, descend, compressor) {
|
||||||
var d = this.definition();
|
var d = this.definition();
|
||||||
push_ref(d, this);
|
push_ref(d, this);
|
||||||
@@ -5836,6 +5839,14 @@ merge(Compressor.prototype, {
|
|||||||
assignments.add(def.id, node);
|
assignments.add(def.id, node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (node instanceof AST_SymbolImport) {
|
||||||
|
var def = node.definition();
|
||||||
|
if (!(def.id in in_use_ids) && (!drop_vars || !is_safe_lexical(def))) {
|
||||||
|
in_use_ids[def.id] = true;
|
||||||
|
in_use.push(def);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} else if (node instanceof AST_This && scope instanceof AST_DefClass) {
|
} else if (node instanceof AST_This && scope instanceof AST_DefClass) {
|
||||||
var def = scope.name.definition();
|
var def = scope.name.definition();
|
||||||
if (!(def.id in in_use_ids)) {
|
if (!(def.id in in_use_ids)) {
|
||||||
|
|||||||
@@ -165,3 +165,38 @@ forbid_merge: {
|
|||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4708_1: {
|
||||||
|
options = {
|
||||||
|
imports: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
import a from "foo";
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
import a from "foo";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_4708_2: {
|
||||||
|
options = {
|
||||||
|
imports: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
console.log(a);
|
||||||
|
import a from "foo";
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
console.log(a);
|
||||||
|
import a from "foo";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ exports.patch_module_statements = function(code) {
|
|||||||
symbols = symbols.replace(/[{}]/g, "").trim().replace(/\s*,\s*/g, ",");
|
symbols = symbols.replace(/[{}]/g, "").trim().replace(/\s*,\s*/g, ",");
|
||||||
symbols = symbols.replace(/\*/, '"*"').replace(/\bas\s+(?!$|,|as\s)/g, ":");
|
symbols = symbols.replace(/\*/, '"*"').replace(/\bas\s+(?!$|,|as\s)/g, ":");
|
||||||
imports.push([
|
imports.push([
|
||||||
"var {",
|
"const {",
|
||||||
symbols,
|
symbols,
|
||||||
"} = new Proxy(Object.create(null), { get(_, value) { return { value }; } });",
|
"} = new Proxy(Object.create(null), { get(_, value) { return { value }; } });",
|
||||||
].join(""));
|
].join(""));
|
||||||
|
|||||||
@@ -1020,22 +1020,30 @@ function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn
|
|||||||
return "switch (" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") { " + createSwitchParts(recurmax, 4, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "}";
|
return "switch (" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") { " + createSwitchParts(recurmax, 4, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + "}";
|
||||||
case STMT_VAR:
|
case STMT_VAR:
|
||||||
if (SUPPORT.destructuring && stmtDepth == 1 && rng(5) == 0) {
|
if (SUPPORT.destructuring && stmtDepth == 1 && rng(5) == 0) {
|
||||||
unique_vars.push("c");
|
unique_vars.push("a", "b", "c", "undefined", "NaN", "Infinity");
|
||||||
var s = rng(2) ? " " + createVarName(MANDATORY) : "";
|
var s = "";
|
||||||
|
if (rng(2)) {
|
||||||
|
var name = createVarName(MANDATORY);
|
||||||
|
block_vars.push(name);
|
||||||
|
s += " " + name;
|
||||||
|
}
|
||||||
if (rng(10)) {
|
if (rng(10)) {
|
||||||
if (s) s += ",";
|
if (s) s += ",";
|
||||||
if (rng(2)) {
|
if (rng(2)) {
|
||||||
s += " * as " + createVarName(MANDATORY);
|
var name = createVarName(MANDATORY);
|
||||||
|
block_vars.push(name);
|
||||||
|
s += " * as " + name;
|
||||||
} else {
|
} else {
|
||||||
var names = [];
|
var names = [];
|
||||||
for (var i = rng(4); --i >= 0;) {
|
for (var i = rng(4); --i >= 0;) {
|
||||||
var name = createVarName(MANDATORY);
|
var name = createVarName(MANDATORY);
|
||||||
|
block_vars.push(name);
|
||||||
names.push(rng(2) ? getDotKey() + " as " + name : name);
|
names.push(rng(2) ? getDotKey() + " as " + name : name);
|
||||||
}
|
}
|
||||||
s += " { " + names.join(", ") + " }";
|
s += " { " + names.join(", ") + " }";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unique_vars.pop();
|
unique_vars.length -= 6;
|
||||||
if (s) s += " from";
|
if (s) s += " from";
|
||||||
return "import" + s + ' "path/to/module.js";';
|
return "import" + s + ' "path/to/module.js";';
|
||||||
} else if (SUPPORT.destructuring && rng(20) == 0) {
|
} else if (SUPPORT.destructuring && rng(20) == 0) {
|
||||||
@@ -2217,6 +2225,10 @@ function is_error_recursion(ex) {
|
|||||||
return ex.name == "RangeError" && /Invalid string length|Maximum call stack size exceeded/.test(ex.message);
|
return ex.name == "RangeError" && /Invalid string length|Maximum call stack size exceeded/.test(ex.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_error_redeclaration(ex) {
|
||||||
|
return ex.name == "SyntaxError" && /already been declared|redeclaration/.test(ex.message);
|
||||||
|
}
|
||||||
|
|
||||||
function is_error_destructuring(ex) {
|
function is_error_destructuring(ex) {
|
||||||
return ex.name == "TypeError" && /^Cannot destructure /.test(ex.message);
|
return ex.name == "TypeError" && /^Cannot destructure /.test(ex.message);
|
||||||
}
|
}
|
||||||
@@ -2409,6 +2421,10 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
ok = sandbox.same_stdout(original_strict, uglify_strict);
|
ok = sandbox.same_stdout(original_strict, uglify_strict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ignore difference in error message caused by `import` symbol redeclaration
|
||||||
|
if (!ok && errored && /\bimport\b/.test(original_code)) {
|
||||||
|
if (is_error_redeclaration(uglify_result) && is_error_redeclaration(original_result)) ok = true;
|
||||||
|
}
|
||||||
// ignore difference in error message caused by `in`
|
// ignore difference in error message caused by `in`
|
||||||
if (!ok && errored && is_error_in(uglify_result) && is_error_in(original_result)) ok = true;
|
if (!ok && errored && is_error_in(uglify_result) && is_error_in(original_result)) ok = true;
|
||||||
// ignore difference in error message caused by spread syntax
|
// ignore difference in error message caused by spread syntax
|
||||||
|
|||||||
Reference in New Issue
Block a user