Merge branch 'master' into harmony-v3.0.15

This commit is contained in:
alexlamsl
2017-06-01 18:26:09 +08:00
6 changed files with 130 additions and 30 deletions

View File

@@ -691,7 +691,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
where `eval` or `with` are used. where `eval` or `with` are used.
- `safari10` (default `false`). Pass `true` to work around the Safari 10 loop - `safari10` (default `false`). Pass `true` to work around the Safari 10 loop
iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041) iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041)
"Cannot declare a let variable twice". "Cannot declare a let variable twice".
Examples: Examples:

View File

@@ -1718,6 +1718,63 @@ merge(Compressor.prototype, {
} }
throw def; throw def;
}); });
var object_fns = [
'constructor',
'toString',
'valueOf',
];
var native_fns = {
Array: makePredicate([
'indexOf',
'join',
'lastIndexOf',
'slice',
].concat(object_fns)),
Boolean: makePredicate(object_fns),
Number: makePredicate([
'toExponential',
'toFixed',
'toPrecision',
].concat(object_fns)),
RegExp: makePredicate([
'test',
].concat(object_fns)),
String: makePredicate([
'charAt',
'charCodeAt',
'concat',
'indexOf',
'italics',
'lastIndexOf',
'match',
'replace',
'search',
'slice',
'split',
'substr',
'substring',
'trim',
].concat(object_fns)),
};
def(AST_Call, function(compressor){
var exp = this.expression;
if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
var key = exp.property;
if (key instanceof AST_Node) {
key = ev(key, compressor);
}
var val = ev(exp.expression, compressor);
if ((val && native_fns[val.constructor.name] || return_false)(key)) {
return val[key].apply(val, this.args.map(function(arg) {
return ev(arg, compressor);
}));
}
}
throw def;
});
def(AST_New, function(compressor){
throw def;
});
})(function(node, func){ })(function(node, func){
node.DEFMETHOD("_eval", func); node.DEFMETHOD("_eval", func);
}); });
@@ -3312,6 +3369,11 @@ merge(Compressor.prototype, {
&& is_iife_call(self)) { && is_iife_call(self)) {
return self.negate(compressor, true); return self.negate(compressor, true);
} }
var ev = self.evaluate(compressor);
if (ev !== self) {
ev = make_node_from_constant(ev, self).optimize(compressor);
return best_of(compressor, ev, self);
}
return self; return self;
}); });

View File

