add semicolons option in the code generator (default: true)

pass `false` to separate statements with newlines instead of semicolons
This commit is contained in:
Mihai Bazon
2012-10-17 14:51:27 +03:00
parent 8957b3a694
commit 6472f9410e
2 changed files with 17 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ function OutputStream(options) {
beautify : false,
source_map : null,
bracketize : false,
semicolons : true,
comments : false
}, true);
@@ -130,14 +131,23 @@ function OutputStream(options) {
print("\n");
};
var requireSemicolonChars = makePredicate("( [ + * / - , .");
function print(str) {
str = String(str);
var ch = str.charAt(0);
if (might_need_semicolon) {
if (";}".indexOf(ch) < 0 && !/[;]$/.test(last)) {
OUTPUT += ";";
current_col++;
current_pos++;
if (options.semicolons || requireSemicolonChars(ch)) {
OUTPUT += ";";
current_col++;
current_pos++;
} else {
OUTPUT += "\n";
current_pos++;
current_line++;
current_col = 0;
}
if (!options.beautify)
might_need_space = false;
}