language-javascript
language-javascript copied to clipboard
Comments can mess with the resulting ast's semantics
The following code:
function foo() {
return
bar()
}
is properly parsed to the following output:
Right (JSAstProgram [JSFunction 'foo' () (JSBlock [JSReturn ,JSMethodCall (JSIdentifier 'bar',JSArguments ())])])
However, this semantically identical piece of code:
function foo() {
return //
bar()
}
Seems to get parsed to the following:
Right (JSAstProgram [JSFunction 'foo' () (JSBlock [JSReturn JSMemberExpression (JSIdentifier 'bar',JSArguments ()) ])])
Here, the parser is interpreting the code as the function returning the result of bar(), instead of them being separate sentences.