Avoid adding extra newlines when formating jsonata

Fixes #2472
This commit is contained in:
Nick O'Leary 2020-02-24 11:41:27 +00:00
parent 3f86fd7176
commit 40c3099e4e
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 3 additions and 3 deletions

View File

@ -59,8 +59,8 @@
stack.pop(); stack.pop();
} }
} }
} }
// console.log(stack); // console.log(stack);
var result = str; var result = str;
var indent = 0; var indent = 0;
@ -83,7 +83,7 @@
pre = result.substring(0,offset+f.pos+1); pre = result.substring(0,offset+f.pos+1);
post = result.substring(offset+f.pos+1); post = result.substring(offset+f.pos+1);
indented = indentLine(post,indent); indented = indentLine(post,indent);
result = pre+"\n"+indented; result = pre+(/\n$/.test(pre)?"":"\n")+indented;
offset += indented.length-post.length+1; offset += indented.length-post.length+1;
} else { } else {
longStack.push(false); longStack.push(false);
@ -94,7 +94,7 @@
pre = result.substring(0,offset+f.pos); pre = result.substring(0,offset+f.pos);
post = result.substring(offset+f.pos); post = result.substring(offset+f.pos);
indented = indentLine(post,indent); indented = indentLine(post,indent);
result = pre+"\n"+indented; result = pre+(/\n$/.test(pre)?"":"\n")+indented;
offset += indented.length-post.length+1; offset += indented.length-post.length+1;
} }
longStack.pop(); longStack.pop();