Remove flatten helper
MODIFY
packages/@romejs/js-formatter/builders/jsx/JSXElement.ts
packages/@romejs/js-formatter/builders/jsx/JSXElement.ts
*/
import Builder from '../../Builder';
-import {Tokens, space, indent, flatten, operator, concat} from '../../tokens';
+import {Tokens, space, indent, operator, concat} from '../../tokens';
import {jsxElement, AnyNode} from '@romejs/js-ast';
export default function JSXElement(builder: Builder, node: AnyNode): Tokens {
@@ -34,10 +34,9 @@ export default function JSXElement(builder: Builder, node: AnyNode): Tokens {
return [
concat(tokens),
operator('>'),
- indent(
- flatten(node.children.map((child) => builder.tokenize(child, node))),
- ),
-
+ indent(node.children.map(
+ (child) => concat(builder.tokenize(child, node)),
+ )),
operator('</'),
concat(builder.tokenize(node.name, node)),
operator('>'),

MODIFY
packages/@romejs/js-formatter/builders/jsx/JSXFragment.ts
packages/@romejs/js-formatter/builders/jsx/JSXFragment.ts
*/
import Builder from '../../Builder';
-import {Tokens, indent, operator, flatten} from '../../tokens';
+import {Tokens, indent, operator, concat} from '../../tokens';
import {jsxFragment, AnyNode} from '@romejs/js-ast';
export default function JSXFragment(builder: Builder, node: AnyNode): Tokens {
@@ -14,9 +14,7 @@ export default function JSXFragment(builder: Builder, node: AnyNode): Tokens {
return [
operator('<>'),
- indent(
- flatten(node.children.map((child) => builder.tokenize(child, node))),
- ),
+ indent(node.children.map((child) => concat(builder.tokenize(child, node)))),
operator('</>'),
];
}

MODIFY
packages/@romejs/js-formatter/builders/regex/RegExpCharSet.ts
packages/@romejs/js-formatter/builders/regex/RegExpCharSet.ts
*/
import Builder from '../../Builder';
-import {Tokens, verbatim, flatten, concat} from '../../tokens';
+import {Tokens, verbatim, concat} from '../../tokens';
import {AnyNode, regExpCharSet} from '@romejs/js-ast';
export default function RegExpCharSet(builder: Builder, node: AnyNode): Tokens {
@@ -20,7 +20,7 @@ export default function RegExpCharSet(builder: Builder, node: AnyNode): Tokens {
return [
concat(tokens),
- concat(flatten(node.body.map((item) => builder.tokenize(item, node)))),
+ concat(node.body.map((item) => concat(builder.tokenize(item, node)))),
verbatim(']'),
];
}

MODIFY
packages/@romejs/js-formatter/builders/regex/RegExpSubExpression.ts
packages/@romejs/js-formatter/builders/regex/RegExpSubExpression.ts
*/
import Builder from '../../Builder';
-import {Tokens, flatten} from '../../tokens';
+import {Tokens, concat} from '../../tokens';
import {
AnyNode,
RegExpSubExpression,
@@ -18,5 +18,5 @@ export default function RegExpSubExpression(
node: AnyNode,
): Tokens {
node = regExpSubExpression.assert(node);
- return flatten(node.body.map((item) => builder.tokenize(item, node)));
+ return node.body.map((item) => concat(builder.tokenize(item, node)));
}

MODIFY
packages/@romejs/js-formatter/tokens.ts
packages/@romejs/js-formatter/tokens.ts
@@ -238,13 +238,3 @@ export function concat(tokens: Tokens): ConcatToken {
tokens,
};
}
-
-export function flatten(arr: Array<Tokens>): Tokens {
- let tokens: Tokens = [];
-
- for (const elem of arr) {
- tokens = tokens.concat(elem);
- }
-
- return tokens;
-}

Remove flatten helper