Skip to content

Commit

Permalink
Fixed parsing of spread operator inside objects defined in arrow func…
Browse files Browse the repository at this point in the history
…tions body. Fixes #38
  • Loading branch information
mck89 committed Jul 11, 2021
1 parent b33fa0d commit 2f5b26f
Show file tree
Hide file tree
Showing 5 changed files with 476 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Peast/Syntax/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,7 @@ protected function parseObjectBindingPattern()
*/
protected function parseRestProperty()
{
$state = $this->scanner->getState();
if ($token = $this->scanner->consume("...")) {

if ($argument = $this->parseIdentifier(static::$bindingIdentifier)) {
Expand All @@ -2914,7 +2915,7 @@ protected function parseRestProperty()
return $this->completeNode($node);
}

$this->error();
$this->scanner->setState($state);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const foo = () => ({
...(void 0)
});
/**************************************************/
const foo=()=>({...(void 0)});
/**************************************************/
const foo = ( ) => ( {
...( void 0 )
} );
258 changes: 258 additions & 0 deletions test/Peast/Syntax/ES2018/files/ObjectBinding/Spread2.Tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
[
{
"type": "Keyword",
"value": "const",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 5,
"index": 5
}
}
},
{
"type": "Identifier",
"value": "foo",
"location": {
"start": {
"line": 1,
"column": 6,
"index": 6
},
"end": {
"line": 1,
"column": 9,
"index": 9
}
}
},
{
"type": "Punctuator",
"value": "=",
"location": {
"start": {
"line": 1,
"column": 10,
"index": 10
},
"end": {
"line": 1,
"column": 11,
"index": 11
}
}
},
{
"type": "Punctuator",
"value": "(",
"location": {
"start": {
"line": 1,
"column": 12,
"index": 12
},
"end": {
"line": 1,
"column": 13,
"index": 13
}
}
},
{
"type": "Punctuator",
"value": ")",
"location": {
"start": {
"line": 1,
"column": 13,
"index": 13
},
"end": {
"line": 1,
"column": 14,
"index": 14
}
}
},
{
"type": "Punctuator",
"value": "=>",
"location": {
"start": {
"line": 1,
"column": 15,
"index": 15
},
"end": {
"line": 1,
"column": 17,
"index": 17
}
}
},
{
"type": "Punctuator",
"value": "(",
"location": {
"start": {
"line": 1,
"column": 18,
"index": 18
},
"end": {
"line": 1,
"column": 19,
"index": 19
}
}
},
{
"type": "Punctuator",
"value": "{",
"location": {
"start": {
"line": 1,
"column": 19,
"index": 19
},
"end": {
"line": 1,
"column": 20,
"index": 20
}
}
},
{
"type": "Punctuator",
"value": "...",
"location": {
"start": {
"line": 1,
"column": 20,
"index": 20
},
"end": {
"line": 1,
"column": 23,
"index": 23
}
}
},
{
"type": "Punctuator",
"value": "(",
"location": {
"start": {
"line": 1,
"column": 23,
"index": 23
},
"end": {
"line": 1,
"column": 24,
"index": 24
}
}
},
{
"type": "Keyword",
"value": "void",
"location": {
"start": {
"line": 1,
"column": 24,
"index": 24
},
"end": {
"line": 1,
"column": 28,
"index": 28
}
}
},
{
"type": "Numeric",
"value": "0",
"location": {
"start": {
"line": 1,
"column": 29,
"index": 29
},
"end": {
"line": 1,
"column": 30,
"index": 30
}
}
},
{
"type": "Punctuator",
"value": ")",
"location": {
"start": {
"line": 1,
"column": 30,
"index": 30
},
"end": {
"line": 1,
"column": 31,
"index": 31
}
}
},
{
"type": "Punctuator",
"value": "}",
"location": {
"start": {
"line": 1,
"column": 31,
"index": 31
},
"end": {
"line": 1,
"column": 32,
"index": 32
}
}
},
{
"type": "Punctuator",
"value": ")",
"location": {
"start": {
"line": 1,
"column": 32,
"index": 32
},
"end": {
"line": 1,
"column": 33,
"index": 33
}
}
},
{
"type": "Punctuator",
"value": ";",
"location": {
"start": {
"line": 1,
"column": 33,
"index": 33
},
"end": {
"line": 1,
"column": 34,
"index": 34
}
}
}
]
1 change: 1 addition & 0 deletions test/Peast/Syntax/ES2018/files/ObjectBinding/Spread2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = () => ({...(void 0)});
Loading

0 comments on commit 2f5b26f

Please sign in to comment.