-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail to tokenize a regular expression #1873
Comments
@ariya Any chance this issue will be looked at? It was logged 18 days ago, and no response since. |
@vitaly-t Please be patient, every contributor seems to be extremely busy these days. |
@vitaly-t What version of esprima are you using? I cannot reproduce a failure using the online demo. |
@michaelficarra There is something not right with that online test. I cannot get it to fail, but locally it fails always, with any 3.x or 4.0.0 version of Esprima. You must define the input correctly, like this: const input = 'if(true){}/\\d/.test(\'\');'; then it will fail when you run it locally through Esprima. |
Actually no, I can, and here it is. |
@vitaly-t That's not a JavaScript program. Check your quotes. |
@michaelficarra it perfectly is JavaScript. You can change it to this, if you like: const input = "if(true){}/\\d/.test('');"; Not sure what you mean by program, it is a piece of compressed JavaScript, as I described it in the beginning. I can see that the online test fails to reproduce the issue, but you can reproduce it locally 😉 |
@vitaly-t Sorry, but you're just wrong.
I cannot reproduce this either on the website or locally using a freshly-installed esprima |
Another way to play with this is with RunKit, e.g. https://runkit.com/5a127690868980001150b6df/5a127690bb5c880012193356. |
In a simplified form, this is the code that fails: const esprima = require('esprima');
const input = "if(true){}/\\d/.test('');";
esprima.tokenize(input); I'm using method esprima.tokenize(input, {loc: true, range: true}, node => {
if (node.type === 'RegularExpression') {
// processing...
}
}); |
@vitaly-t Thanks for the clarification! So this is basically a problem for the pure tokenizer (not the parser). |
@ariya it would appear, yes, sorry for the confusion earlier. The tokenizer fails with the given example. |
At the same time, ensure that it can fall back if the regex literal proved to be invalid. Fix jquery#1772 Fix jquery#1873
@ariya Just tested against version 4.0.1, and the issue is still there. So whatever that commit was - does not fix the issue. Please re-open it. i'm getting the very same error:
|
@vitaly-t If you want to try it out, can you try the master branch? |
Fails to process the following code:
or
This is a perfectly valid JavaScript after compression that Esprima cannot handle - throws an error:
The text was updated successfully, but these errors were encountered: