Handle ConcatToken
MODIFY
packages/@romejs/js-formatter/Printer.ts
packages/@romejs/js-formatter/Printer.ts
@@ -19,6 +19,7 @@ import {
OperatorToken,
VerbatimToken,
PositionMarkerToken,
+ ConcatToken,
} from './tokens';
import {BuilderOptions} from './Builder';
import {
@@ -517,6 +518,7 @@ export default class Printer {
}
break;
+ case 'ConcatToken':
case 'Indent':
case 'PositionMarker':
group = this.findUnbrokenGroupForLinkedGroups(token.tokens);
@@ -584,6 +586,10 @@ export default class Printer {
state.sourceLocation = origSourceLocation;
}
+ printConcatToken(token: ConcatToken) {
+ this.print(token.tokens);
+ }
+
print(tokens: undefined | Tokens, i: number = 0) {
if (tokens === undefined) {
return;
@@ -646,6 +652,10 @@ export default class Printer {
case 'PositionMarker':
this.printPositionMarkerToken(token);
break;
+
+ case 'ConcatToken':
+ this.printConcatToken(token);
+ break;
}
if (abort) {

MODIFY
packages/@romejs/js-formatter/tokens.ts
packages/@romejs/js-formatter/tokens.ts
@@ -94,6 +94,11 @@ export type PositionMarkerToken = {
location: SourceLocation;
};
+export type ConcatToken = {
+ type: 'ConcatToken';
+ tokens: Tokens;
+};
+
export type Token =
| GroupToken
| IndentToken
@@ -107,7 +112,8 @@ export type Token =
| TerminatorlessToken
| CommentToken
| WordToken
- | PositionMarkerToken;
+ | PositionMarkerToken
+ | ConcatToken;
export type Tokens = Array<Token>;
@@ -226,6 +232,13 @@ export function positionMarker(
};
}
+export function concat(tokens: Tokens): ConcatToken {
+ return {
+ type: 'ConcatToken',
+ tokens,
+ };
+}
+
export function flatten(arr: Array<Tokens>): Tokens {
let tokens: Tokens = [];

Handle ConcatToken