1 | // Type definitions for @babel/parser
|
2 | // Project: https://github.com/babel/babel/tree/master/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(input: string, options?: ParserOptions): import('). /types'File;
|
12 |
|
13 | /**
|
14 | * Parse the provided code as a single expression.
|
15 | */
|
16 | export function parseExpression(input: string, options?: ParserOptions): import('). /types'Expression;
|
17 |
|
18 | export interface ParserOptions {
|
19 | /**
|
20 | * By default, import and export declarations can only appear at a program's top level.
|
21 | * Setting this option to true allows them anywhere where a statement is allowed.
|
22 | */
|
23 | allowImportExportEverywhere?: boolean;
|
24 |
|
25 | /**
|
26 | * By default, await use is not allowed outside of an async function.
|
27 | * Set this to true to accept such code.
|
28 | */
|
29 | allowAwaitOutsideFunction?: boolean;
|
30 |
|
31 | /**
|
32 | * By default, a return statement at the top level raises an error.
|
33 | * Set this to true to accept such code.
|
34 | */
|
35 | allowReturnOutsideFunction?: boolean;
|
36 |
|
37 | allowSuperOutsideMethod?: boolean;
|
38 |
|
39 | /**
|
40 | * Indicate the mode the code should be parsed in.
|
41 | * Can be one of "script", "module", or "unambiguous". Defaults to "script".
|
42 | * "unambiguous" will make @babel/parser attempt to guess, based on the presence
|
43 | * of ES6 import or export statements.
|
44 | * Files with ES6 imports and exports are considered "module" and are otherwise "script".
|
45 | */
|
46 | sourceType?: 'script' | 'module' | 'unambiguous';
|
47 |
|
48 | /**
|
49 | * Correlate output AST nodes with their source filename.
|
50 | * Useful when generating code and source maps from the ASTs of multiple input files.
|
51 | */
|
52 | sourceFilename?: string;
|
53 |
|
54 | /**
|
55 | * By default, the first line of code parsed is treated as line 1.
|
56 | * You can provide a line number to alternatively start with.
|
57 | * Useful for integration with other source tools.
|
58 | */
|
59 | startLine?: number;
|
60 |
|
61 | /**
|
62 | * Array containing the plugins that you want to enable.
|
63 | */
|
64 | plugins?: ParserPlugin[];
|
65 |
|
66 | /**
|
67 | * Should the parser work in strict mode.
|
68 | * Defaults to true if sourceType === 'module'. Otherwise, false.
|
69 | */
|
70 | strictMode?: boolean;
|
71 |
|
72 | /**
|
73 | * Adds a ranges property to each node: [node.start, node.end]
|
74 | */
|
75 | ranges?: boolean;
|
76 |
|
77 | /**
|
78 | * Adds all parsed tokens to a tokens property on the File node.
|
79 | */
|
80 | tokens?: boolean;
|
81 | }
|
82 |
|
83 | export type ParserPlugin =
|
84 | 'estree' |
|
85 | 'jsx' |
|
86 | 'flow' |
|
87 | 'flowComments' |
|
88 | 'typescript' |
|
89 | 'doExpressions' |
|
90 | 'objectRestSpread' |
|
91 | 'decorators' |
|
92 | 'decorators-legacy' |
|
93 | 'classProperties' |
|
94 | 'classPrivateProperties' |
|
95 | 'classPrivateMethods' |
|
96 | 'exportDefaultFrom' |
|
97 | 'exportNamespaceFrom' |
|
98 | 'asyncGenerators' |
|
99 | 'functionBind' |
|
100 | 'functionSent' |
|
101 | 'dynamicImport' |
|
102 | 'numericSeparator' |
|
103 | 'optionalChaining' |
|
104 | 'importMeta' |
|
105 | 'bigInt' |
|
106 | 'optionalCatchBinding' |
|
107 | 'throwExpressions' |
|
108 | 'pipelineOperator' |
|
109 | 'nullishCoalescingOperator';
|