add retainLines code generator option

This commit is contained in:
Sebastian McKenzie 2015-04-29 00:20:35 +01:00
parent 433d704739
commit 04766b13f5
3 changed files with 17 additions and 2 deletions

View File

@ -70,7 +70,7 @@ export default class Buffer {
}
newline(i, removeLast) {
if (this.format.compact) return;
if (this.format.compact || this.format.retainLines) return;
if (this.format.concise) {
this.space();
@ -99,7 +99,7 @@ export default class Buffer {
this._newline(removeLast);
}
_newline(removeLast) {
_newline(removeLast, force) {
// never allow more than two lines
if (this.endsWith("\n\n")) return;

View File

@ -34,6 +34,7 @@ class CodeGenerator {
}
var format = {
retainLines: opts.retainLines,
comments: opts.comments == null || opts.comments,
compact: opts.compact,
quotes: CodeGenerator.findCommonStringDelimeter(code, tokens),
@ -149,6 +150,13 @@ class CodeGenerator {
print(node, parent, opts = {}) {
if (!node) return;
// catch up to this nodes newline if we're behind
if (node.loc && this.format.retainLines) {
while (this.position.line < node.loc.start.line) {
this._push("\n");
}
}
if (parent && parent._compact) {
node._compact = true;
}

View File

@ -25,6 +25,13 @@
"type": "string"
},
"retainLines": {
"hidden": true,
"type": "boolean",
"default": false,
"description": "retain line numbers - will result in really ugly code"
},
"nonStandard": {
"type": "boolean",
"default": true,