aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Lau <justin@tclau.com>2013-05-06 02:45:41 +0800
committerMihai Bazon <mihai@bazon.net>2013-05-07 14:20:19 +0300
commit9af2bbffde2653237b36a06b005209be9f6cc1e6 (patch)
tree1639bfdd0838285bfba70efc01032802de8a6dd4
parentfcd544cc106bbd04ca8003046fa76154cdb4046e (diff)
downloadtracifyjs-9af2bbffde2653237b36a06b005209be9f6cc1e6.tar.gz
tracifyjs-9af2bbffde2653237b36a06b005209be9f6cc1e6.zip
Fixed dot properties not optimizing unicode identifiers. Signed-off-by: Justin Lau <justin@tclau.com>
-rw-r--r--lib/compress.js4
-rw-r--r--lib/parse.js8
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..b3687201 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -167,6 +167,14 @@ function is_identifier_char(ch) {
;
};
+function is_identifier_string(str){
+ for (var i = str.length; --i >= 0;) {
+ if (!is_identifier_char(str.charAt(i)))
+ return false;
+ }
+ return true;
+};
+
function parse_js_number(num) {
if (RE_HEX_NUMBER.test(num)) {
return parseInt(num.substr(2), 16);