UNPKG

6.91 kBTypeScriptView Raw
1import { DebugLevel } from '@typescript-eslint/types';
2import { Program } from 'typescript';
3import { TSESTree, TSNode, TSESTreeToTSNode, TSToken } from './ts-estree';
4import { CanonicalPath } from './create-program/shared';
5declare type DebugModule = 'typescript-eslint' | 'eslint' | 'typescript';
6export interface Extra {
7 code: string;
8 comment: boolean;
9 comments: TSESTree.Comment[];
10 createDefaultProgram: boolean;
11 debugLevel: Set<DebugModule>;
12 errorOnTypeScriptSyntacticAndSemanticIssues: boolean;
13 errorOnUnknownASTType: boolean;
14 EXPERIMENTAL_useSourceOfProjectReferenceRedirect: boolean;
15 extraFileExtensions: string[];
16 filePath: string;
17 jsx: boolean;
18 loc: boolean;
19 log: (message: string) => void;
20 preserveNodeMaps?: boolean;
21 projects: CanonicalPath[];
22 range: boolean;
23 strict: boolean;
24 tokens: null | TSESTree.Token[];
25 tsconfigRootDir: string;
26 useJSXTextNode: boolean;
27}
28interface ParseOptions {
29 /**
30 * create a top-level comments array containing all comments
31 */
32 comment?: boolean;
33 /**
34 * An array of modules to turn explicit debugging on for.
35 * - 'typescript-eslint' is the same as setting the env var `DEBUG=typescript-eslint:*`
36 * - 'eslint' is the same as setting the env var `DEBUG=eslint:*`
37 * - 'typescript' is the same as setting `extendedDiagnostics: true` in your tsconfig compilerOptions
38 *
39 * For convenience, also supports a boolean:
40 * - true === ['typescript-eslint']
41 * - false === []
42 */
43 debugLevel?: DebugLevel;
44 /**
45 * Cause the parser to error if it encounters an unknown AST node type (useful for testing).
46 * This case only usually occurs when TypeScript releases new features.
47 */
48 errorOnUnknownASTType?: boolean;
49 /**
50 * Absolute (or relative to `cwd`) path to the file being parsed.
51 */
52 filePath?: string;
53 /**
54 * Enable parsing of JSX.
55 * For more details, see https://www.typescriptlang.org/docs/handbook/jsx.html
56 *
57 * NOTE: this setting does not effect known file types (.js, .jsx, .ts, .tsx, .json) because the
58 * TypeScript compiler has its own internal handling for known file extensions.
59 *
60 * For the exact behavior, see https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsecmafeaturesjsx
61 */
62 jsx?: boolean;
63 /**
64 * Controls whether the `loc` information to each node.
65 * The `loc` property is an object which contains the exact line/column the node starts/ends on.
66 * This is similar to the `range` property, except it is line/column relative.
67 */
68 loc?: boolean;
69 loggerFn?: ((message: string) => void) | false;
70 /**
71 * Controls whether the `range` property is included on AST nodes.
72 * The `range` property is a [number, number] which indicates the start/end index of the node in the file contents.
73 * This is similar to the `loc` property, except this is the absolute index.
74 */
75 range?: boolean;
76 /**
77 * Set to true to create a top-level array containing all tokens from the file.
78 */
79 tokens?: boolean;
80 useJSXTextNode?: boolean;
81}
82interface ParseAndGenerateServicesOptions extends ParseOptions {
83 /**
84 * Causes the parser to error if the TypeScript compiler returns any unexpected syntax/semantic errors.
85 */
86 errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
87 /**
88 * ***EXPERIMENTAL FLAG*** - Use this at your own risk.
89 *
90 * Causes TS to use the source files for referenced projects instead of the compiled .d.ts files.
91 * This feature is not yet optimized, and is likely to cause OOMs for medium to large projects.
92 *
93 * This flag REQUIRES at least TS v3.9, otherwise it does nothing.
94 *
95 * See: https://github.com/typescript-eslint/typescript-eslint/issues/2094
96 */
97 EXPERIMENTAL_useSourceOfProjectReferenceRedirect?: boolean;
98 /**
99 * When `project` is provided, this controls the non-standard file extensions which will be parsed.
100 * It accepts an array of file extensions, each preceded by a `.`.
101 */
102 extraFileExtensions?: string[];
103 /**
104 * Absolute (or relative to `tsconfigRootDir`) path to the file being parsed.
105 * When `project` is provided, this is required, as it is used to fetch the file from the TypeScript compiler's cache.
106 */
107 filePath?: string;
108 /**
109 * Allows the user to control whether or not two-way AST node maps are preserved
110 * during the AST conversion process.
111 *
112 * By default: the AST node maps are NOT preserved, unless `project` has been specified,
113 * in which case the maps are made available on the returned `parserServices`.
114 *
115 * NOTE: If `preserveNodeMaps` is explicitly set by the user, it will be respected,
116 * regardless of whether or not `project` is in use.
117 */
118 preserveNodeMaps?: boolean;
119 /**
120 * Absolute (or relative to `tsconfigRootDir`) paths to the tsconfig(s).
121 * If this is provided, type information will be returned.
122 */
123 project?: string | string[];
124 /**
125 * If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from
126 * being matched by the globs.
127 * This accepts an array of globs to ignore.
128 *
129 * By default, this is set to ["**\/node_modules/**"]
130 */
131 projectFolderIgnoreList?: string[];
132 /**
133 * The absolute path to the root directory for all provided `project`s.
134 */
135 tsconfigRootDir?: string;
136 /**
137 ***************************************************************************************
138 * IT IS RECOMMENDED THAT YOU DO NOT USE THIS OPTION, AS IT CAUSES PERFORMANCE ISSUES. *
139 ***************************************************************************************
140 *
141 * When passed with `project`, this allows the parser to create a catch-all, default program.
142 * This means that if the parser encounters a file not included in any of the provided `project`s,
143 * it will not error, but will instead parse the file and its dependencies in a new program.
144 */
145 createDefaultProgram?: boolean;
146}
147export declare type TSESTreeOptions = ParseAndGenerateServicesOptions;
148export interface ParserWeakMap<TKey, TValueBase> {
149 get<TValue extends TValueBase>(key: TKey): TValue;
150 has(key: unknown): boolean;
151}
152export interface ParserWeakMapESTreeToTSNode<TKey extends TSESTree.Node = TSESTree.Node> {
153 get<TKeyBase extends TKey>(key: TKeyBase): TSESTreeToTSNode<TKeyBase>;
154 has(key: unknown): boolean;
155}
156export interface ParserServices {
157 program: Program;
158 esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
159 tsNodeToESTreeNodeMap: ParserWeakMap<TSNode | TSToken, TSESTree.Node>;
160 hasFullTypeInformation: boolean;
161}
162export {};
163//# sourceMappingURL=parser-options.d.ts.map
\No newline at end of file