Compare commits

...

6 Commits

Author SHA1 Message Date
Mihai Bazon
0552dbd93c v2.4.20 2015-04-13 18:59:21 +03:00
Mihai Bazon
18c63ff3d8 Fix compression of conditionals
Don't move the condition on the right side of an assignment when
the left side may have side effects.

Fix #677
2015-04-13 17:29:48 +03:00
Mihai Bazon
e04ef56243 Use the before visitor in mangle props
(works around a bug in our tree walker which, while cloning nodes, breaks
references between labeled statements and break/continue labels)
2015-04-10 11:33:29 +03:00
Mihai Bazon
5d60484553 More fixes for the breaking changes in yargs
Close #670
2015-04-05 13:20:22 +03:00
Mihai Bazon
3c846e6f7b Merge pull request #669 from galvanix/documentation-inSourceMap
Document passing source maps directly to minify() using inSourceMap
2015-04-04 15:29:03 +03:00
David Caldwell
2850dc69fd Document passing source maps directly to minify() using inSourceMap 2015-04-03 17:27:28 -07:00
6 changed files with 28 additions and 7 deletions

View File

@@ -591,6 +591,16 @@ var result = UglifyJS.minify("compiled.js", {
// same as before, it returns `code` and `map`
```
If your input source map is not in a file, you can pass it in as an object
using the `inSourceMap` argument:
```javascript
var result = UglifyJS.minify("compiled.js", {
inSourceMap: JSON.parse(my_source_map_string),
outSourceMap: "minified.js.map"
});
```
The `inSourceMap` is only used if you also request `outSourceMap` (it makes
no sense otherwise).

View File

@@ -215,7 +215,7 @@ if (ARGS.keep_fnames) {
if (BEAUTIFY)
UglifyJS.merge(OUTPUT_OPTIONS, BEAUTIFY);
if (ARGS.comments) {
if (ARGS.comments != null) {
if (/^\/.*\/[a-zA-Z]*$/.test(ARGS.comments)) {
var regex_pos = ARGS.comments.lastIndexOf("/");
try {
@@ -357,11 +357,11 @@ async.eachLimit(files, 1, function (file, cb) {
TOPLEVEL = UglifyJS.AST_Node.from_mozilla_ast(TOPLEVEL);
});
if (ARGS.wrap) {
if (ARGS.wrap != null) {
TOPLEVEL = TOPLEVEL.wrap_commonjs(ARGS.wrap, ARGS.export_all);
}
if (ARGS.enclose) {
if (ARGS.enclose != null) {
var arg_parameter_list = ARGS.enclose;
if (arg_parameter_list === true) {
arg_parameter_list = [];

View File

@@ -2343,6 +2343,7 @@ merge(Compressor.prototype, {
&& alternative instanceof AST_Assign
&& consequent.operator == alternative.operator
&& consequent.left.equivalent_to(alternative.left)
&& !consequent.left.has_side_effects(compressor)
) {
/*
* Stuff like this:

View File

@@ -102,7 +102,7 @@ function mangle_properties(ast, options) {
}));
// step 2: transform the tree, renaming properties
return ast.transform(new TreeTransformer(null, function(node){
return ast.transform(new TreeTransformer(function(node){
if (node instanceof AST_ObjectKeyVal) {
if (should_mangle(node.key)) {
node.key = mangle(node.key);

View File

@@ -3,7 +3,7 @@
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
"homepage": "http://lisperator.net/uglifyjs",
"main": "tools/node.js",
"version": "2.4.19",
"version": "2.4.20",
"engines": { "node" : ">=0.4.0" },
"maintainers": [{
"name": "Mihai Bazon",

View File

@@ -86,7 +86,9 @@ ifs_4: {
x(foo)[10].bar.baz = something_else();
}
expect: {
x(foo)[10].bar.baz = (foo && bar) ? something() : something_else();
foo && bar
? x(foo)[10].bar.baz = something()
: x(foo)[10].bar.baz = something_else();
}
}
@@ -133,6 +135,7 @@ ifs_6: {
comparisons: true
};
input: {
var x;
if (!foo && !bar && !baz && !boo) {
x = 10;
} else {
@@ -140,6 +143,7 @@ ifs_6: {
}
}
expect: {
var x;
x = foo || bar || baz || boo ? 20 : 10;
}
}
@@ -165,6 +169,7 @@ cond_2: {
conditionals: true
};
input: {
var x;
if (some_condition()) {
x = new FooBar(1);
} else {
@@ -172,6 +177,7 @@ cond_2: {
}
}
expect: {
var x;
x = new FooBar(some_condition() ? 1 : 2);
}
}
@@ -303,6 +309,7 @@ cond_7_1: {
evaluate : true
};
input: {
var x;
// access to global should be assumed to have side effects
if (y) {
x = 1+1;
@@ -311,6 +318,7 @@ cond_7_1: {
}
}
expect: {
var x;
x = (y, 2);
}
}
@@ -321,6 +329,7 @@ cond_8: {
evaluate : true
};
input: {
var a;
// compress these
a = condition ? true : false;
@@ -355,6 +364,7 @@ cond_8: {
}
expect: {
var a;
a = !!condition;
a = !condition;
a = !!condition();