Comments (7)
I've just released the new version 1.16 containing the fix for this bug. Thank you for reporting!
from peast.
@Krinkle that's amazing, thank you for letting me know!
from peast.
I wasn’t able to find a trustworthy-looking “canonical” validator for earlier ES versions
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'
}
from peast.
The difference is apparently caused by the trailingCommaFunctionCallDeclaration
syntax feature, specifically its check in parseFormalParameterList()
(as opposed to the one in parseArgumentList()
, which doesn’t affect this issue AFAICT). If I add &&false
to that condition in parseFormalParameterList()
, Peast can parse the code again. So I’m guessing Peast is trying to parse (a=1,2)
as the beginning of an arrow function (like (a=1,b=2)=>a+b
) and complaining that 2
is not a parameter name, and then… somehow not backtracking properly, whereas in ES8+ it does backtrack? (But I’m way out of my depth here, I don’t know how Peast’s parser works.)
from peast.
Your analysis is correct, when the parser reads the 2
it stops parsing the parseFormalParameterList
because it's not valid for that context, for this reason it detects the comma before 2
as a trailing comma so it throws an exception if the trailingCommaFunctionCallDeclaration
feature is not active.
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.
from peast.
Amazing, thank you!
from peast.
@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:
- easy to use (one function as entry point),
- dependency-free (thus easy to audit and review for our checked-into-git vendor, read more),
- under an OSI-approved and GPL-compatible free software license,
- fast enough to validate new submissions in real-time during a web response.
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.
from peast.
Related Issues (20)
- Incorrect parsing of return statements with multi line template literals HOT 1
- Parse error with question mark followed by dot in ternary operator HOT 4
- Question: Known to PHP transpilers HOT 2
- Fails to parse some JS HOT 6
- Security Policy questions HOT 3
- Customize the grammar a bit? HOT 1
- Fatal error when xdebug enabled HOT 3
- wp i18n make-pot (WordPress) failing to parse specific JavaScript code HOT 3
- Failed to parse specific js code HOT 1
- Question: Is it possible to query by key name? HOT 4
- Utils::quoteLiteralString escapes \uFFF characters HOT 3
- async function declaration gets stripped HOT 3
- Generating optimized autoload files error → Could not scan for classes inside HOT 2
- Parsing issue HOT 2
- Required block brackets are removed on case statements HOT 1
- Parser chokes on a method named async HOT 1
- Improper regex string replacement (for a lack of better words) HOT 2
- Non-empty invalid script is perceived as empty valid script HOT 1
- Unexpected syntax error when parsing a regexp with backslashes and special characters (new in 1.16.1) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peast.