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

classEscape SyntaxError #98

Closed
mdjermanovic opened this issue Dec 13, 2019 · 12 comments · Fixed by #99
Closed

classEscape SyntaxError #98

mdjermanovic opened this issue Dec 13, 2019 · 12 comments · Fixed by #99

Comments

@mdjermanovic
Copy link

Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/vsts/work/1/s/lib/linter/config-comment-parser.js: classEscape at position 12
    a-zA-Z0-9\-/]+):
              ^
    at bail (/home/vsts/work/1/s/node_modules/regjsparser/parser.js:1118:13)

ref eslint/eslint#12660

@mdjermanovic
Copy link
Author

The regex in question is: /([a-zA-Z0-9\-/]+):/gu

That \- could be an unnecessary escape, but v8 doesn't complain about it.

@jviereck
Copy link
Owner

jviereck commented Dec 13, 2019

Firefox does this:

(/([a-zA-Z0-9\-/]+):/gu).source == "([a-zA-Z0-9\\-/]+):"

@mdjermanovic
Copy link
Author

Firefox does this:

(/([a-zA-Z0-9\-/]+):/gu).source == "([a-zA-Z0-9\\-/]+):"

Why that doesn't look correct, \\ on the right side is a string escape?

With the u flag, \- seems to be explicitly allowed in character classes as a ClassEscape? (not IdentityEscape)

@mysticatea
Copy link

mysticatea commented Dec 16, 2019

/([a-zA-Z0-9\-/]+):/gu is a valid regular expression, but regjsparser raises wrong syntax error. (https://runkit.com/embed/3a5p2ec8y9fl)

See the above link that throws on a native regular expression.

@chriseppstein
Copy link

This is breaking ember applications. Will there be a fix released soon?

Workaround for yarn users:

{
  "resolutions": {
    "regjsparser": "0.6.0"
  }
}

@jviereck
Copy link
Owner

Looking at this and will keep you posted.

@jviereck
Copy link
Owner

Reduction:

regjsparser.parse('[\\-/]', '') // Works (1)
regjsparser.parse('[\\-/]', 'u') // Fails (2)

Also note, that

// Executed in Firefox 71
r = new RegExp('[\\-/]')
r.exec('\\') // -> null
r.exec('-') // -> Array ['-']
r.exec('/') // -> Array ['/']

Note that the parsing of regjsparser.parse('[\\-/]', '') returns the correct AST matching the output required to what the test against the real engine in Firefox is producing.

From this, it seems the problem is when using the 'u' flag for parsing the string.

@jviereck
Copy link
Owner

@chriseppstein , I am about to board my NYC -> ZHR bound plane and cannot commit to have a fix done soon. In case this is time critical, can you maybe do a workaround in the meantime by avoid using the "u" flag?

@chriseppstein
Copy link

@jviereck Thank you for looking into this. It's a transitive dependency of regexpu-core and I'm pretty sure the point of using it is the u flag 😬

@jviereck
Copy link
Owner

Thanks to the quick PR from @JLHwung this was fixed in #99.

RegExp provided as error case in the first issue is parsing now upstream: http://www.julianviereck.de/regjsparser/#%2F%28%5Ba-zA-Z0-9%5C-%2F%5D%2B%29%2Fug

A new v0.6.2 was drafted and pushed to NPM: https://www.npmjs.com/package/regjsparser/v/0.6.2

@jviereck
Copy link
Owner

@chriseppstein @mdjermanovic please let us know in case there are still problems on this one!

On a personal note, it's useful for me to know what's the impact of a reported bug is to give it the proper priorities. Reading that this breaks Ember applications made this a P0 for me.

@JLHwung
Copy link
Contributor

JLHwung commented Dec 22, 2019

@jviereck As a side note, astexplorer.net has supported regjsparser: https://astexplorer.net/#/gist/ef57a380fe2b8297bb9c1ea563ee5025/ba427130bca471ec269cea94f07c489462cdd7fc

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

Successfully merging a pull request may close this issue.

5 participants