From 4c1a7b1082ae9ebe2211b61c6b7919115682c4eb Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 18 Jan 2017 12:13:50 -0800 Subject: [PATCH] Introduce second argument to ifBreak (#302) --- src/pp.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/pp.js b/src/pp.js index df76dae4..4a85a446 100644 --- a/src/pp.js +++ b/src/pp.js @@ -51,8 +51,15 @@ function conditionalGroup(states, opts) { ); } -function ifBreak(contents) { - return { type: "if-break", contents }; +function ifBreak(breakContents, flatContents) { + if (breakContents) { + assertDoc(breakContents); + } + if (flatContents) { + assertDoc(flatContents); + } + + return { type: "if-break", breakContents, flatContents }; } function iterDoc(topDoc, func) { @@ -78,6 +85,13 @@ function iterDoc(topDoc, func) { for (var i = doc.parts.length - 1; i >= 0; i--) { docs.push(doc.parts[i]); } + } else if (doc.type === "if-break") { + if (doc.breakContents) { + docs.push(doc.breakContents); + } + if (doc.flatContents) { + docs.push(doc.flatContents); + } } else if (doc.type !== "line") { docs.push(doc.contents); } @@ -175,7 +189,14 @@ function fits(next, restCommands, width) { break; case "if-break": if (mode === MODE_BREAK) { - cmds.push([ ind, mode, doc.contents ]); + if (doc.breakContents) { + cmds.push([ ind, mode, doc.breakContents ]); + } + } + if (mode === MODE_FLAT) { + if (doc.flatContents) { + cmds.push([ ind, mode, doc.flatContents ]); + } } break; @@ -297,7 +318,14 @@ function print(w, doc) { break; case "if-break": if (mode === MODE_BREAK) { - cmds.push([ ind, MODE_BREAK, doc.contents ]); + if (doc.breakContents) { + cmds.push([ ind, mode, doc.breakContents ]); + } + } + if (mode === MODE_FLAT) { + if (doc.flatContents) { + cmds.push([ ind, mode, doc.flatContents ]); + } } break;