-
Notifications
You must be signed in to change notification settings - Fork 20
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
Peast cannot parse comma expression in assignment expression prior to ES8 (ES2017) #65
Comments
Here’s acorn, for what it’s worth, reporting this as parseable in ES3 and ES5: > acorn.version
'8.11.3'
> acorn.parse('(a=1,2)', { ecmaVersion: 3 })
Node {
type: 'Program',
start: 0,
end: 7,
body: [
Node {
type: 'ExpressionStatement',
start: 0,
end: 7,
expression: [Node]
}
],
sourceType: 'script'
}
> acorn.parse('(a=1,2)', { ecmaVersion: 5 })
Node {
type: 'Program',
start: 0,
end: 7,
body: [
Node {
type: 'ExpressionStatement',
start: 0,
end: 7,
expression: [Node]
}
],
sourceType: 'script'
} |
The difference is apparently caused by the |
Your analysis is correct, when the parser reads the I will look into this, it seems that it is caused by the wrong detection of what is a trailing comma in a parameters list. |
I've just released the new version 1.16 containing the fix for this bug. Thank you for reporting! |
Amazing, thank you! |
@mck89 In case you'd like to keep track, your library is now used in the MediaWiki software that powers Wikipedia! I selected your library as part of T75714, for our ResourceLoader component, where we validate user-submitted JavaScript code (what?). I found your library the most well-maintained and up-to-date implementation I could find, valuing in particular:
You're listed and credited at https://en.wikipedia.org/wiki/Special:Version. The code using it is also mirrored at https://github.com/wikimedia/mediawiki. |
@Krinkle that's amazing, thank you for letting me know! |
Minimal example:
As far as I understand, this should be valid in all syntax versions – comma expressions and assignment expressions are both carried over from C. However, Peast refuses to parse this prior to ES8:
I believe this is a bug in Peast, though I’m not sure. I wasn’t able to find a trustworthy-looking “canonical” validator for earlier ES versions, but at least Node.js has been able to parse this syntax since the earliest versions on Docker Hub (published June 2015):
Slightly less minimal version (you can try that it prints
3
in Node, but it’s also rejected by Peast pre-ES8):See also T354807 at Wikimedia’s bugtracker if you’re interested.
The text was updated successfully, but these errors were encountered: