language-javascript icon indicating copy to clipboard operation
language-javascript copied to clipboard

Comments can mess with the resulting ast's semantics

Open julian-berbel opened this issue 4 years ago • 0 comments

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.

julian-berbel avatar Nov 30 '21 01:11 julian-berbel