Closed maciejhirsz closed 6 years ago
there is also
x++ + ++y
which the codegen prints as
x+++++y
then, if we try to parse that it becomes a binary expression with the left hand side being a double postfix increment but it should actually be a syntax error
EDIT: I used the web version to test this, so please ignore if it's already fixed on master
Hello @s-coimbra21, I cannot acknowledge the issue with the source x++ + ++y
.
The syntax is also valid JavaScript with the following AST:
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "UpdateExpression",
"operator": "++",
"argument": {
"type": "Identifier",
"name": "x",
"start": 0,
"end": 1
},
"prefix": false,
"start": 0,
"end": 3
},
"right": {
"type": "UpdateExpression",
"operator": "++",
"argument": {
"type": "Identifier",
"name": "y",
"start": 8,
"end": 9
},
"prefix": true,
"start": 6,
"end": 9
},
"start": 0,
"end": 9
},
"start": 0,
"end": 9
}
],
"start": 0,
"end": 9
}
The currently deployed version on http://maciej.codes/ratel-wasm generates the same code again. However, the returned ranges in source differ currently from master.
My apologies, the first snippet parses correctly. The error is the code that is generated from that snippet (x+++++y
) which should be a syntax error but which the ratel parser accepts though it produces an invalid AST (basically it parses (x++)++ + y
)
Ye, there are two issues here, one is not checking validity of left value ((x++)
is an invalid expression for ++
or any assignment operators). Another is that codegen should wrap the middle +
in spaces.
Fixed with #85
and
Should be parsed as
x; ++y;
andx; --y;
respectively. They are currently parsed asx++; y;
andx--; y;