From d56ebd7d7b8de0b46ce203b580df28d76fa16692 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 14 May 2013 10:41:28 +0300 Subject: [PATCH] Fix a["1_1"] Close #204 --- lib/compress.js | 4 ++-- lib/parse.js | 1 + test/compress/properties.js | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index c94af7d0..24cdc026 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1965,8 +1965,8 @@ merge(Compressor.prototype, { var prop = self.property; if (prop instanceof AST_String && compressor.option("properties")) { prop = prop.getValue(); - if (compressor.option("screw_ie8") && RESERVED_WORDS(prop) - || !(RESERVED_WORDS(prop)) && is_identifier_string(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 c8c5d0a0..a687495b 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -170,6 +170,7 @@ function is_identifier_char(ch) { function is_identifier_string(str){ var i = str.length; if (i == 0) return false; + if (is_digit(str.charCodeAt(0))) return false; while (--i >= 0) { if (!is_identifier_char(str.charAt(i))) return false; diff --git a/test/compress/properties.js b/test/compress/properties.js index f490fd86..85045961 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -20,6 +20,7 @@ dot_properties: { a["*"] = "asterisk"; a["\u0EB3"] = "unicode"; a[""] = "whitespace"; + a["1_1"] = "foo"; } expect: { a.foo = "bar"; @@ -27,6 +28,7 @@ dot_properties: { a["*"] = "asterisk"; a.\u0EB3 = "unicode"; a[""] = "whitespace"; + a["1_1"] = "foo"; } } -- 2.34.1