Compare commits

..

5 Commits

Author SHA1 Message Date
Mihai Bazon
96ad94ab41 v2.4.22 2015-05-18 13:58:25 +03:00
Mihai Bazon
a5b60217ce Fix compressing conditionals
Only transform foo() ? EXP(x) : EXP(y) into EXP(foo() ? x : y) if EXP has no
side effects.

Fix #710
2015-05-18 13:56:04 +03:00
Mihai Bazon
44fd6694eb fix again reserved props 2015-05-13 22:03:00 +03:00
Mihai Bazon
e48db3a8b6 Make reserved names take priority over the name cache 2015-05-07 15:01:16 +03:00
Mihai Bazon
e637bdaf4e Only drop the BOM when it's the first character.
Close #704
2015-05-05 10:11:38 +03:00
5 changed files with 13 additions and 5 deletions

View File

@@ -2356,6 +2356,7 @@ merge(Compressor.prototype, {
if (consequent instanceof AST_Call
&& alternative.TYPE === consequent.TYPE
&& consequent.args.length == alternative.args.length
&& !consequent.expression.has_side_effects(compressor)
&& consequent.expression.equivalent_to(alternative.expression)) {
if (consequent.args.length == 0) {
return make_node(AST_Seq, self, {

View File

@@ -213,7 +213,7 @@ var EX_EOF = {};
function tokenizer($TEXT, filename, html5_comments) {
var S = {
text : $TEXT.replace(/\uFEFF/g, ''),
text : $TEXT.replace(/^\uFEFF/g, ''),
filename : filename,
pos : 0,
tokpos : 0,

View File

@@ -140,15 +140,16 @@ function mangle_properties(ast, options) {
// only function declarations after this line
function can_mangle(name) {
if (reserved.indexOf(name) >= 0) return false;
if (options.only_cache) {
return cache.props.has(name);
}
if (reserved.indexOf(name) >= 0) return false;
if (/^[0-9.]+$/.test(name)) return false;
return true;
}
function should_mangle(name) {
if (reserved.indexOf(name) >= 0) return false;
return cache.props.has(name)
|| names_to_mangle.indexOf(name) >= 0;
}

View File

@@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD",
"version": "2.4.21",
"version": "2.4.22",
"engines": {
"node": ">=0.4.0"
},

View File

@@ -153,6 +153,7 @@ cond_1: {
conditionals: true
};
input: {
var do_something; // if undeclared it's assumed to have side-effects
if (some_condition()) {
do_something(x);
} else {
@@ -160,6 +161,7 @@ cond_1: {
}
}
expect: {
var do_something;
do_something(some_condition() ? x : y);
}
}
@@ -169,7 +171,7 @@ cond_2: {
conditionals: true
};
input: {
var x;
var x, FooBar;
if (some_condition()) {
x = new FooBar(1);
} else {
@@ -177,7 +179,7 @@ cond_2: {
}
}
expect: {
var x;
var x, FooBar;
x = new FooBar(some_condition() ? 1 : 2);
}
}
@@ -187,6 +189,7 @@ cond_3: {
conditionals: true
};
input: {
var FooBar;
if (some_condition()) {
new FooBar(1);
} else {
@@ -194,6 +197,7 @@ cond_3: {
}
}
expect: {
var FooBar;
some_condition() ? new FooBar(1) : FooBar(2);
}
}
@@ -203,6 +207,7 @@ cond_4: {
conditionals: true
};
input: {
var do_something;
if (some_condition()) {
do_something();
} else {
@@ -210,6 +215,7 @@ cond_4: {
}
}
expect: {
var do_something;
some_condition(), do_something();
}
}