add semicolons option in the code generator (default: true)
pass `false` to separate statements with newlines instead of semicolons
This commit is contained in:
@@ -241,6 +241,10 @@ can pass additional arguments that control the code output:
|
|||||||
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
||||||
`do`, `while` or `with` statements, even if their body is a single
|
`do`, `while` or `with` statements, even if their body is a single
|
||||||
statement.
|
statement.
|
||||||
|
- `semicolons` (default `true`) -- separate statements with semicolons. If
|
||||||
|
you pass `false` then whenever possible we will use a newline instead of a
|
||||||
|
semicolon, leading to more readable output of uglified code (size before
|
||||||
|
gzip could be smaller; size after gzip insignificantly larger).
|
||||||
|
|
||||||
### Keeping copyright notices or other comments
|
### Keeping copyright notices or other comments
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ function OutputStream(options) {
|
|||||||
beautify : false,
|
beautify : false,
|
||||||
source_map : null,
|
source_map : null,
|
||||||
bracketize : false,
|
bracketize : false,
|
||||||
|
semicolons : true,
|
||||||
comments : false
|
comments : false
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
@@ -130,14 +131,23 @@ function OutputStream(options) {
|
|||||||
print("\n");
|
print("\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
||||||
|
|
||||||
function print(str) {
|
function print(str) {
|
||||||
str = String(str);
|
str = String(str);
|
||||||
var ch = str.charAt(0);
|
var ch = str.charAt(0);
|
||||||
if (might_need_semicolon) {
|
if (might_need_semicolon) {
|
||||||
if (";}".indexOf(ch) < 0 && !/[;]$/.test(last)) {
|
if (";}".indexOf(ch) < 0 && !/[;]$/.test(last)) {
|
||||||
OUTPUT += ";";
|
if (options.semicolons || requireSemicolonChars(ch)) {
|
||||||
current_col++;
|
OUTPUT += ";";
|
||||||
current_pos++;
|
current_col++;
|
||||||
|
current_pos++;
|
||||||
|
} else {
|
||||||
|
OUTPUT += "\n";
|
||||||
|
current_pos++;
|
||||||
|
current_line++;
|
||||||
|
current_col = 0;
|
||||||
|
}
|
||||||
if (!options.beautify)
|
if (!options.beautify)
|
||||||
might_need_space = false;
|
might_need_space = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user