Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider Javascript automatic semicolon insertion #635

Open
ElianCordoba opened this issue Feb 3, 2024 · 3 comments
Open

Consider Javascript automatic semicolon insertion #635

ElianCordoba opened this issue Feb 3, 2024 · 3 comments
Labels
bug Something isn't working diffing triaged

Comments

@ElianCordoba
Copy link

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.

@croconut
Copy link

croconut commented Feb 14, 2024

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

@Wilfred Wilfred added bug Something isn't working upstream-parser triaged labels Feb 19, 2024
@Wilfred
Copy link
Owner

Wilfred commented Feb 19, 2024

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.

@Wilfred
Copy link
Owner

Wilfred commented Feb 20, 2024

This is probably the same root issue as #587.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working diffing triaged
Projects
None yet
Development

No branches or pull requests

3 participants