Skip to content

Commit ef1ed5d

Browse files
committed
tweak
1 parent ed805d8 commit ef1ed5d

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

src/context.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
/** @import { TSESTree } from '@typescript-eslint/types' */
2-
/** @import { Command, Dedent, Visitors, Indent, Newline, Margin } from './types' */
2+
/** @import { Command, Visitors } from './types' */
33

4-
/** @type {Margin} */
5-
export const margin = { type: 'Margin' };
6-
7-
/** @type {Newline} */
8-
export const newline = { type: 'Newline' };
9-
10-
/** @type {Indent} */
11-
export const indent = { type: 'Indent' };
12-
13-
/** @type {Dedent} */
14-
export const dedent = { type: 'Dedent' };
4+
export const margin = 0;
5+
export const newline = 1;
6+
export const indent = 2;
7+
export const dedent = 3;
158

169
export class Context {
1710
#visitors;

src/index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,18 @@ export function print(node, visitors, opts = {}) {
8484
return;
8585
}
8686

87-
switch (command) {
88-
case newline:
87+
if (typeof command === 'number') {
88+
if (command === newline) {
8989
needs_newline = true;
90-
return;
91-
92-
case margin:
90+
} else if (command === margin) {
9391
needs_margin = true;
94-
return;
95-
96-
case indent:
92+
} else if (command === indent) {
9793
current_newline += indent_str;
98-
return;
99-
100-
case dedent:
94+
} else if (command === dedent) {
10195
current_newline = current_newline.slice(0, -indent_str.length);
102-
return;
96+
}
97+
98+
return;
10399
}
104100

105101
if (needs_newline) {

src/types.d.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,12 @@ export interface Location {
4141
column: number;
4242
}
4343

44-
export interface Margin {
45-
type: 'Margin';
46-
}
47-
48-
export interface Newline {
49-
type: 'Newline';
50-
}
51-
52-
export interface Indent {
53-
type: 'Indent';
54-
}
55-
56-
export interface Dedent {
57-
type: 'Dedent';
58-
}
59-
6044
export interface IndentChange {
6145
type: 'IndentChange';
6246
offset: number;
6347
}
6448

65-
export type Command = string | Location | Margin | Newline | Indent | Dedent | Command[];
49+
export type Command = string | number | Location | Command[];
6650

6751
export interface PrintOptions {
6852
sourceMapSource?: string;

0 commit comments

Comments
 (0)