Skip to content

Commit 68c3845

Browse files
committed
WIP
1 parent aada856 commit 68c3845

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/handlers.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @import { TSESTree } from '@typescript-eslint/types' */
2-
/** @import { Chunk, Command, Dedent, Handlers, Indent, Newline, NodeWithComments, Sequence, State, TypeAnnotationNodes } from './types' */
2+
/** @import { Chunk, Command, Dedent, Handlers, Indent, Newline, NodeWithComments, State, TypeAnnotationNodes } from './types' */
33

44
/** @type {Newline} */
55
const newline = { type: 'Newline' };
@@ -30,11 +30,10 @@ function measure(commands, from, to = commands.length) {
3030
const command = commands[i];
3131
if (typeof command === 'string') {
3232
total += command.length;
33+
} else if (Array.isArray(command)) {
34+
total += measure(command, 0, command.length);
3335
} else if (command.type === 'Chunk') {
3436
total += command.content.length;
35-
} else if (command.type === 'Sequence') {
36-
// assume this is ', '
37-
total += 2;
3837
}
3938
}
4039

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ export function print(node, opts = {}) {
7979
return;
8080
}
8181

82+
if (Array.isArray(command)) {
83+
for (let i = 0; i < command.length; i += 1) {
84+
run(command[i]);
85+
}
86+
return;
87+
}
88+
8289
switch (command.type) {
8390
case 'Chunk':
8491
const loc = command.loc;

src/types.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,12 @@ export interface IndentChange {
6464
offset: number;
6565
}
6666

67-
export interface Sequence {
68-
type: 'Sequence';
69-
children: Command[];
70-
}
71-
7267
export interface CommentChunk {
7368
type: 'Comment';
7469
comment: TSESTree.Comment;
7570
}
7671

77-
export type Command = string | Chunk | Newline | Indent | Dedent | Sequence | CommentChunk;
72+
export type Command = string | Chunk | Newline | Indent | Dedent | CommentChunk | Command[];
7873

7974
export interface PrintOptions {
8075
sourceMapSource?: string;

0 commit comments

Comments
 (0)