Comments (4)
I've just fixed this error, the problem wasn't the object itself but the spread operator inside it, the parser was failing too early when consuming it. Thank you for reporting!
from peast.
I've released version 1.13.2 with this bugfix
from peast.
Some additional context:
Source which fails:
$source = 'const foo = () => ({ ...(void 0) });';
$ast = Peast\Peast::latest( $source )->parse();
Fatal error: Uncaught Peast\Syntax\Exception: Unexpected: ( in /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/ParserAbstract.php:305
Stack trace:
#0 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(2917): Peast\Syntax\ParserAbstract->error()
#1 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(2885): Peast\Syntax\Parser->parseRestProperty()
#2 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(2326): Peast\Syntax\Parser->parseObjectBindingPattern()
#3 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(2417): Peast\Syntax\Parser->parseBindingPattern()
#4 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(1604): Peast\Syntax\Parser->parseBindingElement()
#5 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(2660): Peast\Syntax\Parser->parseFormalParameterList()
#6 /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/Parser.php(2720): Peast\Syntax\Parser->parseArrowParameters()
#7 /private/tmp/peast/vendor/mck89/peast/lib/P in /private/tmp/peast/vendor/mck89/peast/lib/Peast/Syntax/ParserAbstract.php on line 305
AST based on https://astexplorer.net/
{
"type": "Program",
"start": 0,
"end": 36,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 36,
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 35,
"id": {
"type": "Identifier",
"start": 6,
"end": 9,
"name": "foo"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 12,
"end": 35,
"id": null,
"expression": true,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "ObjectExpression",
"start": 19,
"end": 34,
"properties": [
{
"type": "SpreadElement",
"start": 21,
"end": 32,
"argument": {
"type": "UnaryExpression",
"start": 25,
"end": 31,
"operator": "void",
"prefix": true,
"argument": {
"type": "Literal",
"start": 30,
"end": 31,
"value": 0,
"raw": "0"
}
}
}
]
}
}
}
],
"kind": "const"
}
],
"sourceType": "module"
}
Source which passes:
$source = 'const foo = () => {
return { ...(void 0) };
};';
$ast = Peast\Peast::latest( $source )->parse();
Value of $ast
object(Peast\Syntax\Node\Program)#10 (6) {
["propertiesMap":protected]=>
array(2) {
["body"]=>
bool(true)
["sourceType"]=>
bool(false)
}
["sourceType":protected]=>
string(6) "script"
["body":protected]=>
array(1) {
[0]=>
object(Peast\Syntax\Node\VariableDeclaration)#44 (6) {
["propertiesMap":protected]=>
array(2) {
["declarations"]=>
bool(true)
["kind"]=>
bool(false)
}
["declarations":protected]=>
array(1) {
[0]=>
object(Peast\Syntax\Node\VariableDeclarator)#20 (6) {
["propertiesMap":protected]=>
array(2) {
["id"]=>
bool(true)
["init"]=>
bool(true)
}
["id":protected]=>
object(Peast\Syntax\Node\Identifier)#18 (5) {
["propertiesMap":protected]=>
array(1) {
["name"]=>
bool(false)
}
["name":protected]=>
string(3) "foo"
["location"]=>
object(Peast\Syntax\SourceLocation)#19 (2) {
["start"]=>
object(Peast\Syntax\Position)#14 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(6)
["index":protected]=>
int(6)
}
["end"]=>
object(Peast\Syntax\Position)#17 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(9)
["index":protected]=>
int(9)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["init":protected]=>
object(Peast\Syntax\Node\ArrowFunctionExpression)#33 (10) {
["propertiesMap":protected]=>
array(1) {
["expression"]=>
bool(false)
}
["expression":protected]=>
bool(false)
["id":protected]=>
NULL
["params":protected]=>
array(0) {
}
["body":protected]=>
object(Peast\Syntax\Node\BlockStatement)#50 (5) {
["propertiesMap":protected]=>
array(1) {
["body"]=>
bool(true)
}
["body":protected]=>
array(1) {
[0]=>
object(Peast\Syntax\Node\ReturnStatement)#41 (5) {
["propertiesMap":protected]=>
array(1) {
["argument"]=>
bool(true)
}
["argument":protected]=>
object(Peast\Syntax\Node\ObjectExpression)#55 (5) {
["propertiesMap":protected]=>
array(1) {
["properties"]=>
bool(true)
}
["properties":protected]=>
array(1) {
[0]=>
object(Peast\Syntax\Node\SpreadElement)#62 (5) {
["propertiesMap":protected]=>
array(1) {
["argument"]=>
bool(true)
}
["argument":protected]=>
object(Peast\Syntax\Node\ParenthesizedExpression)#61 (5) {
["propertiesMap":protected]=>
array(1) {
["expression"]=>
bool(true)
}
["expression":protected]=>
object(Peast\Syntax\Node\UnaryExpression)#70 (7) {
["propertiesMap":protected]=>
array(3) {
["argument"]=>
bool(true)
["operator"]=>
bool(false)
["prefix"]=>
bool(false)
}
["operator":protected]=>
string(4) "void"
["prefix":protected]=>
bool(true)
["argument":protected]=>
object(Peast\Syntax\Node\NumericLiteral)#66 (8) {
["propertiesMap":protected]=>
array(1) {
["format"]=>
bool(false)
}
["format":protected]=>
string(7) "decimal"
["forms":protected]=>
array(3) {
["b"]=>
array(3) {
["check"]=>
string(18) "/^0b[01]+[01_]*$/i"
["conv"]=>
string(6) "bindec"
["format"]=>
string(6) "binary"
}
["o"]=>
array(3) {
["check"]=>
string(20) "/^0o[0-7]+[0-7_]*$/i"
["conv"]=>
string(6) "octdec"
["format"]=>
string(5) "octal"
}
["x"]=>
array(3) {
["check"]=>
string(26) "/^0x[0-9a-f]+[0-9a-f_]*$/i"
["conv"]=>
string(6) "hexdec"
["format"]=>
string(11) "hexadecimal"
}
}
["value":protected]=>
int(0)
["raw":protected]=>
string(1) "0"
["location"]=>
object(Peast\Syntax\SourceLocation)#67 (2) {
["start"]=>
object(Peast\Syntax\Position)#63 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(22)
["index":protected]=>
int(42)
}
["end"]=>
object(Peast\Syntax\Position)#65 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(23)
["index":protected]=>
int(43)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#71 (2) {
["start"]=>
object(Peast\Syntax\Position)#57 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(17)
["index":protected]=>
int(37)
}
["end"]=>
object(Peast\Syntax\Position)#65 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(23)
["index":protected]=>
int(43)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#68 (2) {
["start"]=>
object(Peast\Syntax\Position)#53 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(16)
["index":protected]=>
int(36)
}
["end"]=>
object(Peast\Syntax\Position)#69 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(24)
["index":protected]=>
int(44)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#36 (2) {
["start"]=>
object(Peast\Syntax\Position)#48 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(13)
["index":protected]=>
int(33)
}
["end"]=>
object(Peast\Syntax\Position)#69 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(24)
["index":protected]=>
int(44)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#56 (2) {
["start"]=>
object(Peast\Syntax\Position)#43 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(11)
["index":protected]=>
int(31)
}
["end"]=>
object(Peast\Syntax\Position)#64 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(26)
["index":protected]=>
int(46)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#42 (2) {
["start"]=>
object(Peast\Syntax\Position)#37 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(4)
["index":protected]=>
int(24)
}
["end"]=>
object(Peast\Syntax\Position)#54 (3) {
["line":protected]=>
int(2)
["column":protected]=>
int(27)
["index":protected]=>
int(47)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#47 (2) {
["start"]=>
object(Peast\Syntax\Position)#32 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(18)
["index":protected]=>
int(18)
}
["end"]=>
object(Peast\Syntax\Position)#45 (3) {
["line":protected]=>
int(3)
["column":protected]=>
int(1)
["index":protected]=>
int(49)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["generator":protected]=>
bool(false)
["async":protected]=>
bool(false)
["location"]=>
object(Peast\Syntax\SourceLocation)#31 (2) {
["start"]=>
object(Peast\Syntax\Position)#23 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(12)
["index":protected]=>
int(12)
}
["end"]=>
object(Peast\Syntax\Position)#45 (3) {
["line":protected]=>
int(3)
["column":protected]=>
int(1)
["index":protected]=>
int(49)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#21 (2) {
["start"]=>
object(Peast\Syntax\Position)#14 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(6)
["index":protected]=>
int(6)
}
["end"]=>
object(Peast\Syntax\Position)#45 (3) {
["line":protected]=>
int(3)
["column":protected]=>
int(1)
["index":protected]=>
int(49)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
}
["kind":protected]=>
string(5) "const"
["location"]=>
object(Peast\Syntax\SourceLocation)#52 (2) {
["start"]=>
object(Peast\Syntax\Position)#9 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(0)
["index":protected]=>
int(0)
}
["end"]=>
object(Peast\Syntax\Position)#49 (3) {
["line":protected]=>
int(3)
["column":protected]=>
int(2)
["index":protected]=>
int(50)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
}
["location"]=>
object(Peast\Syntax\SourceLocation)#11 (2) {
["start"]=>
object(Peast\Syntax\Position)#9 (3) {
["line":protected]=>
int(1)
["column":protected]=>
int(0)
["index":protected]=>
int(0)
}
["end"]=>
object(Peast\Syntax\Position)#49 (3) {
["line":protected]=>
int(3)
["column":protected]=>
int(2)
["index":protected]=>
int(50)
}
}
["leadingComments":protected]=>
array(0) {
}
["trailingComments":protected]=>
array(0) {
}
}
from peast.
Hi @mck89 thanks for the quick fix. Confirming that it's now working as expected. Are you planning to publish the fix in a patch release?
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
- Peast cannot parse comma expression in assignment expression prior to ES8 (ES2017) HOT 7
- 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.