Compare commits

..

6 Commits

Author SHA1 Message Date
Mihai Bazon
d13aa3954d v2.3.3 2013-05-14 11:33:28 +03:00
Mihai Bazon
f64539fb76 Compress code passed to new Function if it's a constant.
Only for `--unsafe`.

Close #203
2013-05-14 10:47:06 +03:00
Mihai Bazon
d56ebd7d7b Fix a["1_1"]
Close #204
2013-05-14 10:42:34 +03:00
Mihai Bazon
3edfe7d0ee Merge pull request #202 from nschonni/add-travis-ci
Add CI build for supported Node versions
2013-05-10 02:56:24 -07:00
Nick Schonning
46814f88d9 Add Travis build badge to README 2013-05-08 23:48:12 -04:00
Nick Schonning
4a19802d0c Add CI build for supported Node versions 2013-05-08 23:42:06 -04:00
7 changed files with 53 additions and 4 deletions

7
.travis.yml Normal file
View File

@@ -0,0 +1,7 @@
language: node_js
node_js:
- "0.4"
- "0.6"
- "0.8"
- "0.10"
- "0.11"

View File

@@ -1,5 +1,6 @@
UglifyJS 2 UglifyJS 2
========== ==========
[![Build Status](https://travis-ci.org/mishoo/UglifyJS2.png)](https://travis-ci.org/mishoo/UglifyJS2)
UglifyJS is a JavaScript parser, minifier, compressor or beautifier toolkit. UglifyJS is a JavaScript parser, minifier, compressor or beautifier toolkit.

View File

@@ -1589,6 +1589,45 @@ merge(Compressor.prototype, {
operator: "+", operator: "+",
right: make_node(AST_String, self, { value: "" }) right: make_node(AST_String, self, { value: "" })
}); });
case "Function":
if (self.args[self.args.length - 1] instanceof AST_String) {
// quite a corner-case, but we can handle it:
// https://github.com/mishoo/UglifyJS2/issues/203
// if the code argument is a constant, then we can minify it.
try {
var code = "(function(" + self.args.slice(0, -1).map(function(arg){
return arg.value;
}).join(",") + "){" + self.args[self.args.length - 1].value + "})()";
var ast = parse(code);
ast.figure_out_scope();
var comp = new Compressor(compressor.options);
ast = ast.transform(comp);
ast.figure_out_scope();
ast.mangle_names();
var fun = ast.body[0].body.expression;
var args = fun.argnames.map(function(arg, i){
return make_node(AST_String, self.args[i], {
value: arg.print_to_string()
});
});
var code = OutputStream();
AST_BlockStatement.prototype._codegen.call(fun, fun, code);
code = code.toString().replace(/^\{|\}$/g, "");
args.push(make_node(AST_String, self.args[self.args.length - 1], {
value: code
}));
self.args = args;
return self;
} catch(ex) {
if (ex instanceof JS_Parse_Error) {
compressor.warn("Error parsing code passed to new Function [{file}:{line},{col}]", self.args[self.args.length - 1].start);
compressor.warn(ex.toString());
} else {
console.log(ex);
}
}
}
break;
} }
} }
else if (exp instanceof AST_Dot && exp.property == "toString" && self.args.length == 0) { else if (exp instanceof AST_Dot && exp.property == "toString" && self.args.length == 0) {
@@ -1965,8 +2004,8 @@ merge(Compressor.prototype, {
var prop = self.property; var prop = self.property;
if (prop instanceof AST_String && compressor.option("properties")) { if (prop instanceof AST_String && compressor.option("properties")) {
prop = prop.getValue(); prop = prop.getValue();
if (compressor.option("screw_ie8") && RESERVED_WORDS(prop) if ((compressor.option("screw_ie8") && RESERVED_WORDS(prop))
|| !(RESERVED_WORDS(prop)) && is_identifier_string(prop)) { || (!(RESERVED_WORDS(prop)) && is_identifier_string(prop))) {
return make_node(AST_Dot, self, { return make_node(AST_Dot, self, {
expression : self.expression, expression : self.expression,
property : prop property : prop

View File

@@ -170,6 +170,7 @@ function is_identifier_char(ch) {
function is_identifier_string(str){ function is_identifier_string(str){
var i = str.length; var i = str.length;
if (i == 0) return false; if (i == 0) return false;
if (is_digit(str.charCodeAt(0))) return false;
while (--i >= 0) { while (--i >= 0) {
if (!is_identifier_char(str.charAt(i))) if (!is_identifier_char(str.charAt(i)))
return false; return false;

View File

@@ -44,7 +44,6 @@
"use strict"; "use strict";
// Tree transformer helpers. // Tree transformer helpers.
// XXX: eventually I should refactor the compressor to use this infrastructure.
function TreeTransformer(before, after) { function TreeTransformer(before, after) {
TreeWalker.call(this); TreeWalker.call(this);

View File

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

View File

@@ -20,6 +20,7 @@ dot_properties: {
a["*"] = "asterisk"; a["*"] = "asterisk";
a["\u0EB3"] = "unicode"; a["\u0EB3"] = "unicode";
a[""] = "whitespace"; a[""] = "whitespace";
a["1_1"] = "foo";
} }
expect: { expect: {
a.foo = "bar"; a.foo = "bar";
@@ -27,6 +28,7 @@ dot_properties: {
a["*"] = "asterisk"; a["*"] = "asterisk";
a.\u0EB3 = "unicode"; a.\u0EB3 = "unicode";
a[""] = "whitespace"; a[""] = "whitespace";
a["1_1"] = "foo";
} }
} }