-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Parser.ts
106 lines (100 loc) · 3.14 KB
/
Parser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* eslint-disable @typescript-eslint/no-namespace */
import type { ParserServices, TSESTree } from '../ts-estree';
import type { ParserOptions } from './ParserOptions';
import type { Scope } from './Scope';
export namespace Parser {
export interface ParserMeta {
/**
* The unique name of the parser.
*/
name: string;
/**
* The a string identifying the version of the parser.
*/
version?: string;
}
/**
* A loose definition of the ParserModule type for use with configs
* This type intended to relax validation of configs so that parsers that have
* different AST types or scope managers can still be passed to configs
*
* @see {@link LooseRuleDefinition}, {@link LooseProcessorModule}
*/
export type LooseParserModule =
| {
/**
* Information about the parser to uniquely identify it when serializing.
*/
meta?: Partial<ParserMeta>;
/**
* Parses the given text into an ESTree AST
*/
parse(text: string, options?: unknown): unknown;
}
| {
/**
* Information about the parser to uniquely identify it when serializing.
*/
meta?: Partial<ParserMeta>;
/**
* Parses the given text into an AST
*/
parseForESLint(
text: string,
options?: unknown,
): {
// intentionally not using a Record to preserve optionals
[k in keyof ParseResult]: unknown;
};
};
export type ParserModule =
| {
/**
* Information about the parser to uniquely identify it when serializing.
*/
meta?: ParserMeta;
/**
* Parses the given text into an ESTree AST
*/
parse(text: string, options?: ParserOptions): TSESTree.Program;
}
| {
/**
* Information about the parser to uniquely identify it when serializing.
*/
meta?: ParserMeta;
/**
* Parses the given text into an AST
*/
parseForESLint(text: string, options?: ParserOptions): ParseResult;
};
export interface ParseResult {
/**
* The ESTree AST
*/
ast: TSESTree.Program;
/**
* Any parser-dependent services (such as type checkers for nodes).
* The value of the services property is available to rules as `context.sourceCode.parserServices`.
* The default is an empty object.
*/
services?: ParserServices;
/**
* A `ScopeManager` object.
* Custom parsers can use customized scope analysis for experimental/enhancement syntaxes.
* The default is the `ScopeManager` object which is created by `eslint-scope`.
*/
scopeManager?: Scope.ScopeManager;
/**
* An object to customize AST traversal.
* The keys of the object are the type of AST nodes.
* Each value is an array of the property names which should be traversed.
* The default is `KEYS` of `eslint-visitor-keys`.
*/
visitorKeys?: VisitorKeys;
}
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
export interface VisitorKeys {
[nodeType: string]: readonly string[];
}
}