difftastic
difftastic copied to clipboard
Consider Javascript automatic semicolon insertion
Javascript has a feature called automatic semicolon insertion (ASI in short) that, as the name implies, will insert semicolons, this powers the optionality of semicolon when coding.
This behaviour can produce a change in the behaviour of the code, for example
function test() {
return 1
}
// => 1
// vs
function test() {
return
1
}
// => undefined
This is because the second function gets a semicolon which makes the code look like this
function test() {
return;
1;
};
Difftastic currently outputs this as no changes, but this can be dangerous because the behaviour of the code changed.
to add to this, needing to add semicolons, in general, slows down JS interpreters (the parser needs to find an error, backtrack and attempt to insert a semicolon to recover from the parse error, then it can continue)
i would recommend all semicolons show up in a diff, not just the ones that would change e.g. function results like the above
Oof, I agree this is a bug. Thanks for the report.
It looks to me like a diffing bug, the parser seems to be doing the right thing.
This is probably the same root issue as #587.