Skip to content

Commit

Permalink
Fixed bug when parsing sequence expressions using older ES versions. F…
Browse files Browse the repository at this point in the history
…ixes #65
  • Loading branch information
mck89 committed Jan 11, 2024
1 parent 81b2bae commit 63dee90
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

#### 1.16.0
* Implemented ES2024 parser, no new syntax features have been introduced
* Fixed bug when parsing sequence expressions using older ES versions

#### 1.15.4
* Fixed rendering of `let` and `const` inside `switch` cases that always require brackets
Expand Down
7 changes: 6 additions & 1 deletion lib/Peast/Syntax/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1609,9 +1609,14 @@ protected function parseFormalParameterList()
break;
}
}
//Check if it ends with a comma, then check if the comma is a trailing comma,
//in that case throw an error if the trailing comma feature is not enabled
if ($hasComma &&
!$this->features->trailingCommaFunctionCallDeclaration) {
$this->error();
$token = $this->scanner->getToken();
if ($token && $token->value === ")") {
$this->error();
}
}
return $list;
}
Expand Down
5 changes: 5 additions & 0 deletions test/Peast/Syntax/ES2015/files/Misc/Sequence2.Render.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(a = 1, 2);
/**************************************************/
(a=1,2);
/**************************************************/
( a = 1, 2 );
130 changes: 130 additions & 0 deletions test/Peast/Syntax/ES2015/files/Misc/Sequence2.Tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
[
{
"type": "Punctuator",
"value": "(",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 1,
"index": 1
}
}
},
{
"type": "Identifier",
"value": "a",
"location": {
"start": {
"line": 1,
"column": 1,
"index": 1
},
"end": {
"line": 1,
"column": 2,
"index": 2
}
}
},
{
"type": "Punctuator",
"value": "=",
"location": {
"start": {
"line": 1,
"column": 2,
"index": 2
},
"end": {
"line": 1,
"column": 3,
"index": 3
}
}
},
{
"type": "Numeric",
"value": "1",
"location": {
"start": {
"line": 1,
"column": 3,
"index": 3
},
"end": {
"line": 1,
"column": 4,
"index": 4
}
}
},
{
"type": "Punctuator",
"value": ",",
"location": {
"start": {
"line": 1,
"column": 4,
"index": 4
},
"end": {
"line": 1,
"column": 5,
"index": 5
}
}
},
{
"type": "Numeric",
"value": "2",
"location": {
"start": {
"line": 1,
"column": 5,
"index": 5
},
"end": {
"line": 1,
"column": 6,
"index": 6
}
}
},
{
"type": "Punctuator",
"value": ")",
"location": {
"start": {
"line": 1,
"column": 6,
"index": 6
},
"end": {
"line": 1,
"column": 7,
"index": 7
}
}
},
{
"type": "Punctuator",
"value": ";",
"location": {
"start": {
"line": 1,
"column": 7,
"index": 7
},
"end": {
"line": 1,
"column": 8,
"index": 8
}
}
}
]
1 change: 1 addition & 0 deletions test/Peast/Syntax/ES2015/files/Misc/Sequence2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(a=1,2);
150 changes: 150 additions & 0 deletions test/Peast/Syntax/ES2015/files/Misc/Sequence2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"type": "Program",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 8,
"index": 8
}
},
"leadingComments": [],
"trailingComments": [],
"body": [
{
"type": "ExpressionStatement",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 8,
"index": 8
}
},
"leadingComments": [],
"trailingComments": [],
"expression": {
"type": "ParenthesizedExpression",
"location": {
"start": {
"line": 1,
"column": 0,
"index": 0
},
"end": {
"line": 1,
"column": 7,
"index": 7
}
},
"leadingComments": [],
"trailingComments": [],
"expression": {
"type": "SequenceExpression",
"location": {
"start": {
"line": 1,
"column": 1,
"index": 1
},
"end": {
"line": 1,
"column": 6,
"index": 6
}
},
"leadingComments": [],
"trailingComments": [],
"expressions": [
{
"type": "AssignmentExpression",
"location": {
"start": {
"line": 1,
"column": 1,
"index": 1
},
"end": {
"line": 1,
"column": 4,
"index": 4
}
},
"leadingComments": [],
"trailingComments": [],
"left": {
"type": "Identifier",
"location": {
"start": {
"line": 1,
"column": 1,
"index": 1
},
"end": {
"line": 1,
"column": 2,
"index": 2
}
},
"leadingComments": [],
"trailingComments": [],
"name": "a",
"rawName": "a"
},
"operator": "=",
"right": {
"type": "Literal",
"location": {
"start": {
"line": 1,
"column": 3,
"index": 3
},
"end": {
"line": 1,
"column": 4,
"index": 4
}
},
"leadingComments": [],
"trailingComments": [],
"value": 1,
"raw": "1",
"format": "decimal"
}
},
{
"type": "Literal",
"location": {
"start": {
"line": 1,
"column": 5,
"index": 5
},
"end": {
"line": 1,
"column": 6,
"index": 6
}
},
"leadingComments": [],
"trailingComments": [],
"value": 2,
"raw": "2",
"format": "decimal"
}
]
}
}
}
],
"sourceType": "script"
}

0 comments on commit 63dee90

Please sign in to comment.