aboutsummaryrefslogtreecommitdiff
path: root/lib/parse.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-03-15 00:20:20 +0800
committerGitHub <noreply@github.com>2019-03-15 00:20:20 +0800
commitd90777b724689af625c36ed6d557b024775ee95a (patch)
tree5fe1aad5f5aeaad383b0cef847b445e862af07fd /lib/parse.js
parente49297e5eb7039246cc3a78019234826631eb623 (diff)
downloadtracifyjs-d90777b724689af625c36ed6d557b024775ee95a.tar.gz
tracifyjs-d90777b724689af625c36ed6d557b024775ee95a.zip
parse `mangle.properties.regex` in `--config-file` properly (#3337)
fixes #3315
Diffstat (limited to 'lib/parse.js')
-rw-r--r--lib/parse.js29
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/parse.js b/lib/parse.js
index 29df370c..a58557dd 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -758,17 +758,21 @@ function parse($TEXT, options) {
croak(msg, token.line, token.col);
}
+ function token_to_string(type, value) {
+ return type + (value === undefined ? "" : " «" + value + "»");
+ }
+
function unexpected(token) {
if (token == null)
token = S.token;
- token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
+ token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
}
function expect_token(type, val) {
if (is(type, val)) {
return next();
}
- token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
+ token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
}
function expect(punc) {
@@ -788,7 +792,7 @@ function parse($TEXT, options) {
function semicolon(optional) {
if (is("punc", ";")) next();
- else if (!optional && !can_insert_semicolon()) unexpected();
+ else if (!optional && !can_insert_semicolon()) expect_token("punc", ";");
}
function parenthesised() {
@@ -1069,7 +1073,7 @@ function parse($TEXT, options) {
var in_statement = ctor === AST_Defun;
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
if (in_statement && !name)
- unexpected();
+ expect_token("name");
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
unexpected(prev());
expect("(");
@@ -1119,7 +1123,7 @@ function parse($TEXT, options) {
expect("{");
var a = [];
while (!is("punc", "}")) {
- if (is("eof")) unexpected();
+ if (is("eof")) expect_token("punc", "}");
a.push(statement(strict_defun));
}
next();
@@ -1130,7 +1134,7 @@ function parse($TEXT, options) {
expect("{");
var a = [], cur = null, branch = null, tmp;
while (!is("punc", "}")) {
- if (is("eof")) unexpected();
+ if (is("eof")) expect_token("punc", "}");
if (is("keyword", "case")) {
if (branch) branch.end = prev();
cur = [];
@@ -1141,8 +1145,7 @@ function parse($TEXT, options) {
});
a.push(branch);
expect(":");
- }
- else if (is("keyword", "default")) {
+ } else if (is("keyword", "default")) {
if (branch) branch.end = prev();
cur = [];
branch = new AST_Default({
@@ -1150,8 +1153,7 @@ function parse($TEXT, options) {
body : cur
});
a.push(branch);
- }
- else {
+ } else {
if (!cur) unexpected();
cur.push(statement());
}
@@ -1420,10 +1422,10 @@ function parse($TEXT, options) {
}
function as_name() {
- var tmp = S.token;
- if (tmp.type != "name") unexpected();
+ if (!is("name")) expect_token("name");
+ var name = S.token.value;
next();
- return tmp.value;
+ return name;
}
function _make_symbol(type) {
@@ -1625,6 +1627,7 @@ function parse($TEXT, options) {
}
if (options.expression) {
+ handle_regexp();
return expression(true);
}