Compare commits
16 Commits
harmony-v3
...
harmony-v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873755b35c | ||
|
|
744032755d | ||
|
|
4fac8076b8 | ||
|
|
6920e898d1 | ||
|
|
dd71639264 | ||
|
|
2dcc552ce0 | ||
|
|
a020d2ead3 | ||
|
|
68645b28d3 | ||
|
|
aaa8212837 | ||
|
|
bd84007cf4 | ||
|
|
55387e8fd0 | ||
|
|
1241600013 | ||
|
|
7e3e9da860 | ||
|
|
a784717fe2 | ||
|
|
00f509405b | ||
|
|
e8235657e4 |
@@ -631,6 +631,13 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `unsafe_math` (default: false) -- optimize numerical expressions like
|
- `unsafe_math` (default: false) -- optimize numerical expressions like
|
||||||
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
||||||
|
|
||||||
|
- `unsafe_methods` (default: false) -- Converts `{ m: function(){} }` to
|
||||||
|
`{ m(){} }`. `ecma` must be set to `6` or greater to enable this transform.
|
||||||
|
If `unsafe_methods` is a RegExp then key/value pairs with keys matching the
|
||||||
|
RegExp will be converted to concise methods.
|
||||||
|
Note: if enabled there is a risk of getting a "`<method name>` is not a
|
||||||
|
constructor" TypeError should any code try to `new` the former function.
|
||||||
|
|
||||||
- `unsafe_proto` (default: false) -- optimize expressions like
|
- `unsafe_proto` (default: false) -- optimize expressions like
|
||||||
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
||||||
|
|
||||||
|
|||||||
@@ -134,11 +134,10 @@ var AST_Debugger = DEFNODE("Debugger", null, {
|
|||||||
$documentation: "Represents a debugger statement",
|
$documentation: "Represents a debugger statement",
|
||||||
}, AST_Statement);
|
}, AST_Statement);
|
||||||
|
|
||||||
var AST_Directive = DEFNODE("Directive", "value scope quote", {
|
var AST_Directive = DEFNODE("Directive", "value quote", {
|
||||||
$documentation: "Represents a directive, like \"use strict\";",
|
$documentation: "Represents a directive, like \"use strict\";",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
|
value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
|
||||||
scope: "[AST_Scope/S] The scope that this directive affects",
|
|
||||||
quote: "[string] the original quote character"
|
quote: "[string] the original quote character"
|
||||||
},
|
},
|
||||||
}, AST_Statement);
|
}, AST_Statement);
|
||||||
@@ -303,10 +302,9 @@ var AST_With = DEFNODE("With", "expression", {
|
|||||||
|
|
||||||
/* -----[ scope and functions ]----- */
|
/* -----[ scope and functions ]----- */
|
||||||
|
|
||||||
var AST_Scope = DEFNODE("Scope", "directives variables functions uses_with uses_eval parent_scope enclosed cname", {
|
var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent_scope enclosed cname", {
|
||||||
$documentation: "Base class for all statements introducing a lexical scope",
|
$documentation: "Base class for all statements introducing a lexical scope",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
directives: "[string*/S] an array of directives declared in this scope",
|
|
||||||
variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
|
variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
|
||||||
functions: "[Object/S] like `variables`, but only lists function declarations",
|
functions: "[Object/S] like `variables`, but only lists function declarations",
|
||||||
uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
|
uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ function Compressor(options, false_by_default) {
|
|||||||
unsafe_comps : false,
|
unsafe_comps : false,
|
||||||
unsafe_Func : false,
|
unsafe_Func : false,
|
||||||
unsafe_math : false,
|
unsafe_math : false,
|
||||||
|
unsafe_methods: false,
|
||||||
unsafe_proto : false,
|
unsafe_proto : false,
|
||||||
unsafe_regexp : false,
|
unsafe_regexp : false,
|
||||||
unused : !false_by_default,
|
unused : !false_by_default,
|
||||||
@@ -289,6 +290,10 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan) {
|
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan) {
|
||||||
var reduce_vars = rescan && compressor.option("reduce_vars");
|
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 safe_ids = Object.create(null);
|
||||||
var suppressor = new TreeWalker(function(node) {
|
var suppressor = new TreeWalker(function(node) {
|
||||||
if (!(node instanceof AST_Symbol)) return;
|
if (!(node instanceof AST_Symbol)) return;
|
||||||
@@ -404,10 +409,9 @@ merge(Compressor.prototype, {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Accessor) {
|
if (node instanceof AST_Accessor) {
|
||||||
var save_ids = safe_ids;
|
push();
|
||||||
safe_ids = Object.create(null);
|
|
||||||
descend();
|
descend();
|
||||||
safe_ids = save_ids;
|
pop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Binary
|
if (node instanceof AST_Binary
|
||||||
@@ -874,7 +878,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function has_overlapping_symbol(fn, arg) {
|
function has_overlapping_symbol(fn, arg, fn_strict) {
|
||||||
var found = false, scan_this = !(fn instanceof AST_Arrow);
|
var found = false, scan_this = !(fn instanceof AST_Arrow);
|
||||||
arg.walk(new TreeWalker(function(node, descend) {
|
arg.walk(new TreeWalker(function(node, descend) {
|
||||||
if (found) return true;
|
if (found) return true;
|
||||||
@@ -885,7 +889,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return found = true;
|
return found = true;
|
||||||
}
|
}
|
||||||
if (scan_this && node instanceof AST_This) {
|
if ((fn_strict || scan_this) && node instanceof AST_This) {
|
||||||
return found = true;
|
return found = true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {
|
if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {
|
||||||
@@ -910,6 +914,8 @@ merge(Compressor.prototype, {
|
|||||||
&& all(iife.args, function(arg) {
|
&& all(iife.args, function(arg) {
|
||||||
return !(arg instanceof AST_Expansion);
|
return !(arg instanceof AST_Expansion);
|
||||||
})) {
|
})) {
|
||||||
|
var fn_strict = compressor.has_directive("use strict");
|
||||||
|
if (fn_strict && fn.body.indexOf(fn_strict) < 0) fn_strict = false;
|
||||||
var names = Object.create(null);
|
var names = Object.create(null);
|
||||||
for (var i = fn.argnames.length; --i >= 0;) {
|
for (var i = fn.argnames.length; --i >= 0;) {
|
||||||
var sym = fn.argnames[i];
|
var sym = fn.argnames[i];
|
||||||
@@ -918,7 +924,7 @@ merge(Compressor.prototype, {
|
|||||||
if (sym instanceof AST_Expansion) {
|
if (sym instanceof AST_Expansion) {
|
||||||
var elements = iife.args.slice(i);
|
var elements = iife.args.slice(i);
|
||||||
if (all(elements, function(arg) {
|
if (all(elements, function(arg) {
|
||||||
return !has_overlapping_symbol(fn, arg);
|
return !has_overlapping_symbol(fn, arg, fn_strict);
|
||||||
})) {
|
})) {
|
||||||
candidates.unshift(make_node(AST_VarDef, sym, {
|
candidates.unshift(make_node(AST_VarDef, sym, {
|
||||||
name: sym.expression,
|
name: sym.expression,
|
||||||
@@ -930,7 +936,7 @@ merge(Compressor.prototype, {
|
|||||||
} else {
|
} else {
|
||||||
var arg = iife.args[i];
|
var arg = iife.args[i];
|
||||||
if (!arg) arg = make_node(AST_Undefined, sym).transform(compressor);
|
if (!arg) arg = make_node(AST_Undefined, sym).transform(compressor);
|
||||||
else if (has_overlapping_symbol(fn, arg)) arg = null;
|
else if (has_overlapping_symbol(fn, arg, fn_strict)) arg = null;
|
||||||
if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
|
if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
|
||||||
name: sym,
|
name: sym,
|
||||||
value: arg
|
value: arg
|
||||||
@@ -4866,7 +4872,10 @@ merge(Compressor.prototype, {
|
|||||||
// p:async function(){} ---> async p(){}
|
// p:async function(){} ---> async p(){}
|
||||||
// p:()=>{} ---> p(){}
|
// p:()=>{} ---> p(){}
|
||||||
// p:async()=>{} ---> async p(){}
|
// p:async()=>{} ---> async p(){}
|
||||||
if (compressor.option("ecma") >= 6) {
|
var unsafe_methods = compressor.option("unsafe_methods");
|
||||||
|
if (unsafe_methods
|
||||||
|
&& compressor.option("ecma") >= 6
|
||||||
|
&& (!(unsafe_methods instanceof RegExp) || unsafe_methods.test(self.key + ""))) {
|
||||||
var key = self.key;
|
var key = self.key;
|
||||||
var value = self.value;
|
var value = self.value;
|
||||||
var is_arrow_with_block = value instanceof AST_Arrow
|
var is_arrow_with_block = value instanceof AST_Arrow
|
||||||
|
|||||||
@@ -506,13 +506,17 @@ function OutputStream(options) {
|
|||||||
nodetype.DEFMETHOD("_codegen", generator);
|
nodetype.DEFMETHOD("_codegen", generator);
|
||||||
};
|
};
|
||||||
|
|
||||||
var use_asm = false;
|
|
||||||
var in_directive = false;
|
var in_directive = false;
|
||||||
|
var active_scope = null;
|
||||||
|
var use_asm = null;
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("print", function(stream, force_parens){
|
AST_Node.DEFMETHOD("print", function(stream, force_parens){
|
||||||
var self = this, generator = self._codegen, prev_use_asm = use_asm;
|
var self = this, generator = self._codegen;
|
||||||
if (self instanceof AST_Directive && self.value == "use asm" && stream.parent() instanceof AST_Scope) {
|
if (self instanceof AST_Scope) {
|
||||||
use_asm = true;
|
active_scope = self;
|
||||||
|
}
|
||||||
|
else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
||||||
|
use_asm = active_scope;
|
||||||
}
|
}
|
||||||
function doit() {
|
function doit() {
|
||||||
self.add_comments(stream);
|
self.add_comments(stream);
|
||||||
@@ -526,8 +530,8 @@ function OutputStream(options) {
|
|||||||
doit();
|
doit();
|
||||||
}
|
}
|
||||||
stream.pop_node();
|
stream.pop_node();
|
||||||
if (self instanceof AST_Scope) {
|
if (self === use_asm) {
|
||||||
use_asm = prev_use_asm;
|
use_asm = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
||||||
|
|||||||
28
lib/parse.js
28
lib/parse.js
@@ -44,9 +44,9 @@
|
|||||||
|
|
||||||
"use strict";
|
"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 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';
|
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case yield await';
|
||||||
|
|
||||||
KEYWORDS = makePredicate(KEYWORDS);
|
KEYWORDS = makePredicate(KEYWORDS);
|
||||||
@@ -1013,6 +1013,12 @@ function parse($TEXT, options) {
|
|||||||
next();
|
next();
|
||||||
return function_(AST_Defun, false, true);
|
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", ":")
|
return is_token(peek(), "punc", ":")
|
||||||
? labeled_statement()
|
? labeled_statement()
|
||||||
: simple_statement();
|
: simple_statement();
|
||||||
@@ -1149,15 +1155,11 @@ function parse($TEXT, options) {
|
|||||||
body : statement()
|
body : statement()
|
||||||
});
|
});
|
||||||
|
|
||||||
case "import":
|
|
||||||
next();
|
|
||||||
var node = import_();
|
|
||||||
semicolon();
|
|
||||||
return node;
|
|
||||||
|
|
||||||
case "export":
|
case "export":
|
||||||
next();
|
if (!is_token(peek(), "punc", "(")) {
|
||||||
return export_();
|
next();
|
||||||
|
return export_();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unexpected();
|
unexpected();
|
||||||
@@ -1320,6 +1322,9 @@ function parse($TEXT, options) {
|
|||||||
if (in_statement && !name)
|
if (in_statement && !name)
|
||||||
unexpected();
|
unexpected();
|
||||||
|
|
||||||
|
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||||
|
unexpected(prev());
|
||||||
|
|
||||||
var args = parameters();
|
var args = parameters();
|
||||||
var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
|
var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
|
||||||
return new ctor({
|
return new ctor({
|
||||||
@@ -1875,7 +1880,8 @@ function parse($TEXT, options) {
|
|||||||
: !no_in && kind === "const" && S.input.has_directive("use strict")
|
: !no_in && kind === "const" && S.input.has_directive("use strict")
|
||||||
? croak("Missing initializer in const declaration") : null,
|
? croak("Missing initializer in const declaration") : null,
|
||||||
end : prev()
|
end : prev()
|
||||||
})
|
});
|
||||||
|
if (def.name.name == "import") croak("Unexpected token: import");
|
||||||
}
|
}
|
||||||
a.push(def);
|
a.push(def);
|
||||||
if (!is("punc", ","))
|
if (!is("punc", ","))
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
var mangle_with_block_scope =
|
var mangle_with_block_scope =
|
||||||
(!options.ie8 && node instanceof AST_SymbolCatch) ||
|
(!options.ie8 && node instanceof AST_SymbolCatch) ||
|
||||||
node instanceof AST_SymbolBlockDeclaration;
|
node instanceof AST_SymbolBlockDeclaration;
|
||||||
if (mangle_with_block_scope) {
|
if (mangle_with_block_scope && options.reserved.indexOf(node.name) < 0) {
|
||||||
to_mangle.push(node.definition());
|
to_mangle.push(node.definition());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.1.1",
|
"version": "3.1.3",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -290,6 +290,7 @@ issue_2105_1: {
|
|||||||
passes: 3,
|
passes: 3,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
unsafe_methods: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -104,3 +104,65 @@ asm_mixed: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asm_toplevel: {
|
||||||
|
options = {}
|
||||||
|
input: {
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
function f() {
|
||||||
|
0.0;
|
||||||
|
(function(){
|
||||||
|
0.0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
expect_exact: '"use asm";0.0;function f(){0.0;(function(){0.0})}0.0;'
|
||||||
|
}
|
||||||
|
|
||||||
|
asm_function_expression: {
|
||||||
|
options = {}
|
||||||
|
input: {
|
||||||
|
0.0;
|
||||||
|
var a = function() {
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
function f() {
|
||||||
|
0.0;
|
||||||
|
return function(){
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
expect_exact: '0;var a=function(){"use asm";0.0};function f(){0;return function(){"use asm";0.0};0}0;'
|
||||||
|
}
|
||||||
|
|
||||||
|
asm_nested_functions: {
|
||||||
|
options = {}
|
||||||
|
input: {
|
||||||
|
0.0;
|
||||||
|
function a() {
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
function b() {
|
||||||
|
0.0;
|
||||||
|
function c(){
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
function d(){
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
||||||
|
}
|
||||||
|
|||||||
@@ -2725,3 +2725,73 @@ issue_2313_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2319_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return a;
|
||||||
|
}(!function() {
|
||||||
|
return this;
|
||||||
|
}()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return !function() {
|
||||||
|
return this;
|
||||||
|
}();
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2319_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
"use strict";
|
||||||
|
return a;
|
||||||
|
}(!function() {
|
||||||
|
return this;
|
||||||
|
}()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
"use strict";
|
||||||
|
return a;
|
||||||
|
}(!function() {
|
||||||
|
return this;
|
||||||
|
}()));
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2319_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function(a) {
|
||||||
|
return a;
|
||||||
|
}(!function() {
|
||||||
|
return this;
|
||||||
|
}()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function(a) {
|
||||||
|
return !function() {
|
||||||
|
return this;
|
||||||
|
}();
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|||||||
@@ -226,3 +226,27 @@ keyword_valid_3: {
|
|||||||
export { default as default } from "module.js";
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -804,3 +804,38 @@ object_spread_of_sequence: {
|
|||||||
console.log({ ...o || o });
|
console.log({ ...o || o });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue 2316
|
||||||
|
class_name_can_be_preserved_with_reserved: {
|
||||||
|
mangle = {
|
||||||
|
reserved: [ "Foo" ],
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function x() {
|
||||||
|
class Foo {}
|
||||||
|
Foo.bar;
|
||||||
|
class Bar {}
|
||||||
|
Bar.foo;
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
var Foo = class Foo {};
|
||||||
|
Foo.bar;
|
||||||
|
var Bar = class Bar {};
|
||||||
|
Bar.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x() {
|
||||||
|
class Foo {}
|
||||||
|
Foo.bar;
|
||||||
|
class a {}
|
||||||
|
a.foo;
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
var Foo = class Foo {};
|
||||||
|
Foo.bar;
|
||||||
|
var a = class a {};
|
||||||
|
a.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -516,6 +516,7 @@ variable_as_computed_property: {
|
|||||||
prop_func_to_concise_method: {
|
prop_func_to_concise_method: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
({
|
({
|
||||||
@@ -544,6 +545,7 @@ prop_func_to_concise_method: {
|
|||||||
prop_arrow_to_concise_method: {
|
prop_arrow_to_concise_method: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
({
|
({
|
||||||
@@ -592,6 +594,7 @@ concise_method_to_prop_arrow: {
|
|||||||
prop_func_to_async_concise_method: {
|
prop_func_to_async_concise_method: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 8,
|
ecma: 8,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
({
|
({
|
||||||
@@ -614,6 +617,7 @@ prop_func_to_async_concise_method: {
|
|||||||
prop_func_to_concise_method_various: {
|
prop_func_to_concise_method_various: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
({
|
({
|
||||||
@@ -646,6 +650,7 @@ prop_func_to_concise_method_various: {
|
|||||||
prop_arrows_to_concise_method_various: {
|
prop_arrows_to_concise_method_various: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
({
|
({
|
||||||
@@ -674,6 +679,7 @@ prop_arrows_to_concise_method_various: {
|
|||||||
prop_arrow_with_this: {
|
prop_arrow_with_this: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function run(arg) {
|
function run(arg) {
|
||||||
@@ -711,6 +717,7 @@ prop_arrow_with_this: {
|
|||||||
prop_arrow_with_nested_this: {
|
prop_arrow_with_nested_this: {
|
||||||
options = {
|
options = {
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function run(arg) {
|
function run(arg) {
|
||||||
|
|||||||
@@ -887,6 +887,7 @@ methods_keep_quoted_true: {
|
|||||||
options = {
|
options = {
|
||||||
arrows: true,
|
arrows: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
@@ -906,6 +907,7 @@ methods_keep_quoted_false: {
|
|||||||
options = {
|
options = {
|
||||||
arrows: true,
|
arrows: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
@@ -931,6 +933,7 @@ methods_keep_quoted_from_dead_code: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
unsafe_methods: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
@@ -964,3 +967,88 @@ issue_2256: {
|
|||||||
g.keep = g.g;
|
g.keep = g.g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2321: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = {
|
||||||
|
foo: function(){ console.log("foo") },
|
||||||
|
bar() { console.log("bar") }
|
||||||
|
};
|
||||||
|
var foo = new f.foo();
|
||||||
|
var bar = f.bar();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = {
|
||||||
|
foo: function() {
|
||||||
|
console.log("foo");
|
||||||
|
},
|
||||||
|
bar() {
|
||||||
|
console.log("bar");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var foo = new f.foo();
|
||||||
|
var bar = f.bar();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_methods_regex: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: /^[A-Z1]/,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = {
|
||||||
|
123: function(){ console.log("123") },
|
||||||
|
foo: function(){ console.log("foo") },
|
||||||
|
bar() { console.log("bar") },
|
||||||
|
Baz: function(){ console.log("baz") },
|
||||||
|
BOO: function(){ console.log("boo") },
|
||||||
|
null: function(){ console.log("null") },
|
||||||
|
undefined: function(){ console.log("undefined") },
|
||||||
|
};
|
||||||
|
f[123]();
|
||||||
|
new f.foo();
|
||||||
|
f.bar();
|
||||||
|
f.Baz();
|
||||||
|
f.BOO();
|
||||||
|
new f.null();
|
||||||
|
new f.undefined();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = {
|
||||||
|
123() { console.log("123") },
|
||||||
|
foo: function(){ console.log("foo") },
|
||||||
|
bar() { console.log("bar"); },
|
||||||
|
Baz() { console.log("baz") },
|
||||||
|
BOO() { console.log("boo") },
|
||||||
|
null: function(){ console.log("null") },
|
||||||
|
undefined: function(){ console.log("undefined") },
|
||||||
|
};
|
||||||
|
f[123]();
|
||||||
|
new f.foo();
|
||||||
|
f.bar();
|
||||||
|
f.Baz();
|
||||||
|
f.BOO();
|
||||||
|
new f.null();
|
||||||
|
new f.undefined();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"123",
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
"boo",
|
||||||
|
"null",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
@@ -2549,7 +2549,7 @@ issue_1922_2: {
|
|||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
accessor: {
|
accessor_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -2578,6 +2578,89 @@ accessor: {
|
|||||||
expect_stdout: "1 1"
|
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: {
|
issue_2090_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../node");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Export", function() {
|
describe("Export/Import", function() {
|
||||||
it("Should parse export directives", function() {
|
it("Should parse export directives", function() {
|
||||||
var inputs = [
|
var inputs = [
|
||||||
['export * from "a.js"', ['*'], "a.js"],
|
['export * from "a.js"', ['*'], "a.js"],
|
||||||
@@ -36,4 +36,22 @@ describe("Export", function() {
|
|||||||
assert.equal(st.module_name.value, filename);
|
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));
|
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() {
|
describe("keep_quoted_props", function() {
|
||||||
it("Should preserve quotes in object literals", function() {
|
it("Should preserve quotes in object literals", function() {
|
||||||
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
|
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
|
||||||
|
|||||||
Reference in New Issue
Block a user