From 8227e8795b309b46e0f2ef998d7238198eb07425 Mon Sep 17 00:00:00 2001 From: Justin Lau Date: Sun, 5 May 2013 22:08:13 +0800 Subject: [PATCH 1/4] Added scenario in test case where properties shouldn't be accessed with dotted syntax even with screw_ie8 option. Signed-off-by: Justin Lau --- test/compress/properties.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/compress/properties.js b/test/compress/properties.js index 9b066ec9..118bc4c2 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -17,10 +17,12 @@ dot_properties: { input: { a["foo"] = "bar"; a["if"] = "if"; + a["*"] = "asterisk"; } expect: { a.foo = "bar"; a["if"] = "if"; + a["*"] = "asterisk"; } } @@ -32,9 +34,11 @@ dot_properties_es5: { input: { a["foo"] = "bar"; a["if"] = "if"; + a["*"] = "asterisk"; } expect: { a.foo = "bar"; a.if = "if"; + a["*"] = "asterisk"; } } From 1e3bc0caa0a8ad8c3bcab07d539ee153ea8e96b3 Mon Sep 17 00:00:00 2001 From: Justin Lau Date: Sun, 5 May 2013 22:27:43 +0800 Subject: [PATCH 2/4] Fixed dot property issue with invlid identifier names. Signed-off-by: Justin Lau --- lib/compress.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index ebd3dd7a..623fe45e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1962,7 +1962,8 @@ merge(Compressor.prototype, { var prop = self.property; if (prop instanceof AST_String && compressor.option("properties")) { prop = prop.getValue(); - if (is_identifier(prop) || compressor.option("screw_ie8")) { + if (is_identifier(prop) + || (compressor.option("screw_ie8") && /^[a-z_$][a-z0-9_$]*$/i.test(prop))) { return make_node(AST_Dot, self, { expression : self.expression, property : prop From fcd544cc106bbd04ca8003046fa76154cdb4046e Mon Sep 17 00:00:00 2001 From: Justin Lau Date: Mon, 6 May 2013 01:26:33 +0800 Subject: [PATCH 3/4] Added test scenario with unicode in properties name. Signed-off-by: Justin Lau --- test/compress/properties.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/compress/properties.js b/test/compress/properties.js index 118bc4c2..d52680c2 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -18,11 +18,13 @@ dot_properties: { a["foo"] = "bar"; a["if"] = "if"; a["*"] = "asterisk"; + a["\u0EB3"] = "unicode"; } expect: { a.foo = "bar"; a["if"] = "if"; a["*"] = "asterisk"; + a.\u0EB3 = "unicode"; } } @@ -35,10 +37,12 @@ dot_properties_es5: { a["foo"] = "bar"; a["if"] = "if"; a["*"] = "asterisk"; + a["\u0EB3"] = "unicode"; } expect: { a.foo = "bar"; a.if = "if"; a["*"] = "asterisk"; + a.\u0EB3 = "unicode"; } } From adeb7b2fe692c52dd7513409bea2e9b5420ccee3 Mon Sep 17 00:00:00 2001 From: Justin Lau Date: Mon, 6 May 2013 02:45:41 +0800 Subject: [PATCH 4/4] Fixed dot properties not optimizing unicode identifiers. Signed-off-by: Justin Lau --- lib/compress.js | 4 ++-- lib/parse.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 623fe45e..992d78f8 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1962,8 +1962,8 @@ merge(Compressor.prototype, { var prop = self.property; if (prop instanceof AST_String && compressor.option("properties")) { prop = prop.getValue(); - if (is_identifier(prop) - || (compressor.option("screw_ie8") && /^[a-z_$][a-z0-9_$]*$/i.test(prop))) { + if (compressor.option("screw_ie8") && RESERVED_WORDS(prop) + || !(RESERVED_WORDS(prop)) && is_identifier_string(prop)) { return make_node(AST_Dot, self, { expression : self.expression, property : prop diff --git a/lib/parse.js b/lib/parse.js index da39b5b1..b5f605a6 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -167,6 +167,14 @@ function is_identifier_char(ch) { ; }; +function is_identifier_string(string){ + for(var i in string) { + if(!is_identifier_char(string[i])) + return false; + } + return true; +} + function parse_js_number(num) { if (RE_HEX_NUMBER.test(num)) { return parseInt(num.substr(2), 16);