Skip to content

Commit

Permalink
(fix) replace flatMap (node 11+) with flatten util (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Sep 3, 2020
1 parent b95b1e3 commit 9382490
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/print/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ export function isPreTagContent(path: FastPath): boolean {
(node.type === 'Attribute' && !formattableAttributes.includes(node.name)),
);
}

export function flatten<T>(arrays: T[][]): T[] {
return ([] as T[]).concat.apply([], arrays);
}
12 changes: 7 additions & 5 deletions src/print/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastPath, Doc, doc, ParserOptions } from 'prettier';
import { Node, IfBlockNode, AttributeNode } from './nodes';
import { isASTNode, isPreTagContent } from './helpers';
import { isASTNode, isPreTagContent, flatten } from './helpers';
import { extractAttributes } from '../lib/extractAttributes';
import { getText } from '../lib/getText';
import { parseSortOrder, SortOrderPart } from '../options';
Expand Down Expand Up @@ -104,10 +104,12 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
if (ignoreNext && (node.type !== 'Text' || !isEmptyNode(node))) {
ignoreNext = false;
return concat(
options.originalText
.slice(options.locStart(node), options.locEnd(node))
.split('\n')
.flatMap((o, i) => (i == 0 ? o : [literalline, o])),
flatten(
options.originalText
.slice(options.locStart(node), options.locEnd(node))
.split('\n')
.map((o, i) => (i == 0 ? [o] : [literalline, o])),
),
);
}

Expand Down

0 comments on commit 9382490

Please sign in to comment.