|
1 | | -import type { PluginList } from "./plugin-utils.ts"; |
| 1 | +import type { Plugin } from "./plugin-utils.ts"; |
2 | 2 |
|
3 | 3 | // A second optional argument can be given to further configure |
4 | 4 | // the parser process. These options are recognized: |
5 | 5 |
|
6 | 6 | export type SourceType = "script" | "module" | "unambiguous"; |
7 | 7 |
|
8 | 8 | export interface Options { |
9 | | - sourceType?: SourceType; |
10 | | - sourceFilename?: string; |
11 | | - startIndex?: number; |
12 | | - startColumn?: number; |
13 | | - startLine?: number; |
| 9 | + /** |
| 10 | + * By default, import and export declarations can only appear at a program's top level. |
| 11 | + * Setting this option to true allows them anywhere where a statement is allowed. |
| 12 | + */ |
| 13 | + allowImportExportEverywhere?: boolean; |
| 14 | + |
| 15 | + /** |
| 16 | + * By default, await use is not allowed outside of an async function. |
| 17 | + * Set this to true to accept such code. |
| 18 | + */ |
14 | 19 | allowAwaitOutsideFunction?: boolean; |
| 20 | + |
| 21 | + /** |
| 22 | + * By default, a return statement at the top level raises an error. |
| 23 | + * Set this to true to accept such code. |
| 24 | + */ |
15 | 25 | allowReturnOutsideFunction?: boolean; |
| 26 | + |
| 27 | + /** |
| 28 | + * By default, new.target use is not allowed outside of a function or class. |
| 29 | + * Set this to true to accept such code. |
| 30 | + */ |
16 | 31 | allowNewTargetOutsideFunction?: boolean; |
17 | | - allowImportExportEverywhere?: boolean; |
| 32 | + |
18 | 33 | allowSuperOutsideMethod?: boolean; |
| 34 | + |
| 35 | + /** |
| 36 | + * By default, exported identifiers must refer to a declared variable. |
| 37 | + * Set this to true to allow export statements to reference undeclared variables. |
| 38 | + */ |
19 | 39 | allowUndeclaredExports?: boolean; |
20 | | - plugins?: PluginList; |
21 | | - strictMode?: boolean | undefined | null; |
| 40 | + |
| 41 | + /** |
| 42 | + * By default, Babel parser JavaScript code according to Annex B syntax. |
| 43 | + * Set this to `false` to disable such behavior. |
| 44 | + */ |
| 45 | + annexB?: boolean; |
| 46 | + |
| 47 | + /** |
| 48 | + * By default, Babel attaches comments to adjacent AST nodes. |
| 49 | + * When this option is set to false, comments are not attached. |
| 50 | + * It can provide up to 30% performance improvement when the input code has many comments. |
| 51 | + * @babel/eslint-parser will set it for you. |
| 52 | + * It is not recommended to use attachComment: false with Babel transform, |
| 53 | + * as doing so removes all the comments in output code, and renders annotations such as |
| 54 | + * /* istanbul ignore next *\/ nonfunctional. |
| 55 | + */ |
| 56 | + attachComment?: boolean; |
| 57 | + |
| 58 | + /** |
| 59 | + * By default, Babel always throws an error when it finds some invalid code. |
| 60 | + * When this option is set to true, it will store the parsing error and |
| 61 | + * try to continue parsing the invalid input file. |
| 62 | + */ |
| 63 | + errorRecovery?: boolean; |
| 64 | + |
| 65 | + /** |
| 66 | + * Indicate the mode the code should be parsed in. |
| 67 | + * Can be one of "script", "module", or "unambiguous". Defaults to "script". |
| 68 | + * "unambiguous" will make @babel/parser attempt to guess, based on the presence |
| 69 | + * of ES6 import or export statements. |
| 70 | + * Files with ES6 imports and exports are considered "module" and are otherwise "script". |
| 71 | + */ |
| 72 | + sourceType?: "script" | "module" | "unambiguous"; |
| 73 | + |
| 74 | + /** |
| 75 | + * Correlate output AST nodes with their source filename. |
| 76 | + * Useful when generating code and source maps from the ASTs of multiple input files. |
| 77 | + */ |
| 78 | + sourceFilename?: string; |
| 79 | + |
| 80 | + /** |
| 81 | + * By default, all source indexes start from 0. |
| 82 | + * You can provide a start index to alternatively start with. |
| 83 | + * Useful for integration with other source tools. |
| 84 | + */ |
| 85 | + startIndex?: number; |
| 86 | + |
| 87 | + /** |
| 88 | + * By default, the first line of code parsed is treated as line 1. |
| 89 | + * You can provide a line number to alternatively start with. |
| 90 | + * Useful for integration with other source tools. |
| 91 | + */ |
| 92 | + startLine?: number; |
| 93 | + |
| 94 | + /** |
| 95 | + * By default, the parsed code is treated as if it starts from line 1, column 0. |
| 96 | + * You can provide a column number to alternatively start with. |
| 97 | + * Useful for integration with other source tools. |
| 98 | + */ |
| 99 | + startColumn?: number; |
| 100 | + |
| 101 | + /** |
| 102 | + * Array containing the plugins that you want to enable. |
| 103 | + */ |
| 104 | + plugins?: Plugin[]; |
| 105 | + |
| 106 | + /** |
| 107 | + * Should the parser work in strict mode. |
| 108 | + * Defaults to true if sourceType === 'module'. Otherwise, false. |
| 109 | + */ |
| 110 | + strictMode?: boolean; |
| 111 | + |
| 112 | + /** |
| 113 | + * Adds a ranges property to each node: [node.start, node.end] |
| 114 | + */ |
22 | 115 | ranges?: boolean; |
| 116 | + |
| 117 | + /** |
| 118 | + * Adds all parsed tokens to a tokens property on the File node. |
| 119 | + */ |
23 | 120 | tokens?: boolean; |
24 | | - createImportExpressions?: boolean; |
| 121 | + |
| 122 | + /** |
| 123 | + * By default, the parser adds information about parentheses by setting |
| 124 | + * `extra.parenthesized` to `true` as needed. |
| 125 | + * When this option is `true` the parser creates `ParenthesizedExpression` |
| 126 | + * AST nodes instead of using the `extra` property. |
| 127 | + */ |
25 | 128 | createParenthesizedExpressions?: boolean; |
26 | | - errorRecovery?: boolean; |
27 | | - attachComment?: boolean; |
28 | | - annexB?: boolean; |
| 129 | + |
| 130 | + /** |
| 131 | + * The default is false in Babel 7 and true in Babel 8 |
| 132 | + * Set this to true to parse it as an `ImportExpression` node. |
| 133 | + * Otherwise `import(foo)` is parsed as `CallExpression(Import, [Identifier(foo)])`. |
| 134 | + */ |
| 135 | + createImportExpressions?: boolean; |
29 | 136 | } |
30 | 137 |
|
31 | 138 | export const enum OptionFlags { |
|
0 commit comments