[#1718][JsLIGO]: Fix automatic semicolon insertion for if-else statements
Motivation and Context
There was a bug in JsLIGO ASI where we would add a semi-colon after )
& else
if there was a \n
(new-line character) after them.
this is syntax error for valid JS/TS code like
...
if (cond); <- inserted by ASI
return value
...
Description
This MR fix the issue by detecting the above mentioned cases & not adding a semi-colon in those cases.
Fixes #1718 (closed)
Component
-
compiler -
website -
webide -
vscode-plugin -
debugger
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
For a JsLIGO file like
export const foo = (b: bool) => {
if (b)
return 42
else
return 21
}
Before
$ ligo.62 compile expression jsligo foo --init-file y.jsligo
File "y.jsligo", line 2, characters 9-8:
1 | export const foo = (b: bool) => {
2 | if (b) \n
3 | return 42
Ill-formed conditional statement.
At this point, the statement executed when the condition is true is
expected.
After
$ ligo compile expression jsligo foo --init-file y.jsligo
{ IF { PUSH int 42 } { PUSH int 21 } }
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha