Skip to content
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

Error happens when decomment parses some regular expressions #15

Open
DIYgod opened this issue Oct 31, 2017 · 10 comments
Open

Error happens when decomment parses some regular expressions #15

DIYgod opened this issue Oct 31, 2017 · 10 comments

Comments

@DIYgod
Copy link

DIYgod commented Oct 31, 2017

A minimal demo:

var decomment = require('decomment');
var code = 'if(true){}/\\d/.test(\'\')';
decomment(code);

Error log:

Error: Line 1: Unexpected token ILLEGAL
    at ErrorHandler.constructError (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:5004:22)
    at ErrorHandler.createError (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:5020:27)
    at ErrorHandler.throwError (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:5027:21)
    at Scanner.throwUnexpectedToken (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:5155:35)
    at Scanner.getComplexIdentifier (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:5488:23)
    at Scanner.scanIdentifier (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:5556:67)
    at Scanner.lex (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:6223:26)
    at Tokenizer.getNextToken (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:6666:84)
    at Object.tokenize (/Users/DIYgod/Code/test/node_modules/esprima/dist/esprima.js:154:36)
    at Object.parseRegEx (/Users/DIYgod/Code/test/node_modules/decomment/lib/utils.js:37:13)
@DIYgod DIYgod changed the title Error happens when decomment parse some regular expression Error happens when decomment parses some regular expressions Oct 31, 2017
@vitaly-t
Copy link
Owner

When Esprima doesn’t like your code, it must an invalid JavaScript ;)

@DIYgod
Copy link
Author

DIYgod commented Oct 31, 2017

The compressed source code is like

if(true){}/\d/.test('');

Then gulp-strip-comments parses my code with toString function to a string like 'if(true){}/\\d/.test(\'\')'

Should I make an issue to gulp-strip-comments?

@vitaly-t
Copy link
Owner

I’m not sure, I will test it later though ;)

@vitaly-t
Copy link
Owner

vitaly-t commented Oct 31, 2017

Here's the test I've done, and it all looks fine:

const decomment = require('decomment');

const str = 'if(true){}/\d/.test(\'\');';

const s = decomment(str);

console.log(s);
//=> if(true){}/d/.test('');

Have you tried gulp-decomment?

@DIYgod
Copy link
Author

DIYgod commented Nov 1, 2017

Sorry for my late reply.

The error happends in /\\d/, not /\d/

@vitaly-t
Copy link
Owner

vitaly-t commented Nov 1, 2017

You should log/chase it against the Esprima engine as the one that fails to process that piece of JavaScript.

There is nothing that can be done about it within this library.

@vitaly-t
Copy link
Owner

vitaly-t commented Nov 1, 2017

There, I've opened an issue: Fails on a compressed piece of code.

@DIYgod
Copy link
Author

DIYgod commented Nov 1, 2017

Thanks!

@vitaly-t
Copy link
Owner

The author of Esprima claims he fixed it, but I've just released an update, and I can still reproduce the issue :(

@vitaly-t
Copy link
Owner

Esprima hasn't been published for 3 years, and now looks a bit abandoned.

I presently do not have time for rewriting this library to use a different parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants