Skip to content

Commit bc17b6d

Browse files
committed
move token types to tokens.ts
1 parent 337c590 commit bc17b6d

File tree

3 files changed

+109
-95
lines changed

3 files changed

+109
-95
lines changed

apps/oxlint/src-js/index.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,28 @@ export type {
2020
} from './plugins/scope.ts';
2121
export type { Settings } from './plugins/settings.ts';
2222
export type { SourceCode } from './plugins/source_code.ts';
23-
export type { CountOptions, FilterFn, RangeOptions, SkipOptions } from './plugins/tokens.ts';
23+
export type {
24+
CountOptions,
25+
FilterFn,
26+
RangeOptions,
27+
SkipOptions,
28+
Token,
29+
BooleanToken,
30+
CommentToken,
31+
BlockCommentToken,
32+
LineCommentToken,
33+
IdentifierToken,
34+
JSXIdentifierToken,
35+
JSXTextToken,
36+
KeywordToken,
37+
NullToken,
38+
NumericToken,
39+
PrivateIdentifierToken,
40+
PunctuatorToken,
41+
RegularExpressionToken,
42+
StringToken,
43+
TemplateToken,
44+
} from './plugins/tokens.ts';
2445
export type {
2546
RuleMeta,
2647
RuleDocs,
@@ -30,16 +51,7 @@ export type {
3051
RuleReplacedByExternalSpecifier,
3152
} from './plugins/rule_meta.ts';
3253
export type { LineColumn, Location, Range, Ranged, Span } from './plugins/location.ts';
33-
export type {
34-
AfterHook,
35-
BeforeHook,
36-
Comment,
37-
Node,
38-
NodeOrToken,
39-
Token,
40-
Visitor,
41-
VisitorWithHooks,
42-
} from './plugins/types.ts';
54+
export type { AfterHook, BeforeHook, Comment, Node, NodeOrToken, Visitor, VisitorWithHooks } from './plugins/types.ts';
4355

4456
const {
4557
defineProperty,

apps/oxlint/src-js/plugins/tokens.ts

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import { parse } from '@typescript-eslint/typescript-estree';
55
import { sourceText, initSourceText } from './source_code.js';
66

7-
import type { Comment, Node, NodeOrToken, Token } from './types.ts';
7+
import type { Comment, Node, NodeOrToken } from './types.ts';
8+
import type { Span } from './location.ts';
89

910
/**
1011
* Options for various `SourceCode` methods e.g. `getFirstToken`.
@@ -43,6 +44,89 @@ export interface RangeOptions {
4344
*/
4445
export type FilterFn = (token: Token) => boolean;
4546

47+
// AST token type.
48+
export type Token =
49+
| BooleanToken
50+
| CommentToken
51+
| IdentifierToken
52+
| JSXIdentifierToken
53+
| JSXTextToken
54+
| KeywordToken
55+
| NullToken
56+
| NumericToken
57+
| PrivateIdentifierToken
58+
| PunctuatorToken
59+
| RegularExpressionToken
60+
| StringToken
61+
| TemplateToken;
62+
63+
interface BaseToken extends Omit<Span, 'start' | 'end'> {
64+
type: Token['type'];
65+
value: string;
66+
}
67+
68+
export interface BooleanToken extends BaseToken {
69+
type: 'Boolean';
70+
}
71+
72+
export type CommentToken = BlockCommentToken | LineCommentToken;
73+
74+
export interface BlockCommentToken extends BaseToken {
75+
type: 'Block';
76+
}
77+
78+
export interface LineCommentToken extends BaseToken {
79+
type: 'Line';
80+
}
81+
82+
export interface IdentifierToken extends BaseToken {
83+
type: 'Identifier';
84+
}
85+
86+
export interface JSXIdentifierToken extends BaseToken {
87+
type: 'JSXIdentifier';
88+
}
89+
90+
export interface JSXTextToken extends BaseToken {
91+
type: 'JSXText';
92+
}
93+
94+
export interface KeywordToken extends BaseToken {
95+
type: 'Keyword';
96+
}
97+
98+
export interface NullToken extends BaseToken {
99+
type: 'Null';
100+
}
101+
102+
export interface NumericToken extends BaseToken {
103+
type: 'Numeric';
104+
}
105+
106+
export interface PrivateIdentifierToken extends BaseToken {
107+
type: 'PrivateIdentifier';
108+
}
109+
110+
export interface PunctuatorToken extends BaseToken {
111+
type: 'Punctuator';
112+
}
113+
114+
export interface RegularExpressionToken extends BaseToken {
115+
type: 'RegularExpression';
116+
regex: {
117+
flags: string;
118+
pattern: string;
119+
};
120+
}
121+
122+
export interface StringToken extends BaseToken {
123+
type: 'String';
124+
}
125+
126+
export interface TemplateToken extends BaseToken {
127+
type: 'Template';
128+
}
129+
46130
// Tokens for the current file parsed by TS-ESLint.
47131
// Created lazily only when needed.
48132
let tokens: Token[] | null = null;

apps/oxlint/src-js/plugins/types.ts

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface Visitor {
77
*/
88

99
import type { Span } from './location.ts';
10+
import type { Token } from './tokens.ts';
1011

1112
import type { VisitorObject as Visitor } from '../generated/visitor.d.ts';
1213
export type { Visitor };
@@ -30,89 +31,6 @@ export type VisitFn = (node: Node) => void;
3031
// AST node type.
3132
export interface Node extends Span {}
3233

33-
// AST token type.
34-
export type Token =
35-
| BooleanToken
36-
| CommentToken
37-
| IdentifierToken
38-
| JSXIdentifierToken
39-
| JSXTextToken
40-
| KeywordToken
41-
| NullToken
42-
| NumericToken
43-
| PrivateIdentifierToken
44-
| PunctuatorToken
45-
| RegularExpressionToken
46-
| StringToken
47-
| TemplateToken;
48-
49-
export interface BaseToken extends Omit<Span, 'start' | 'end'> {
50-
type: Token['type'];
51-
value: string;
52-
}
53-
54-
export interface BooleanToken extends BaseToken {
55-
type: 'Boolean';
56-
}
57-
58-
export type CommentToken = BlockCommentToken | LineCommentToken;
59-
60-
export interface BlockCommentToken extends BaseToken {
61-
type: 'Block';
62-
}
63-
64-
export interface LineCommentToken extends BaseToken {
65-
type: 'Line';
66-
}
67-
68-
export interface IdentifierToken extends BaseToken {
69-
type: 'Identifier';
70-
}
71-
72-
export interface JSXIdentifierToken extends BaseToken {
73-
type: 'JSXIdentifier';
74-
}
75-
76-
export interface JSXTextToken extends BaseToken {
77-
type: 'JSXText';
78-
}
79-
80-
export interface KeywordToken extends BaseToken {
81-
type: 'Keyword';
82-
}
83-
84-
export interface NullToken extends BaseToken {
85-
type: 'Null';
86-
}
87-
88-
export interface NumericToken extends BaseToken {
89-
type: 'Numeric';
90-
}
91-
92-
export interface PrivateIdentifierToken extends BaseToken {
93-
type: 'PrivateIdentifier';
94-
}
95-
96-
export interface PunctuatorToken extends BaseToken {
97-
type: 'Punctuator';
98-
}
99-
100-
export interface RegularExpressionToken extends BaseToken {
101-
type: 'RegularExpression';
102-
regex: {
103-
flags: string;
104-
pattern: string;
105-
};
106-
}
107-
108-
export interface StringToken extends BaseToken {
109-
type: 'String';
110-
}
111-
112-
export interface TemplateToken extends BaseToken {
113-
type: 'Template';
114-
}
115-
11634
// Currently we only support `Node`s, but will add support for `Token`s later.
11735
export type NodeOrToken = Node | Token;
11836

0 commit comments

Comments
 (0)