[Pkg-javascript-commits] [node-acorn-jsx] 86/484: [loose parser] Improve recovery from unterminated strings and regexps
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:08 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 17a0094694db45251d7e92489475a3e2bbd2e4eb
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Thu Jan 17 15:01:13 2013 +0100
[loose parser] Improve recovery from unterminated strings and regexps
---
acorn_loose.js | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/acorn_loose.js b/acorn_loose.js
index f979030..771b205 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -65,9 +65,18 @@
// Try to skip some text, based on the error message, and then continue
var msg = e.message, pos = e.raisedAt, replace = true;
+ console.log(msg);
if (/unterminated/i.test(msg)) {
pos = lineEnd(e.pos);
- replace = !/comment/i.test(msg);
+ if (/string/.test(msg)) {
+ replace = {start: e.pos, end: pos, type: tt.string, value: input.slice(e.pos + 1, pos)};
+ } else if (/regular expr/i.test(msg)) {
+ var re = input.slice(e.pos, pos);
+ try { re = new RegExp(re); } catch(e) {}
+ replace = {start: e.pos, end: pos, type: tt.regexp, value: re};
+ } else {
+ replace = false;
+ }
} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number/i.test(msg)) {
while (pos < input.length && !isSpace(input.charCodeAt(pos))) ++pos;
} else if (/character escape|expected hexadecimal/i.test(msg)) {
@@ -82,7 +91,8 @@
throw e;
}
resetTo(pos);
- if (replace) return {start: pos, end: pos, type: tt.name, value: "✖"};
+ if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖"};
+ if (replace) return replace;
}
}
}
@@ -339,6 +349,7 @@
var maybeName = token.value, expr = parseExpression();
if (isDummy(expr)) {
next();
+ if (token.type === tt.eof) return finishNode(node, "EmptyStatement");
return parseStatement();
} else if (starttype === tt.name && expr.type === "Identifier" && eat(tt.colon)) {
node.body = parseStatement();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list