@@ -1536,7 +1536,8 @@ function OutputStream(options) {
DEFPRINT(AST_NewTarget, function(self, output) { DEFPRINT(AST_NewTarget, function(self, output) {
output.print("new.target"); output.print("new.target");
}); });
AST_ObjectProperty.DEFMETHOD("print_property_name", function(key, quote, output) {
function print_property_name(key, quote, output) {
if (output.option("quote_keys")) { if (output.option("quote_keys")) {
output.print_string(key + ""); output.print_string(key + "");
} else if ((typeof key == "number" } else if ((typeof key == "number"
@@ -1553,7 +1554,8 @@ function OutputStream(options) {
} else { } else {
output.print_string(key, quote); output.print_string(key, quote);
} }
}); }
DEFPRINT(AST_ObjectKeyVal, function(self, output){ DEFPRINT(AST_ObjectKeyVal, function(self, output){
function get_name(self) { function get_name(self) {
var def = self.definition(); var def = self.definition();
@@ -1566,7 +1568,7 @@ function OutputStream(options) {
is_identifier_string(self.key) && is_identifier_string(self.key) &&
get_name(self.value) === self.key get_name(self.value) === self.key
) { ) {
self.print_property_name(self.key, self.quote, output); print_property_name(self.key, self.quote, output);
} else if (allowShortHand && } else if (allowShortHand &&
self.value instanceof AST_DefaultAssign && self.value instanceof AST_DefaultAssign &&
@@ -1574,12 +1576,12 @@ function OutputStream(options) {
is_identifier_string(self.key) && is_identifier_string(self.key) &&
get_name(self.value.left) === self.key get_name(self.value.left) === self.key
) { ) {
self.print_property_name(self.key, self.quote, output); print_property_name(self.key, self.quote, output);
output.print("="); output.print("=");
self.value.right.print(output); self.value.right.print(output);
} else { } else {
if (!(self.key instanceof AST_Node)) { if (!(self.key instanceof AST_Node)) {
self.print_property_name(self.key, self.quote, output); print_property_name(self.key, self.quote, output);
} else { } else {
output.with_square(function() { output.with_square(function() {
self.key.print(output); self.key.print(output);
@@ -1589,15 +1591,18 @@ function OutputStream(options) {
self.value.print(output); self.value.print(output);
} }
}); });
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, self, output) { AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
var self = this;
if (self.static) { if (self.static) {
output.print("static"); output.print("static");
output.space(); output.space();
} }
output.print(type); if (type) {
output.space(); output.print(type);
output.space();
}
if (self.key instanceof AST_SymbolMethod) { if (self.key instanceof AST_SymbolMethod) {
self.print_property_name(self.key.name, self.quote, output); print_property_name(self.key.name, self.quote, output);
} else { } else {
output.with_square(function() { output.with_square(function() {
self.key.print(output); self.key.print(output);
@@ -1606,27 +1611,13 @@ function OutputStream(options) {
self.value._do_print(output, true); self.value._do_print(output, true);
}); });
DEFPRINT(AST_ObjectSetter, function(self, output){ DEFPRINT(AST_ObjectSetter, function(self, output){
self._print_getter_setter("set", self, output); self._print_getter_setter("set", output);
}); });
DEFPRINT(AST_ObjectGetter, function(self, output){ DEFPRINT(AST_ObjectGetter, function(self, output){
self._print_getter_setter("get", self, output); self._print_getter_setter("get", output);
}); });
DEFPRINT(AST_ConciseMethod, function(self, output){ DEFPRINT(AST_ConciseMethod, function(self, output){
if (self.static) { self._print_getter_setter(self.is_generator && "*", output);
output.print("static");
output.space();
}
if (self.is_generator) {
output.print("*");
}
if (self.key instanceof AST_SymbolMethod) {
self.print_property_name(self.key.name, self.quote, output);
} else {
output.with_square(function() {
self.key.print(output);
});
}
self.value._do_print(output, true);
}); });
AST_Symbol.DEFMETHOD("_do_print", function(output){ AST_Symbol.DEFMETHOD("_do_print", function(output){
var def = this.definition(); var def = this.definition();

View File

@@ -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.0.14", "version": "3.0.15",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

View File

@@ -873,13 +873,15 @@ unsafe_charAt_noop: {
input: { input: {
console.log( console.log(
s.charAt(0), s.charAt(0),
"string".charAt(x) "string".charAt(x),
(typeof x).charAt()
); );
} }
expect: { expect: {
console.log( console.log(
s.charAt(0), s.charAt(0),
"string".charAt(x) "string".charAt(x),
(typeof x)[0]
); );
} }
} }
@@ -1130,3 +1132,31 @@ issue_1964_2: {
} }
expect_stdout: "b" expect_stdout: "b"
} }
array_slice_index: {
options = {
evaluate: true,
unsafe: true,
}
input: {
console.log([1,2,3].slice(1)[1]);
}
expect: {
console.log(3);
}
expect_stdout: "3"
}
string_charCodeAt: {
options = {
evaluate: true,
unsafe: true,
}
input: {
console.log("foo".charCodeAt("bar".length));
}
expect: {
console.log(NaN);
}
expect_stdout: "NaN"
}

View File

@@ -557,3 +557,20 @@ native_prototype: {
"".indexOf.call(e, "bar"); "".indexOf.call(e, "bar");
} }
} }
issue_2040: {
input: {
var a = 1;
var b = {
get "a-b"() {
return a;
},
set "a-b"(c) {
a = c;
}
};
console.log(b["a-b"], b["a-b"] = 2, b["a-b"]);
}
expect_exact: 'var a=1;var b={get"a-b"(){return a},set"a-b"(c){a=c}};console.log(b["a-b"],b["a-b"]=2,b["a-b"]);'
expect_stdout: "1 2 2"
}