UNPKG

6.72 kBTypeScriptView Raw
1// This file is auto-generated! Do not modify it directly.
2/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */
3import * as _babel_types from '@babel/types';
4
5type Plugin =
6 | "asyncDoExpressions"
7 | "asyncGenerators"
8 | "bigInt"
9 | "classPrivateMethods"
10 | "classPrivateProperties"
11 | "classProperties"
12 | "classStaticBlock" // Enabled by default
13 | "decimal"
14 | "decorators-legacy"
15 | "decoratorAutoAccessors"
16 | "destructuringPrivate"
17 | "doExpressions"
18 | "dynamicImport"
19 | "explicitResourceManagement"
20 | "exportDefaultFrom"
21 | "exportNamespaceFrom" // deprecated
22 | "flow"
23 | "flowComments"
24 | "functionBind"
25 | "functionSent"
26 | "importMeta"
27 | "jsx"
28 | "logicalAssignment"
29 | "importAssertions"
30 | "importReflection"
31 | "moduleBlocks"
32 | "moduleStringNames"
33 | "nullishCoalescingOperator"
34 | "numericSeparator"
35 | "objectRestSpread"
36 | "optionalCatchBinding"
37 | "optionalChaining"
38 | "partialApplication"
39 | "placeholders"
40 | "privateIn" // Enabled by default
41 | "regexpUnicodeSets"
42 | "throwExpressions"
43 | "topLevelAwait"
44 | "v8intrinsic"
45 | ParserPluginWithOptions[0];
46
47type ParserPluginWithOptions =
48 | ["decorators", DecoratorsPluginOptions]
49 | ["estree", { classFeatures?: boolean }]
50 // @deprecated
51 | ["moduleAttributes", { version: "may-2020" }]
52 | ["pipelineOperator", PipelineOperatorPluginOptions]
53 | ["recordAndTuple", RecordAndTuplePluginOptions]
54 | ["flow", FlowPluginOptions]
55 | ["typescript", TypeScriptPluginOptions];
56
57type PluginConfig = Plugin | ParserPluginWithOptions;
58
59interface DecoratorsPluginOptions {
60 decoratorsBeforeExport?: boolean;
61 allowCallParenthesized?: boolean;
62}
63
64interface PipelineOperatorPluginOptions {
65 proposal: "minimal" | "fsharp" | "hack" | "smart";
66 topicToken?: "%" | "#" | "@@" | "^^" | "^";
67}
68
69interface RecordAndTuplePluginOptions {
70 syntaxType: "bar" | "hash";
71}
72
73interface FlowPluginOptions {
74 all?: boolean;
75 enums?: boolean;
76}
77
78interface TypeScriptPluginOptions {
79 dts?: boolean;
80 disallowAmbiguousJSXLike?: boolean;
81}
82
83// Type definitions for @babel/parser
84// Project: https://github.com/babel/babel/tree/main/packages/babel-parser
85// Definitions by: Troy Gerwien <https://github.com/yortus>
86// Marvin Hagemeister <https://github.com/marvinhagemeister>
87// Avi Vahl <https://github.com/AviVahl>
88// TypeScript Version: 2.9
89
90/**
91 * Parse the provided code as an entire ECMAScript program.
92 */
93declare function parse(
94 input: string,
95 options?: ParserOptions
96): ParseResult<_babel_types.File>;
97
98/**
99 * Parse the provided code as a single expression.
100 */
101declare function parseExpression(
102 input: string,
103 options?: ParserOptions
104): ParseResult<_babel_types.Expression>;
105
106interface ParserOptions {
107 /**
108 * By default, import and export declarations can only appear at a program's top level.
109 * Setting this option to true allows them anywhere where a statement is allowed.
110 */
111 allowImportExportEverywhere?: boolean;
112
113 /**
114 * By default, await use is not allowed outside of an async function.
115 * Set this to true to accept such code.
116 */
117 allowAwaitOutsideFunction?: boolean;
118
119 /**
120 * By default, a return statement at the top level raises an error.
121 * Set this to true to accept such code.
122 */
123 allowReturnOutsideFunction?: boolean;
124
125 allowSuperOutsideMethod?: boolean;
126
127 /**
128 * By default, exported identifiers must refer to a declared variable.
129 * Set this to true to allow export statements to reference undeclared variables.
130 */
131 allowUndeclaredExports?: boolean;
132
133 /**
134 * By default, Babel attaches comments to adjacent AST nodes.
135 * When this option is set to false, comments are not attached.
136 * It can provide up to 30% performance improvement when the input code has many comments.
137 * @babel/eslint-parser will set it for you.
138 * It is not recommended to use attachComment: false with Babel transform,
139 * as doing so removes all the comments in output code, and renders annotations such as
140 * /* istanbul ignore next *\/ nonfunctional.
141 */
142 attachComment?: boolean;
143
144 /**
145 * By default, Babel always throws an error when it finds some invalid code.
146 * When this option is set to true, it will store the parsing error and
147 * try to continue parsing the invalid input file.
148 */
149 errorRecovery?: boolean;
150
151 /**
152 * Indicate the mode the code should be parsed in.
153 * Can be one of "script", "module", or "unambiguous". Defaults to "script".
154 * "unambiguous" will make @babel/parser attempt to guess, based on the presence
155 * of ES6 import or export statements.
156 * Files with ES6 imports and exports are considered "module" and are otherwise "script".
157 */
158 sourceType?: "script" | "module" | "unambiguous";
159
160 /**
161 * Correlate output AST nodes with their source filename.
162 * Useful when generating code and source maps from the ASTs of multiple input files.
163 */
164 sourceFilename?: string;
165
166 /**
167 * By default, the first line of code parsed is treated as line 1.
168 * You can provide a line number to alternatively start with.
169 * Useful for integration with other source tools.
170 */
171 startLine?: number;
172
173 /**
174 * By default, the parsed code is treated as if it starts from line 1, column 0.
175 * You can provide a column number to alternatively start with.
176 * Useful for integration with other source tools.
177 */
178 startColumn?: number;
179
180 /**
181 * Array containing the plugins that you want to enable.
182 */
183 plugins?: ParserPlugin[];
184
185 /**
186 * Should the parser work in strict mode.
187 * Defaults to true if sourceType === 'module'. Otherwise, false.
188 */
189 strictMode?: boolean;
190
191 /**
192 * Adds a ranges property to each node: [node.start, node.end]
193 */
194 ranges?: boolean;
195
196 /**
197 * Adds all parsed tokens to a tokens property on the File node.
198 */
199 tokens?: boolean;
200
201 /**
202 * By default, the parser adds information about parentheses by setting
203 * `extra.parenthesized` to `true` as needed.
204 * When this option is `true` the parser creates `ParenthesizedExpression`
205 * AST nodes instead of using the `extra` property.
206 */
207 createParenthesizedExpressions?: boolean;
208}
209
210type ParserPlugin = PluginConfig;
211
212
213declare const tokTypes: {
214 // todo(flow->ts) real token type
215 [name: string]: any;
216};
217
218interface ParseError {
219 code: string;
220 reasonCode: string;
221}
222
223type ParseResult<Result> = Result & {
224 errors: ParseError[];
225};
226
227export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };