aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-23 06:08:01 +0300
committermax99x <max99x@gmail.com>2011-08-23 06:08:19 +0300
commit536bad16ce88bad71fe94af285f9a9d2f721b2ad (patch)
treee6b5b8935b973819117c40ee1001e82120962d36
parent9cf10ae755d5ef32d558d945c25464e1ba564738 (diff)
Updated UglifyJS to preserve object key quotedness (Closure Compiler compatibility).
-rw-r--r--tools/eliminator/eliminator-test-output.js5
-rw-r--r--tools/eliminator/eliminator-test.js6
-rw-r--r--tools/eliminator/eliminator.coffee6
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/parse-js.js28
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/process.js2
5 files changed, 29 insertions, 18 deletions
diff --git a/tools/eliminator/eliminator-test-output.js b/tools/eliminator/eliminator-test-output.js
index f7dee2b0..4c9224da 100644
--- a/tools/eliminator/eliminator-test-output.js
+++ b/tools/eliminator/eliminator-test-output.js
@@ -34,4 +34,9 @@ var g = function(a1, a2) {
var sadijn = new asd;
sadijn2 = "qwe%sert";
this.Module || (this.Module = {});
+ var obj = {
+ "quoted": 1,
+ "doublequoted": 2,
+ unquoted: 3
+ };
};
diff --git a/tools/eliminator/eliminator-test.js b/tools/eliminator/eliminator-test.js
index 3311b34f..68d9fdf5 100644
--- a/tools/eliminator/eliminator-test.js
+++ b/tools/eliminator/eliminator-test.js
@@ -32,4 +32,10 @@ var g = function (a1, a2) {
var sadijn = new asd;
sadijn2 = "qwe%sert";
this.Module || (this.Module = {});
+ var obj = {
+ 'quoted': 1,
+ "doublequoted": 2,
+ unquoted: 3,
+ 4: 5
+ };
}
diff --git a/tools/eliminator/eliminator.coffee b/tools/eliminator/eliminator.coffee
index 02b0bebd..260ed289 100644
--- a/tools/eliminator/eliminator.coffee
+++ b/tools/eliminator/eliminator.coffee
@@ -9,7 +9,7 @@
Uses only local, single-def names
*
Uses non-local or non-single-def names
- No flow-controlling statements
+ No flow-controlling statements between def and use
No references to any deps between def and use
*
Multi-use
@@ -17,9 +17,6 @@
Uses only single-def names
*
- WARNING(max99x): A round trip through UglifyJS breaks Closure's
- ADVANCED_OPTIMIZATIONS, probably due to lack of
- differentiation between quoted and unquoted keys.
TODO(max99x): Eliminate single-def undefined-initialized vars with no uses
between declaration and definition.
###
@@ -41,7 +38,6 @@ SIMPLE_NODES =
MAX_USES = 3
# The UglifyJs code generator settings to use.
-# TODO(max99x): Fix whatever is causing quote_keys=true to fail inside uglify.
GEN_OPTIONS =
ascii_only: true
beautify: true
diff --git a/tools/eliminator/node_modules/uglify-js/lib/parse-js.js b/tools/eliminator/node_modules/uglify-js/lib/parse-js.js
index 69abf6c6..a89163c6 100644
--- a/tools/eliminator/node_modules/uglify-js/lib/parse-js.js
+++ b/tools/eliminator/node_modules/uglify-js/lib/parse-js.js
@@ -1129,27 +1129,31 @@ function parse($TEXT, exigent_mode, embed_tokens) {
// allow trailing comma
break;
var type = S.token.type;
- var name = as_property_name();
+ var name;
+ var is_quoted = false;
+ switch (S.token.type) {
+ case "string":
+ is_quoted = true;
+ case "num":
+ name = prog1(S.token.value, next);
+ break;
+ default:
+ name = as_name()
+ }
+ var node;
if (type == "name" && (name == "get" || name == "set") && !is("punc", ":")) {
- a.push([ as_name(), function_(false), name ]);
+ node = [ as_name(), function_(false), name ];
} else {
expect(":");
- a.push([ name, expression(false) ]);
+ node = [ name, expression(false) ];
}
+ if (is_quoted) node.quoted = true;
+ a.push(node);
}
next();
return as("object", a);
};
- function as_property_name() {
- switch (S.token.type) {
- case "num":
- case "string":
- return prog1(S.token.value, next);
- }
- return as_name();
- };
-
function as_name() {
switch (S.token.type) {
case "name":
diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js
index d34e2394..85709857 100644
--- a/tools/eliminator/node_modules/uglify-js/lib/process.js
+++ b/tools/eliminator/node_modules/uglify-js/lib/process.js
@@ -1673,7 +1673,7 @@ function gen_code(ast, options) {
return indent(make_function(p[0], p[1][2], p[1][3], p[2]));
}
var key = p[0], val = parenthesize(p[1], "seq");
- if (options.quote_keys) {
+ if (options.quote_keys || p.quoted) {
key = encode_string(key);
} else if ((typeof key == "number" || !beautify && +key + "" == key)
&& parseFloat(key) >= 0) {