Bail to flat mode on new lines
MODIFY
packages/@romejs/js-formatter/Printer.ts
packages/@romejs/js-formatter/Printer.ts
@@ -111,21 +111,21 @@ function print(token: Token, state: State, options: PrinterOptions): void {
if (typeof token === 'string') {
if (token !== '') {
- // Print pending spaces
- if (state.pendingSpaces.value > 0) {
- write(' '.repeat(state.pendingSpaces.value), state);
- state.pendingSpaces.value = 0;
- }
+ let currentLine = state.generatedLine.value;
- write(token, state);
+ state.buffer.push(token);
- // If the line is too long, break the group if it is possible
- if (
- state.flat &&
- ob1Get0(state.generatedColumn.value) > options.printWidth
- ) {
+ if (state.flat) {
+ // If the line is too long, break the group
+ if (ob1Get0(state.generatedColumn.value) > options.printWidth) {
throw new BreakError();
}
+
+ // If a new line was printed, break the group
+ if (currentLine !== state.generatedLine.value) {
+ throw new BreakError();
+ }
+ }
}
} else {
switch (token.type) {

Bail to flat mode on new lines