add retainLines code generator option
This commit is contained in:
parent
433d704739
commit
04766b13f5
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user