Debian Codegraph @

packages/babel-parser/typings/babel-parser.source.d.ts

raw
1 // Type definitions for @babel/parser
2 // Project: https://github.com/babel/babel/tree/main/packages/babel-parser
3 // Definitions by: Troy Gerwien <https://github.com/yortus>
4 // Marvin Hagemeister <https://github.com/marvinhagemeister>
5 // Avi Vahl <https://github.com/AviVahl>
6 // TypeScript Version: 2.9
7
8 /**
9 * Parse the provided code as an entire ECMAScript program.
10 */
11 export function parse(
12 input: string,
13 options?: ParserOptions
14 ): ParseResult<import("@babel/types").File>;
15
16 /**
17 * Parse the provided code as a single expression.
18 */
19 export function parseExpression(
20 input: string,
21 options?: ParserOptions
22 ): ParseResult<import("@babel/types").Expression>;
23
24 export interface ParserOptions {
25 /**
26 * By default, import and export declarations can only appear at a program's top level.
27 * Setting this option to true allows them anywhere where a statement is allowed.
28 */
29 allowImportExportEverywhere?: boolean;
30
31 /**
32 * By default, await use is not allowed outside of an async function.
33 * Set this to true to accept such code.
34 */
35 allowAwaitOutsideFunction?: boolean;
36
37 /**
38 * By default, a return statement at the top level raises an error.
39 * Set this to true to accept such code.
40 */
41 allowReturnOutsideFunction?: boolean;
42
43 allowSuperOutsideMethod?: boolean;
44
45 /**
46 * By default, exported identifiers must refer to a declared variable.
47 * Set this to true to allow export statements to reference undeclared variables.
48 */
49 allowUndeclaredExports?: boolean;
50
51 /**
52 * By default, Babel attaches comments to adjacent AST nodes.
53 * When this option is set to false, comments are not attached.
54 * It can provide up to 30% performance improvement when the input code has many comments.
55 * @babel/eslint-parser will set it for you.
56 * It is not recommended to use attachComment: false with Babel transform,
57 * as doing so removes all the comments in output code, and renders annotations such as
58 * /* istanbul ignore next *\/ nonfunctional.
59 */
60 attachComment?: boolean;
61
62 /**
63 * By default, Babel always throws an error when it finds some invalid code.
64 * When this option is set to true, it will store the parsing error and
65 * try to continue parsing the invalid input file.
66 */
67 errorRecovery?: boolean;
68
69 /**
70 * Indicate the mode the code should be parsed in.
71 * Can be one of "script", "module", or "unambiguous". Defaults to "script".
72 * "unambiguous" will make @babel/parser attempt to guess, based on the presence
73 * of ES6 import or export statements.
74 * Files with ES6 imports and exports are considered "module" and are otherwise "script".
75 */
76 sourceType?: "script" | "module" | "unambiguous";
77
78 /**
79 * Correlate output AST nodes with their source filename.
80 * Useful when generating code and source maps from the ASTs of multiple input files.
81 */
82 sourceFilename?: string;
83
84 /**
85 * By default, the first line of code parsed is treated as line 1.
86 * You can provide a line number to alternatively start with.
87 * Useful for integration with other source tools.
88 */
89 startLine?: number;
90
91 /**
92 * By default, the parsed code is treated as if it starts from line 1, column 0.
93 * You can provide a column number to alternatively start with.
94 * Useful for integration with other source tools.
95 */
96 startColumn?: number;
97
98 /**
99 * Array containing the plugins that you want to enable.
100 */
101 plugins?: ParserPlugin[];
102
103 /**
104 * Should the parser work in strict mode.
105 * Defaults to true if sourceType === 'module'. Otherwise, false.
106 */
107 strictMode?: boolean;
108
109 /**
110 * Adds a ranges property to each node: [node.start, node.end]
111 */
112 ranges?: boolean;
113
114 /**
115 * Adds all parsed tokens to a tokens property on the File node.
116 */
117 tokens?: boolean;
118
119 /**
120 * By default, the parser adds information about parentheses by setting
121 * `extra.parenthesized` to `true` as needed.
122 * When this option is `true` the parser creates `ParenthesizedExpression`
123 * AST nodes instead of using the `extra` property.
124 */
125 createParenthesizedExpressions?: boolean;
126 }
127
128 export type ParserPlugin = import("../src/typings").PluginConfig;
129
130 export type {
131 ParserPluginWithOptions,
132 DecoratorsPluginOptions,
133 PipelineOperatorPluginOptions,
134 RecordAndTuplePluginOptions,
135 FlowPluginOptions,
136 TypeScriptPluginOptions,
137 } from "../src/typings";
138
139 export const tokTypes: {
140 // todo(flow->ts) real token type
141 [name: string]: any;
142 };
143
144 export interface ParseError {
145 code: string;
146 reasonCode: string;
147 }
148
149 export type ParseResult<Result> = Result & {
150 errors: ParseError[];
151 };