JS's funny semicolon insertion can cause non-obvious bugs.
function foo() {
return
1
}
returns undefined
.
For this reason, it's considered best practice to explicitly end statements with a semicolon.
It would be nice if js-beautify did this.
In this case, it would format it as
function foo() {
return;
1;
}
(FYI, uglifyjs -b does exactly this.)
Out of scope, sorry.
The beautifier is designed to be purely a code reformatter, it modifies only white space and does no folding or modifying of the code itself.
I might disagree with with whitespace categorically being "not code" and everything else being "code".
The presence and type of whitespace can alter the behavior of program as much as a semicolon. (e.g. placing a newline in return 1
is highly significant, just as placing a semicolon.)
But I'll concede that this would be non-trivially different than what js-beautify does now :(
Most helpful comment
I might disagree with with whitespace categorically being "not code" and everything else being "code".
The presence and type of whitespace can alter the behavior of program as much as a semicolon. (e.g. placing a newline in
return 1
is highly significant, just as placing a semicolon.)But I'll concede that this would be non-trivially different than what js-beautify does now :(