Fix broken return-statements for preserve_line and extend with no_empty_line

This commit is contained in:
syranide 2014-05-27 20:48:52 +02:00
parent f101d6429b
commit 86df7d95ff

View File

@ -61,6 +61,7 @@ function OutputStream(options) {
semicolons : true,
comments : false,
preserve_line : false,
no_empty_line : false,
screw_ie8 : false,
preamble : null,
}, true);
@ -69,6 +70,7 @@ function OutputStream(options) {
var current_col = 0;
var current_line = 1;
var current_pos = 0;
var current_line_offset = 0;
var OUTPUT = "";
function to_ascii(str, identifier) {
@ -150,7 +152,9 @@ function OutputStream(options) {
OUTPUT += ";";
current_col++;
current_pos++;
} else {
} else if (!options.preserve_line ||
OUTPUT.substr(-6) !== "return")
{
OUTPUT += "\n";
current_pos++;
current_line++;
@ -165,12 +169,20 @@ function OutputStream(options) {
if (!options.beautify && options.preserve_line && stack[stack.length - 1]) {
var target_line = stack[stack.length - 1].start.line;
while (current_line < target_line) {
while (current_line + current_line_offset < target_line) {
if (OUTPUT.substr(-6) === "return")
break;
OUTPUT += "\n";
current_pos++;
current_line++;
current_col = 0;
might_need_space = false;
if (options.no_empty_line) {
current_line_offset = target_line - current_line;
break;
}
}
}