Compare commits
7 Commits
harmony-v3
...
harmony-v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873755b35c | ||
|
|
744032755d | ||
|
|
4fac8076b8 | ||
|
|
6920e898d1 | ||
|
|
dd71639264 | ||
|
|
2dcc552ce0 | ||
|
|
a020d2ead3 |
@@ -290,6 +290,10 @@ merge(Compressor.prototype, {
|
||||
|
||||
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan) {
|
||||
var reduce_vars = rescan && compressor.option("reduce_vars");
|
||||
// Stack of look-up tables to keep track of whether a `SymbolDef` has been
|
||||
// properly assigned before use:
|
||||
// - `push()` & `pop()` when visiting conditional branches
|
||||
// - backup & restore via `save_ids` when visiting out-of-order sections
|
||||
var safe_ids = Object.create(null);
|
||||
var suppressor = new TreeWalker(function(node) {
|
||||
if (!(node instanceof AST_Symbol)) return;
|
||||
@@ -405,10 +409,9 @@ merge(Compressor.prototype, {
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Accessor) {
|
||||
var save_ids = safe_ids;
|
||||
safe_ids = Object.create(null);
|
||||
push();
|
||||
descend();
|
||||
safe_ids = save_ids;
|
||||
pop();
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Binary
|
||||
|
||||
28
lib/parse.js
28
lib/parse.js
@@ -44,9 +44,9 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var KEYWORDS = 'break case catch class const continue debugger default delete do else export extends finally for function if in instanceof new return switch throw try typeof var let void while with import';
|
||||
var KEYWORDS = 'break case catch class const continue debugger default delete do else export extends finally for function if in instanceof let new return switch throw try typeof var void while with';
|
||||
var KEYWORDS_ATOM = 'false null true';
|
||||
var RESERVED_WORDS = 'enum implements interface package private protected public static super this ' + KEYWORDS_ATOM + " " + KEYWORDS;
|
||||
var RESERVED_WORDS = 'enum implements import interface package private protected public static super this ' + KEYWORDS_ATOM + " " + KEYWORDS;
|
||||
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case yield await';
|
||||
|
||||
KEYWORDS = makePredicate(KEYWORDS);
|
||||
@@ -1013,6 +1013,12 @@ function parse($TEXT, options) {
|
||||
next();
|
||||
return function_(AST_Defun, false, true);
|
||||
}
|
||||
if (S.token.value == "import" && !is_token(peek(), "punc", "(")) {
|
||||
next();
|
||||
var node = import_();
|
||||
semicolon();
|
||||
return node;
|
||||
}
|
||||
return is_token(peek(), "punc", ":")
|
||||
? labeled_statement()
|
||||
: simple_statement();
|
||||
@@ -1149,15 +1155,11 @@ function parse($TEXT, options) {
|
||||
body : statement()
|
||||
});
|
||||
|
||||
case "import":
|
||||
next();
|
||||
var node = import_();
|
||||
semicolon();
|
||||
return node;
|
||||
|
||||
case "export":
|
||||
next();
|
||||
return export_();
|
||||
if (!is_token(peek(), "punc", "(")) {
|
||||
next();
|
||||
return export_();
|
||||
}
|
||||
}
|
||||
}
|
||||
unexpected();
|
||||
@@ -1320,6 +1322,9 @@ function parse($TEXT, options) {
|
||||
if (in_statement && !name)
|
||||
unexpected();
|
||||
|
||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||
unexpected(prev());
|
||||
|
||||
var args = parameters();
|
||||
var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
|
||||
return new ctor({
|
||||
@@ -1875,7 +1880,8 @@ function parse($TEXT, options) {
|
||||
: !no_in && kind === "const" && S.input.has_directive("use strict")
|
||||
? croak("Missing initializer in const declaration") : null,
|
||||
end : prev()
|
||||
})
|
||||
});
|
||||
if (def.name.name == "import") croak("Unexpected token: import");
|
||||
}
|
||||
a.push(def);
|
||||
if (!is("punc", ","))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.3",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -226,3 +226,27 @@ keyword_valid_3: {
|
||||
export { default as default } from "module.js";
|
||||
}
|
||||
}
|
||||
|
||||
dynamic_import: {
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
import traditional from './traditional.js';
|
||||
function imp(x) {
|
||||
return import(x);
|
||||
}
|
||||
import("module_for_side_effects.js");
|
||||
let dynamic = import("some/module.js");
|
||||
dynamic.foo();
|
||||
}
|
||||
expect: {
|
||||
import o from "./traditional.js";
|
||||
function t(o) {
|
||||
return import(o);
|
||||
}
|
||||
import("module_for_side_effects.js");
|
||||
let r = import("some/module.js");
|
||||
r.foo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2549,7 +2549,7 @@ issue_1922_2: {
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
accessor: {
|
||||
accessor_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
@@ -2578,6 +2578,89 @@ accessor: {
|
||||
expect_stdout: "1 1"
|
||||
}
|
||||
|
||||
accessor_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var A = 1;
|
||||
var B = {
|
||||
get c() {
|
||||
console.log(A);
|
||||
}
|
||||
};
|
||||
B.c;
|
||||
}
|
||||
expect: {
|
||||
({
|
||||
get c() {
|
||||
console.log(1);
|
||||
}
|
||||
}).c;
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
method_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1;
|
||||
console.log(new class {
|
||||
a() {
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
}().a(), a);
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
console.log(new class {
|
||||
a() {
|
||||
a = 2;
|
||||
return a;
|
||||
}
|
||||
}().a(), a);
|
||||
}
|
||||
expect_stdout: "2 2"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
method_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var A = 1;
|
||||
var B = class {
|
||||
c() {
|
||||
console.log(A);
|
||||
}
|
||||
};
|
||||
new B().c();
|
||||
}
|
||||
expect: {
|
||||
new class {
|
||||
c() {
|
||||
console.log(1);
|
||||
}
|
||||
}().c();
|
||||
}
|
||||
expect_stdout: "1"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_2090_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var assert = require("assert");
|
||||
var uglify = require("../node");
|
||||
|
||||
describe("Export", function() {
|
||||
describe("Export/Import", function() {
|
||||
it("Should parse export directives", function() {
|
||||
var inputs = [
|
||||
['export * from "a.js"', ['*'], "a.js"],
|
||||
@@ -36,4 +36,22 @@ describe("Export", function() {
|
||||
assert.equal(st.module_name.value, filename);
|
||||
}
|
||||
});
|
||||
|
||||
it("Should not parse invalid uses of export", function() {
|
||||
assert.equal(uglify.minify("export").error.message, "Unexpected token: eof (undefined)");
|
||||
assert.equal(uglify.minify("export;").error.message, "Unexpected token: punc (;)");
|
||||
assert.equal(uglify.minify("export();").error.message, "Unexpected token: keyword (export)");
|
||||
assert.equal(uglify.minify("export(1);").error.message, "Unexpected token: keyword (export)");
|
||||
assert.equal(uglify.minify("var export;").error.message, "Name expected");
|
||||
assert.equal(uglify.minify("var export = 1;").error.message, "Name expected");
|
||||
assert.equal(uglify.minify("function f(export){}").error.message, "Invalid function parameter");
|
||||
});
|
||||
|
||||
it("Should not parse invalid uses of import", function() {
|
||||
assert.equal(uglify.minify("import").error.message, "Unexpected token: eof (undefined)");
|
||||
assert.equal(uglify.minify("import;").error.message, "Unexpected token: punc (;)");
|
||||
assert.equal(uglify.minify("var import;").error.message, "Unexpected token: import");
|
||||
assert.equal(uglify.minify("var import = 1;").error.message, "Unexpected token: import");
|
||||
assert.equal(uglify.minify("function f(import){}").error.message, "Unexpected token: name (import)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -73,6 +73,13 @@ describe("minify", function() {
|
||||
assert.strictEqual(run_code(compressed), run_code(original));
|
||||
});
|
||||
|
||||
it("should not parse invalid use of reserved words", function() {
|
||||
assert.strictEqual(Uglify.minify("function enum(){}").error, undefined);
|
||||
assert.strictEqual(Uglify.minify("function static(){}").error, undefined);
|
||||
assert.strictEqual(Uglify.minify("function super(){}").error.message, "Unexpected token: name (super)");
|
||||
assert.strictEqual(Uglify.minify("function this(){}").error.message, "Unexpected token: name (this)");
|
||||
});
|
||||
|
||||
describe("keep_quoted_props", function() {
|
||||
it("Should preserve quotes in object literals", function() {
|
||||
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
|
||||
|
||||
Reference in New Issue
Block a user