Skip to content

Commit

Permalink
fix parsing of property access after new line
Browse files Browse the repository at this point in the history
Account for comments when detecting property access in `tokenizer`.

fixes #1943
  • Loading branch information
alexlamsl committed May 15, 2017
1 parent f18abd1 commit ea95c51
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1368,27 +1372,27 @@ function parse($TEXT, options) {
});

function as_property_name() {
var tmp = S.token;
switch (tmp.type) {
var value = S.token.value;
switch (S.token.type) {
case "operator":
if (!KEYWORDS(tmp.value)) unexpected();
if (!KEYWORDS(value)) unexpected();
case "num":
case "string":
case "name":
case "keyword":
case "atom":
next();
return tmp.value;
return value;
default:
unexpected();
}
};

function as_name() {
var tmp = S.token;
if (tmp.type != "name") unexpected();
var value = S.token.value;
if (S.token.type != "name") unexpected();
next();
return tmp.value;
return value;
};

function _make_symbol(type) {
Expand Down
31 changes: 31 additions & 0 deletions test/compress/issue-1943.js
Original file line number Diff line number Diff line change
@@ -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;"
}

0 comments on commit ea95c51

Please sign in to comment.