fix parsing of property access after new line (#1944)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 15 May 2017 21:40:49 +0000 (05:40 +0800)
committerGitHub <noreply@github.com>
Mon, 15 May 2017 21:40:49 +0000 (05:40 +0800)
Account for comments when detecting property access in `tokenizer`.

fixes #1943

lib/parse.js
test/compress/issue-1943.js [new file with mode: 0644]

index eab9b64..97dd6d4 100644 (file)
@@ -285,7 +285,11 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
         S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX(value)) ||
                            (type == "keyword" && KEYWORDS_BEFORE_EXPRESSION(value)) ||
                            (type == "punc" && PUNC_BEFORE_EXPRESSION(value)));
-        prev_was_dot = (type == "punc" && value == ".");
+        if (type == "punc" && value == ".") {
+            prev_was_dot = true;
+        } else if (!is_comment) {
+            prev_was_dot = false;
+        }
         var ret = {
             type    : type,
             value   : value,
diff --git a/test/compress/issue-1943.js b/test/compress/issue-1943.js
new file mode 100644 (file)
index 0000000..69bb9e6
--- /dev/null
@@ -0,0 +1,31 @@
+operator: {
+    input: {
+        a. //comment
+        typeof
+    }
+    expect_exact: "a.typeof;"
+}
+
+name: {
+    input: {
+        a. //comment
+        b
+    }
+    expect_exact: "a.b;"
+}
+
+keyword: {
+    input: {
+        a. //comment
+        default
+    }
+    expect_exact: "a.default;"
+}
+
+atom: {
+    input: {
+        a. //comment
+        true
+    }
+    expect_exact: "a.true;"
+}