UNPKG

45.7 kBTypeScriptView Raw
1export interface Plugin {
2 (module: Program): Program;
3}
4export declare type ParseOptions = ParserConfig & {
5 comments?: boolean;
6 script?: boolean;
7 /**
8 * Defaults to es3.
9 */
10 target?: JscTarget;
11};
12/**
13 * Programmatic options.
14 */
15export interface Options extends Config {
16 /**
17 * If true, a file is parsed as a script instead of module.
18 */
19 script?: boolean;
20 /**
21 * The working directory that all paths in the programmatic
22 * options will be resolved relative to.
23 *
24 * Defaults to `process.cwd()`.
25 */
26 cwd?: string;
27 caller?: CallerOptions;
28 /** The filename associated with the code currently being compiled,
29 * if there is one. The filename is optional, but not all of Swc's
30 * functionality is available when the filename is unknown, because a
31 * subset of options rely on the filename for their functionality.
32 *
33 * The three primary cases users could run into are:
34 *
35 * - The filename is exposed to plugins. Some plugins may require the
36 * presence of the filename.
37 * - Options like "test", "exclude", and "ignore" require the filename
38 * for string/RegExp matching.
39 * - .swcrc files are loaded relative to the file being compiled.
40 * If this option is omitted, Swc will behave as if swcrc: false has been set.
41 */
42 filename?: string;
43 /**
44 * The initial path that will be processed based on the "rootMode" to
45 * determine the conceptual root folder for the current Swc project.
46 * This is used in two primary cases:
47 *
48 * - The base directory when checking for the default "configFile" value
49 * - The default value for "swcrcRoots".
50 *
51 * Defaults to `opts.cwd`
52 */
53 root?: string;
54 /**
55 * This option, combined with the "root" value, defines how Swc chooses
56 * its project root. The different modes define different ways that Swc
57 * can process the "root" value to get the final project root.
58 *
59 * "root" - Passes the "root" value through as unchanged.
60 * "upward" - Walks upward from the "root" directory, looking for a directory
61 * containinga swc.config.js file, and throws an error if a swc.config.js
62 * is not found.
63 * "upward-optional" - Walk upward from the "root" directory, looking for
64 * a directory containing a swc.config.js file, and falls back to "root"
65 * if a swc.config.js is not found.
66 *
67 *
68 * "root" is the default mode because it avoids the risk that Swc
69 * will accidentally load a swc.config.js that is entirely outside
70 * of the current project folder. If you use "upward-optional",
71 * be aware that it will walk up the directory structure all the
72 * way to the filesystem root, and it is always possible that someone
73 * will have a forgotten swc.config.js in their home directory,
74 * which could cause unexpected errors in your builds.
75 *
76 *
77 * Users with monorepo project structures that run builds/tests on a
78 * per-package basis may well want to use "upward" since monorepos
79 * often have a swc.config.js in the project root. Running Swc
80 * in a monorepo subdirectory without "upward", will cause Swc
81 * to skip loading any swc.config.js files in the project root,
82 * which can lead to unexpected errors and compilation failure.
83 */
84 rootMode?: "root" | "upward" | "upward-optional";
85 /**
86 * The current active environment used during configuration loading.
87 * This value is used as the key when resolving "env" configs,
88 * and is also available inside configuration functions, plugins,
89 * and presets, via the api.env() function.
90 *
91 * Defaults to `process.env.SWC_ENV || process.env.NODE_ENV || "development"`
92 */
93 envName?: string;
94 /**
95 * Defaults to searching for a default `.swcrc` file, but can
96 * be passed the path of any JS or JSON5 config file.
97 *
98 *
99 * NOTE: This option does not affect loading of .swcrc files,
100 * so while it may be tempting to do configFile: "./foo/.swcrc",
101 * it is not recommended. If the given .swcrc is loaded via the
102 * standard file-relative logic, you'll end up loading the same
103 * config file twice, merging it with itself. If you are linking
104 * a specific config file, it is recommended to stick with a
105 * naming scheme that is independent of the "swcrc" name.
106 *
107 * Defaults to `path.resolve(opts.root, ".swcrc")`
108 */
109 configFile?: string | boolean;
110 /**
111 * true will enable searching for configuration files relative to the "filename" provided to Swc.
112 *
113 * A swcrc value passed in the programmatic options will override one set within a configuration file.
114 *
115 * Note: .swcrc files are only loaded if the current "filename" is inside of
116 * a package that matches one of the "swcrcRoots" packages.
117 *
118 *
119 * Defaults to true as long as the filename option has been specificed
120 */
121 swcrc?: boolean;
122 /**
123 * By default, Babel will only search for .babelrc files within the "root" package
124 * because otherwise Babel cannot know if a given .babelrc is meant to be loaded,
125 * or if it's "plugins" and "presets" have even been installed, since the file
126 * being compiled could be inside node_modules, or have been symlinked into the project.
127 *
128 *
129 * This option allows users to provide a list of other packages that should be
130 * considered "root" packages when considering whether to load .babelrc files.
131 *
132 *
133 * For example, a monorepo setup that wishes to allow individual packages
134 * to have their own configs might want to do
135 *
136 *
137 *
138 * Defaults to `opts.root`
139 */
140 swcrcRoots?: boolean | MatchPattern | MatchPattern[];
141 /**
142 * `true` will attempt to load an input sourcemap from the file itself, if it
143 * contains a //# sourceMappingURL=... comment. If no map is found, or the
144 * map fails to load and parse, it will be silently discarded.
145 *
146 * If an object is provided, it will be treated as the source map object itself.
147 *
148 * Defaults to `true`.
149 */
150 inputSourceMap?: boolean | string;
151 /**
152 * - true to generate a sourcemap for the code and include it in the result object.
153 * - "inline" to generate a sourcemap and append it as a data URL to the end of the code, but not include it in the result object.
154 * - "both" is the same as inline, but will include the map in the result object.
155 *
156 * `swc-cli` overloads some of these to also affect how maps are written to disk:
157 *
158 * - true will write the map to a .map file on disk
159 * - "inline" will write the file directly, so it will have a data: containing the map
160 * - "both" will write the file with a data: URL and also a .map.
161 * - Note: These options are bit weird, so it may make the most sense to just use true
162 * and handle the rest in your own code, depending on your use case.
163 */
164 sourceMaps?: boolean | "inline" | "both";
165 /**
166 * The name to use for the file inside the source map object.
167 *
168 * Defaults to `path.basename(opts.filenameRelative)` when available, or `"unknown"`.
169 */
170 sourceFileName?: string;
171 /**
172 * The sourceRoot fields to set in the generated source map, if one is desired.
173 */
174 sourceRoot?: string;
175 plugin?: Plugin;
176 isModule?: boolean;
177}
178export interface CallerOptions {
179 name: string;
180 [key: string]: any;
181}
182export declare type Swcrc = Config | Config[];
183/**
184 * .swcrc
185 */
186export interface Config {
187 /**
188 * Note: The type is string beacuse it follow rust's regex syntax.
189 */
190 test?: string | string[];
191 /**
192 * Note: The type is string beacuse it follow rust's regex syntax.
193 */
194 exclude?: string | string[];
195 env?: EnvConfig;
196 jsc?: JscConfig;
197 module?: ModuleConfig;
198 minify?: boolean;
199}
200/**
201 * Configuration ported from babel-preset-env
202 */
203export interface EnvConfig {
204 mode?: "usage" | "entry";
205 debug?: boolean;
206 dynamicImport?: boolean;
207 loose?: boolean;
208 skip?: string[];
209 include?: string[];
210 exclude?: string[];
211 /**
212 * The version of the used core js.
213 *
214 */
215 coreJs?: string;
216 targets?: any;
217 shippedProposals?: boolean;
218 /**
219 * Enable all trnasforms
220 */
221 forceAllTransforms?: boolean;
222}
223export interface JscConfig {
224 loose?: boolean;
225 /**
226 * Defaults to EsParserConfig
227 */
228 parser?: ParserConfig;
229 transform?: TransformConfig;
230 /**
231 * Use `@swc/helpers` instead of inline helpers.
232 */
233 externalHelpers?: boolean;
234 /**
235 * Defaults to `es3` (which enableds **all** pass).
236 */
237 target?: JscTarget;
238}
239export declare type JscTarget = "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019";
240export declare type ParserConfig = TsParserConfig | EsParserConfig;
241export interface TsParserConfig {
242 syntax: "typescript";
243 /**
244 * Defaults to `false`.
245 */
246 tsx?: boolean;
247 /**
248 * Defaults to `false`.
249 */
250 decorators?: boolean;
251 /**
252 * Defaults to `false`
253 */
254 dynamicImport?: boolean;
255}
256export interface EsParserConfig {
257 syntax: "ecmascript";
258 /**
259 * Defaults to false.
260 */
261 jsx?: boolean;
262 /**
263 * Defaults to `false`.
264 */
265 numericSeparator?: boolean;
266 /**
267 * Defaults to `false`
268 */
269 classPrivateProperty?: boolean;
270 /**
271 * Defaults to `false`
272 */
273 privateMethod?: boolean;
274 /**
275 * Defaults to `false`
276 */
277 classProperty?: boolean;
278 /**
279 * Defaults to `false`
280 */
281 functionBind?: boolean;
282 /**
283 * Defaults to `false`
284 */
285 decorators?: boolean;
286 /**
287 * Defaults to `false`
288 */
289 decoratorsBeforeExport?: boolean;
290 /**
291 * Defaults to `false`
292 */
293 dynamicImport?: boolean;
294 /**
295 * Defaults to `false`
296 */
297 nullishCoalescing?: boolean;
298}
299/**
300 * Options for trasnform.
301 */
302export interface TransformConfig {
303 /**
304 * Effective only if `syntax` supports ƒ.
305 */
306 react?: ReactConfig;
307 constModules?: ConstModulesConfig;
308 /**
309 * Defaults to null, which skips optimizer pass.
310 */
311 optimizer?: OptimizerConfig;
312}
313export interface ReactConfig {
314 /**
315 * Replace the function used when compiling JSX expressions.
316 *
317 * Defaults to `React.createElement`.
318 */
319 pragma: String;
320 /**
321 * Replace the component used when compiling JSX fragments.
322 *
323 * Defaults to `React.Fragment`
324 */
325 pragmaFrag: String;
326 /**
327 * Toggles whether or not to throw an error if a XML namespaced tag name is used. For example:
328 * `<f:image />`
329 *
330 * Though the JSX spec allows this, it is disabled by default since React's
331 * JSX does not currently have support for it.
332 *
333 */
334 throwIfNamespace: boolean;
335 /**
336 * Toggles plugins that aid in development, such as @swc/plugin-transform-react-jsx-self
337 * and @swc/plugin-transform-react-jsx-source.
338 *
339 * Defaults to `false`,
340 *
341 */
342 development: boolean;
343 /**
344 * Use `Object.assign()` instead of `_extends`. Defaults to false.
345 */
346 useBuiltins: boolean;
347}
348/**
349 * - `import { DEBUG } from '@ember/env-flags';`
350 * - `import { FEATURE_A, FEATURE_B } from '@ember/features';`
351 *
352 * See: https://github.com/swc-project/swc/issues/18#issuecomment-466272558
353 */
354export interface ConstModulesConfig {
355 globals?: {
356 [module: string]: {
357 [name: string]: string;
358 };
359 };
360}
361export interface OptimizerConfig {
362 globals?: GlobalPassOption;
363}
364/**
365 * Options for inline-global pass.
366 */
367export interface GlobalPassOption {
368 /**
369 * Global variables.
370 *
371 * e.g. `{ __DEBUG__: true }`
372 */
373 vars?: {
374 [key: string]: string;
375 };
376 /**
377 * Name of environment variables to inline.
378 *
379 * Defaults to `["NODE_ENV", "SWC_ENV"]`
380 */
381 envs?: string[];
382}
383export declare type ModuleConfig = CommonJsConfig | UmdConfig | AmdConfig;
384export interface BaseModuleConfig {
385 /**
386 * By default, when using exports with babel a non-enumerable `__esModule`
387 * property is exported. In some cases this property is used to determine
388 * if the import is the default export or if it contains the default export.
389 *
390 * In order to prevent the __esModule property from being exported, you
391 * can set the strict option to true.
392 *
393 * Defaults to `false`.
394 */
395 strict?: boolean;
396 /**
397 * Emits 'use strict' directive.
398 *
399 * Defaults to `true`.
400 */
401 strict_mode?: boolean;
402 /**
403 * Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.
404 *
405 * This can improve initial load time of your module because evaluating dependencies up
406 * front is sometimes entirely un-necessary. This is especially the case when implementing
407 * a library module.
408 *
409 *
410 * The value of `lazy` has a few possible effects:
411 *
412 * - `false` - No lazy initialization of any imported module.
413 * - `true` - Do not lazy-initialize local `./foo` imports, but lazy-init `foo` dependencies.
414 *
415 * Local paths are much more likely to have circular dependencies, which may break if loaded lazily,
416 * so they are not lazy by default, whereas dependencies between independent modules are rarely cyclical.
417 *
418 * - `Array<string>` - Lazy-initialize all imports with source matching one of the given strings.
419 *
420 * -----
421 *
422 * The two cases where imports can never be lazy are:
423 *
424 * - `import "foo";`
425 *
426 * Side-effect imports are automatically non-lazy since their very existence means
427 * that there is no binding to later kick off initialization.
428 *
429 * - `export * from "foo"`
430 *
431 * Re-exporting all names requires up-front execution because otherwise there is no
432 * way to know what names need to be exported.
433 *
434 * Defaults to `false`.
435 */
436 lazy?: boolean | string[];
437 /**
438 * By default, when using exports with swc a non-enumerable __esModule property is exported.
439 * This property is then used to determine if the import is the default export or if
440 * it contains the default export.
441 *
442 * In cases where the auto-unwrapping of default is not needed, you can set the noInterop option
443 * to true to avoid the usage of the interopRequireDefault helper (shown in inline form above).
444 *
445 * Defaults to `false`.
446 */
447 noInterop?: boolean;
448}
449export interface CommonJsConfig extends BaseModuleConfig {
450 type: "commonjs";
451}
452export interface UmdConfig extends BaseModuleConfig {
453 type: "umd";
454 globals?: {
455 [key: string]: string;
456 };
457}
458export interface AmdConfig extends BaseModuleConfig {
459 type: "amd";
460 moduleId: string;
461}
462export interface Output {
463 /**
464 * Transformed code
465 */
466 code: string;
467 /**
468 * Sourcemap (**not** base64 encoded)
469 */
470 map?: string;
471}
472export interface MatchPattern {
473}
474export interface Span {
475 start: number;
476 end: number;
477 ctxt: number;
478}
479export interface Node {
480 type: string;
481}
482export interface HasSpan {
483 span: Span;
484}
485export interface HasDecorator {
486 decorators?: Decorator[];
487}
488export interface Class extends HasSpan, HasDecorator {
489 body: ClassMember[];
490 superClass?: Expression;
491 is_abstract: boolean;
492 typeParams: TsTypeParameterDeclaration;
493 superTypeParams?: TsTypeParameterInstantiation;
494 implements: TsExpressionWithTypeArguments[];
495}
496export declare type ClassMember = Constructor | ClassMethod | PrivateMethod | ClassProperty | PrivateProperty | TsIndexSignature;
497export interface ClassPropertyBase extends Node, HasSpan, HasDecorator {
498 value?: Expression;
499 typeAnnotation?: TsTypeAnnotation;
500 is_static: boolean;
501 computed: boolean;
502 accessibility?: Accessibility;
503 is_abstract: boolean;
504 is_optional: boolean;
505 readonly: boolean;
506 definite: boolean;
507}
508export interface ClassProperty extends ClassPropertyBase {
509 type: "ClassProperty";
510 key: Expression;
511}
512export interface PrivateProperty extends ClassPropertyBase {
513 type: "PrivateProperty";
514 key: PrivateName;
515}
516export interface Param extends Node, HasSpan, HasDecorator {
517 type: 'Parameter';
518 pat: Pattern;
519}
520export interface Constructor extends Node, HasSpan {
521 type: "Constructor";
522 key: PropertyName;
523 params: (Param | TsParameterProperty)[];
524 body: BlockStatement;
525 accessibility?: Accessibility;
526 is_optional: boolean;
527}
528export interface ClassMethodBase extends Node, HasSpan {
529 function: Fn;
530 kind: MethodKind;
531 is_static: boolean;
532 accessibility?: Accessibility;
533 is_abstract: boolean;
534 is_optional: boolean;
535}
536export interface ClassMethod extends ClassMethodBase {
537 type: "ClassMethod";
538 key: PropertyName;
539}
540export interface PrivateMethod extends ClassMethodBase {
541 type: "PrivateMethod";
542 key: PrivateName;
543}
544export interface Decorator extends Node, HasSpan {
545 type: "Decorator";
546 expression: Expression;
547}
548export declare type MethodKind = "method" | "setter" | "getter";
549export declare type Declaration = ClassDeclaration | FunctionDeclaration | VariableDeclaration | TsInterfaceDeclaration | TsTypeAliasDeclaration | TsEnumDeclaration | TsModuleDeclaration;
550export interface FunctionDeclaration extends Fn {
551 type: "FunctionDeclaration";
552 ident: Identifier;
553 declare: boolean;
554}
555export interface ClassDeclaration extends Class, Node {
556 type: "ClassDeclaration";
557 identifier: Identifier;
558 declare: boolean;
559}
560export interface VariableDeclaration extends Node, HasSpan {
561 type: "VariableDeclaration";
562 kind: VariableDeclarationKind;
563 declare: boolean;
564 declarations: VariableDeclarator[];
565}
566export declare type VariableDeclarationKind = "get" | "let" | "const";
567export interface VariableDeclarator extends Node, HasSpan {
568 type: "VariableDeclarator";
569 id: Pattern;
570 init?: Expression;
571 definite: boolean;
572}
573export declare type Expression = ThisExpression | ArrayExpression | ObjectExpression | FunctionExpression | UnaryExpression | UpdateExpression | BinaryExpression | AssignmentExpression | MemberExpression | ConditionalExpression | CallExpression | NewExpression | SequenceExpression | Identifier | Literal | TemplateLiteral | TaggedTemplateExpression | ArrowFunctionExpression | ClassExpression | YieldExpression | MetaProperty | AwaitExpression | ParenthesisExpression | JSXMemberExpression | JSXNamespacedName | JSXEmptyExpression | JSXElement | JSXFragment | TsTypeAssertion | TsNonNullExpression | TsTypeCastExpression | TsAsExpression | PrivateName | OptionalChainingExpression | Invalid;
574interface ExpressionBase extends Node, HasSpan {
575}
576export interface OptionalChainingExpression extends ExpressionBase {
577 type: "OptionalChainingExpression";
578 /**
579 * Call expression or member expression.
580 */
581 expr: Expression;
582}
583export interface ThisExpression extends ExpressionBase {
584 type: "ThisExpression";
585}
586export interface ArrayExpression extends ExpressionBase {
587 type: "ArrayExpression";
588 elements: (Expression | SpreadElement | undefined)[];
589}
590export interface ObjectExpression extends ExpressionBase {
591 type: "ObjectExpression";
592 properties: (Property | SpreadElement)[];
593}
594export interface Argument {
595 spread: Span;
596 expression: Expression;
597}
598export declare type PropertOrSpread = Property | SpreadElement;
599export interface SpreadElement extends Node {
600 type: "SpreadElement";
601 spread: Span;
602 arguments: Expression;
603}
604export interface UnaryExpression extends ExpressionBase {
605 type: "UnaryExpression";
606 operator: UnaryOperator;
607 argument: Expression;
608}
609export interface UpdateExpression extends ExpressionBase {
610 type: "UpdateExpression";
611 operator: UpdateOperator;
612 prefix: boolean;
613 argument: Expression;
614}
615export interface BinaryExpression extends ExpressionBase {
616 type: "BinaryExpression";
617 operator: BinaryOperator;
618 left: Expression;
619 right: Expression;
620}
621export interface FunctionExpression extends Fn, ExpressionBase {
622 type: "FunctionExpression";
623 identifier: Identifier;
624}
625export interface ClassExpression extends Class, ExpressionBase {
626 type: "ClassExpression";
627 identifier: Identifier;
628}
629export interface AssignmentExpression extends ExpressionBase {
630 type: "AssignmentExpression";
631 operator: AssignmentOperator;
632 left: Pattern | Expression;
633 right: Expression;
634}
635export interface MemberExpression extends ExpressionBase {
636 type: "MemberExpression";
637 object: Expression | Super;
638 property: Expression;
639 computed: boolean;
640}
641export interface ConditionalExpression extends ExpressionBase {
642 type: "ConditionalExpression";
643 test: Expression;
644 consequent: Expression;
645 alternate: Expression;
646}
647export interface Super extends Node, HasSpan {
648 type: "Super";
649}
650export interface CallExpression extends ExpressionBase {
651 type: "CallExpression";
652 callee: Expression | Super;
653 arguments: Argument[];
654 typeArguments?: TsTypeParameterInstantiation;
655}
656export interface NewExpression extends ExpressionBase {
657 type: "NewExpression";
658 callee: Expression;
659 arguments: Argument[];
660 typeArguments?: TsTypeParameterInstantiation;
661}
662export interface SequenceExpression extends ExpressionBase {
663 type: "SequenceExpression";
664 expressions: Expression[];
665}
666export interface ArrowFunctionExpression extends ExpressionBase {
667 type: "ArrowFunctionExpression";
668 params: Pattern[];
669 body: BlockStatement | Expression;
670 async: boolean;
671 generator: boolean;
672 typeParameters?: TsTypeParameterDeclaration;
673 returnType?: TsTypeAnnotation;
674}
675export interface YieldExpression extends ExpressionBase {
676 type: "YieldExpression";
677 argument?: Expression;
678 delegate: boolean;
679}
680export interface MetaProperty extends Node {
681 type: "MetaProperty";
682 meta: Identifier;
683 property: Identifier;
684}
685export interface AwaitExpression extends ExpressionBase {
686 type: "AwaitExpression";
687 argument: Expression;
688}
689export interface TplBase {
690 expressions: Expression[];
691 quasis: TemplateElement[];
692}
693export interface TemplateLiteral extends ExpressionBase, TplBase {
694 type: "TemplateLiteral";
695}
696export interface TaggedTemplateExpression extends ExpressionBase, TplBase {
697 type: "TaggedTemplateExpression";
698 tag: Expression;
699 typeParameters: TsTypeParameterInstantiation;
700}
701export interface TemplateElement extends ExpressionBase {
702 type: "TemplateElement";
703 tail: boolean;
704 cooked: StringLiteral;
705 raw: StringLiteral;
706}
707export interface ParenthesisExpression extends ExpressionBase {
708 type: "ParenthesisExpression";
709 expression: Expression;
710}
711export interface Fn extends HasSpan, HasDecorator {
712 params: Param[];
713 body: BlockStatement;
714 generator: boolean;
715 async: boolean;
716 typeParameters?: TsTypeParameterDeclaration;
717 returnType?: TsTypeAnnotation;
718}
719interface PatternBase {
720 typeAnnotation?: TsTypeAnnotation;
721}
722export interface Identifier extends HasSpan, PatternBase {
723 type: "Identifier";
724 value: string;
725 optional: boolean;
726}
727export interface PrivateName extends ExpressionBase {
728 type: "PrivateName";
729 id: Identifier;
730}
731export declare type JSXObject = JSXMemberExpression | Identifier;
732export interface JSXMemberExpression extends Node {
733 type: "JSXMemberExpression";
734 object: JSXObject;
735 property: Identifier;
736}
737/**
738 * XML-based namespace syntax:
739 */
740export interface JSXNamespacedName extends Node {
741 type: "JSXNamespacedName";
742 namespace: Identifier;
743 name: Identifier;
744}
745export interface JSXEmptyExpression extends Node, HasSpan {
746 type: "JSXEmptyExpression";
747}
748export interface JSXExpressionContainer extends Node {
749 type: "JSXExpressionContainer";
750 expression: JSXExpression;
751}
752export declare type JSXExpression = JSXEmptyExpression | Expression;
753export interface JSXSpreadChild extends Node {
754 type: "JSXSpreadChild";
755 expression: Expression;
756}
757export declare type JSXElementName = Identifier | JSXMemberExpression | JSXNamespacedName;
758export interface JSXOpeningElement extends Node, HasSpan {
759 type: "JSXOpeningElement";
760 name: JSXElementName;
761 attrs?: JSXAttributeOrSpread[];
762 selfClosing: boolean;
763 typeArguments?: TsTypeParameterInstantiation;
764}
765export declare type JSXAttributeOrSpread = JSXAttribute | SpreadElement;
766export interface JSXClosingElement extends Node, HasSpan {
767 type: "JSXClosingElement";
768 name: JSXElementName;
769}
770export interface JSXAttribute extends Node, HasSpan {
771 type: "JSXAttribute";
772 name: JSXAttributeName;
773 value?: JSXAttrValue;
774}
775export declare type JSXAttributeName = Identifier | JSXNamespacedName;
776export declare type JSXAttrValue = Literal | JSXExpressionContainer | JSXElement | JSXFragment;
777export interface JSXText extends Node, HasSpan {
778 type: "JSXText";
779 value: string;
780 raw: string;
781}
782export interface JSXElement extends Node, HasSpan {
783 type: "JSXElement";
784 opening: JSXOpeningElement;
785 children: JSXElementChild[];
786 closing?: JSXClosingElement;
787}
788export declare type JSXElementChild = JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment;
789export interface JSXFragment extends Node, HasSpan {
790 type: "JSXFragment";
791 opening: JSXOpeningFragment;
792 children: JSXElementChild[];
793 closing: JSXClosingFragment;
794}
795export interface JSXOpeningFragment extends Node, HasSpan {
796 type: "JSXOpeningFragment";
797}
798export interface JSXClosingFragment extends Node, HasSpan {
799 type: "JSXClosingFragment";
800}
801export declare type Literal = StringLiteral | BooleanLiteral | NullLiteral | NumericLiteral | RegExpLiteral | JSXText;
802export interface StringLiteral extends Node, HasSpan {
803 type: "StringLiteral";
804 value: string;
805 has_escape: boolean;
806}
807export interface BooleanLiteral extends Node, HasSpan {
808 type: "BooleanLiteral";
809 value: boolean;
810}
811export interface NullLiteral extends Node, HasSpan {
812 type: "NullLiteral";
813}
814export interface RegExpLiteral extends Node, HasSpan {
815 type: "RegExpLiteral";
816 pattern: string;
817 flags: string;
818}
819export interface NumericLiteral extends Node, HasSpan {
820 type: "NumericLiteral";
821 value: number;
822}
823export declare type ModuleDeclaration = ImportDeclaration | ExportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportDefaultExpression | ExportAllDeclaration | TsImportEqualsDeclaration | TsExportAssignment | TsNamespaceExportDeclaration;
824export interface ExportDefaultExpression extends Node, HasSpan {
825 type: "ExportDefaultExpression";
826 expression: Expression;
827}
828export interface ExportDeclaration extends Node, HasSpan {
829 type: "ExportDeclaration";
830 declaration: Declaration;
831}
832export interface ImportDeclaration extends Node, HasSpan {
833 type: "ImportDeclaration";
834 specifiers: ImporSpecifier[];
835 source: StringLiteral;
836}
837export declare type ImporSpecifier = ImportDefaultSpecifier | NamedImportSpecifier | ImportNamespaceSpecifier;
838export interface ExportAllDeclaration extends Node, HasSpan {
839 type: "ExportAllDeclaration";
840 source: StringLiteral;
841}
842/**
843 * - `export { foo } from 'mod'`
844 * - `export { foo as bar } from 'mod'`
845 */
846export interface ExportNamedDeclaration extends Node, HasSpan {
847 type: "ExportNamedDeclaration";
848 specifiers: ExportSpecifier[];
849 source?: StringLiteral;
850}
851export interface ExportDefaultDeclaration extends Node, HasSpan {
852 type: "ExportDefaultDeclaration";
853 decl: DefaultDecl;
854}
855export declare type DefaultDecl = ClassExpression | FunctionExpression | TsInterfaceDeclaration;
856export declare type ImportSpecifier = NamedImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier;
857/**
858 * e.g. `import foo from 'mod.js'`
859 */
860export interface ImportDefaultSpecifier extends Node, HasSpan {
861 type: "ImportDefaultSpecifier";
862 local: Identifier;
863}
864/**
865 * e.g. `import * as foo from 'mod.js'`.
866 */
867export interface ImportNamespaceSpecifier extends Node, HasSpan {
868 type: "ImportNamespaceSpecifier";
869 local: Identifier;
870}
871/**
872 * e.g. - `import { foo } from 'mod.js'`
873 *
874 * local = foo, imported = None
875 *
876 * e.g. `import { foo as bar } from 'mod.js'`
877 *
878 * local = bar, imported = Some(foo) for
879 */
880export interface NamedImportSpecifier extends Node, HasSpan {
881 type: "ImportSpecifier";
882 local: Identifier;
883 imported: Identifier;
884}
885export declare type ExportSpecifier = ExportNamespaceSpecifer | ExportDefaultSpecifier | NamedExportSpecifier;
886/**
887 * `export * as foo from 'src';`
888 */
889export interface ExportNamespaceSpecifer extends Node, HasSpan {
890 type: "ExportNamespaceSpecifer";
891 name: Identifier;
892}
893export interface ExportDefaultSpecifier extends Node, HasSpan {
894 type: "ExportDefaultSpecifier";
895 exported: Identifier;
896}
897export interface NamedExportSpecifier extends Node, HasSpan {
898 type: "ExportSpecifier";
899 orig: Identifier;
900 /**
901 * `Some(bar)` in `export { foo as bar }`
902 */
903 exported: Identifier;
904}
905interface HasInterpreter {
906 /**
907 * e.g. `/usr/bin/node` for `#!/usr/bin/node`
908 */
909 interpreter: string;
910}
911export declare type Program = Module | Script;
912export interface Module extends Node, HasSpan, HasInterpreter {
913 type: "Module";
914 body: ModuleItem[];
915}
916export interface Script extends Node, HasSpan, HasInterpreter {
917 type: "Script";
918 body: Statement[];
919}
920export declare type ModuleItem = ModuleDeclaration | Statement;
921export declare type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "||" | "&&" | "in" | "instanceof" | "??";
922export declare type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=";
923export declare type UpdateOperator = "++" | "--";
924export declare type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
925export declare type Pattern = Identifier | ArrayPattern | RestElement | ObjectPattern | AssignmentPattern | Invalid | Expression;
926export interface ArrayPattern extends Node, HasSpan, PatternBase {
927 type: "ArrayPattern";
928 elements: (Pattern | undefined)[];
929}
930export interface ObjectPattern extends Node, HasSpan, PatternBase {
931 type: "ObjectPattern";
932 props: ObjectPatternProperty[];
933}
934export interface AssignmentPattern extends Node, HasSpan, PatternBase {
935 type: "AssignmentPattern";
936 left: Pattern;
937 right: Expression;
938}
939export interface RestElement extends Node, HasSpan, PatternBase {
940 type: "RestElement";
941 rest: Span;
942 argument: Pattern;
943}
944export declare type ObjectPatternProperty = KeyValuePatternProperty | AssignmentPatternProperty | RestElement;
945/**
946 * `{key: value}`
947 */
948export interface KeyValuePatternProperty extends Node {
949 type: "KeyValuePatternProperty";
950 key: PropertyName;
951 value: Pattern;
952}
953/**
954 * `{key}` or `{key = value}`
955 */
956export interface AssignmentPatternProperty extends Node, HasSpan {
957 type: "AssignmentPatternProperty";
958 key: Identifier;
959 value?: Expression;
960}
961/** Identifier is `a` in `{ a, }` */
962export declare type Property = Identifier | KeyValueProperty | AssignmentProperty | GetterProperty | SetterProperty | MethodProperty;
963interface PropBase extends Node {
964 key: PropertyName;
965}
966export interface KeyValueProperty extends PropBase {
967 type: "KeyValueProperty";
968 value: Expression;
969}
970export interface AssignmentProperty extends Node {
971 type: "AssignmentProperty";
972 key: Identifier;
973 value: Expression;
974}
975export interface GetterProperty extends PropBase, HasSpan {
976 type: "GetterProperty";
977 typeAnnotation?: TsTypeAnnotation;
978 body: BlockStatement;
979}
980export interface SetterProperty extends PropBase, HasSpan {
981 type: "SetterProperty";
982 param: Pattern;
983 body: BlockStatement;
984}
985export interface MethodProperty extends PropBase, Fn {
986 type: "MethodProperty";
987}
988export declare type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropName;
989export interface ComputedPropName extends Node, HasSpan {
990 type: "Computed";
991 expression: Expression;
992}
993export interface BlockStatement extends Node, HasSpan {
994 type: "BlockStatement";
995 stmts: Statement[];
996}
997export interface ExpressionStatement extends Node, HasSpan {
998 type: "ExpressionStatement";
999 expression: Expression;
1000}
1001export declare type Statement = ExpressionStatement | BlockStatement | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
1002export interface EmptyStatement extends Node, HasSpan {
1003 type: "EmptyStatement";
1004}
1005export interface DebuggerStatement extends Node, HasSpan {
1006 type: "DebuggerStatement";
1007}
1008export interface WithStatement extends Node, HasSpan {
1009 type: "WithStatement";
1010 object: Expression;
1011 body: Statement;
1012}
1013export interface ReturnStatement extends Node, HasSpan {
1014 type: "ReturnStatement";
1015 argument: Expression;
1016}
1017export interface LabeledStatement extends Node, HasSpan {
1018 type: "LabeledStatement";
1019 label: Identifier;
1020 body: Statement;
1021}
1022export interface BreakStatement extends Node, HasSpan {
1023 type: "BreakStatement";
1024 label: Identifier;
1025}
1026export interface ContinueStatement extends Node, HasSpan {
1027 type: "ContinueStatement";
1028 label: Identifier;
1029}
1030export interface IfStatement extends Node, HasSpan {
1031 type: "IfStatement";
1032 test: Expression;
1033 consequent: Statement;
1034 alternate?: Statement;
1035}
1036export interface SwitchStatement extends Node, HasSpan {
1037 type: "SwitchStatement";
1038 discriminant: Expression;
1039 cases: SwitchCase[];
1040}
1041export interface ThrowStatement extends Node, HasSpan {
1042 type: "ThrowStatement";
1043 argument: Expression;
1044}
1045export interface TryStatement extends Node, HasSpan {
1046 type: "TryStatement";
1047 block: BlockStatement;
1048 handler?: CatchClause;
1049 finalizer: BlockStatement;
1050}
1051export interface WhileStatement extends Node, HasSpan {
1052 type: "WhileStatement";
1053 test: Expression;
1054 body: Statement;
1055}
1056export interface DoWhileStatement extends Node, HasSpan {
1057 type: "DoWhileStatement";
1058 test: Expression;
1059 body: Statement;
1060}
1061export interface ForStatement extends Node, HasSpan {
1062 type: "ForStatement";
1063 init?: VariableDeclaration | Expression;
1064 test?: Expression;
1065 update?: Expression;
1066 body: Statement;
1067}
1068export interface ForInStatement extends Node, HasSpan {
1069 type: "ForInStatement";
1070 left: VariableDeclaration | Pattern;
1071 right: Expression;
1072 body: Statement;
1073}
1074export interface ForOfStatement extends Node, HasSpan {
1075 type: "ForOfStatement";
1076 /**
1077 * Span of the await token.
1078 *
1079 * es2018 for-await-of statements, e.g., `for await (const x of xs) {`
1080 */
1081 await: Span;
1082 left: VariableDeclaration | Pattern;
1083 right: Expression;
1084 body: Statement;
1085}
1086export interface SwitchCase extends Node, HasSpan {
1087 type: "SwitchCase";
1088 /**
1089 * Undefined for default case
1090 */
1091 test?: Expression;
1092 consequent: Statement[];
1093}
1094export interface CatchClause extends Node, HasSpan {
1095 type: "CatchClause";
1096 /**
1097 * The param is `undefined` if the catch binding is omitted. E.g., `try { foo() } catch {}`
1098 */
1099 param: Pattern;
1100 body: BlockStatement;
1101}
1102export interface TsTypeAnnotation extends Node, HasSpan {
1103 type: "TsTypeAnnotation";
1104 typeAnnotation: TsType;
1105}
1106export interface TsTypeParameterDeclaration extends Node, HasSpan {
1107 type: "TsTypeParameterDeclaration";
1108 parameters: TsTypeParameter[];
1109}
1110export interface TsTypeParameter extends Node, HasSpan {
1111 type: "TsTypeParameter";
1112 name: Identifier;
1113 constraint: TsType;
1114 default: TsType;
1115}
1116export interface TsTypeParameterInstantiation extends Node, HasSpan {
1117 type: "TsTypeParameterInstantiation";
1118 params: TsType[];
1119}
1120export interface TsTypeCastExpression extends Node, HasSpan {
1121 type: "TsTypeCastExpression";
1122 expression: Expression;
1123 typeAnnotation: TsTypeAnnotation;
1124}
1125export interface TsParameterProperty extends Node, HasSpan, HasDecorator {
1126 type: "TsParameterProperty";
1127 accessibility?: Accessibility;
1128 readonly: boolean;
1129 param: TsParameterPropertyParameter;
1130}
1131export declare type TsParameterPropertyParameter = Identifier | AssignmentPattern;
1132export interface TsQualifiedName extends Node {
1133 type: "TsQualifiedName";
1134 left: TsEntityName;
1135 right: Identifier;
1136}
1137export declare type TsEntityName = TsQualifiedName | Identifier;
1138export declare type TsSignatureDeclaration = TsCallSignatureDeclaration | TsConstructSignatureDeclaration | TsMethodSignature | TsFunctionType | TsConstructorType;
1139export declare type TsTypeElement = TsCallSignatureDeclaration | TsConstructSignatureDeclaration | TsPropertySignature | TsMethodSignature | TsIndexSignature;
1140export interface TsCallSignatureDeclaration extends Node, HasSpan {
1141 type: "TsCallSignatureDeclaration";
1142 params: TsFnParameter[];
1143 typeAnnotation: TsTypeAnnotation;
1144 typeParams: TsTypeParameterDeclaration;
1145}
1146export interface TsConstructSignatureDeclaration extends Node, HasSpan {
1147 type: "TsConstructSignatureDeclaration";
1148 params: TsFnParameter[];
1149 typeAnnotation: TsTypeAnnotation;
1150 typeParams: TsTypeParameterDeclaration;
1151}
1152export interface TsPropertySignature extends Node, HasSpan {
1153 type: "TsPropertySignature";
1154 readonly: boolean;
1155 key: Expression;
1156 computed: boolean;
1157 optional: boolean;
1158 init: Expression;
1159 params: TsFnParameter[];
1160 typeAnnotation?: TsTypeAnnotation;
1161 typeParams: TsTypeParameterDeclaration;
1162}
1163export interface TsMethodSignature extends Node, HasSpan {
1164 type: "TsMethodSignature";
1165 readonly: boolean;
1166 key: Expression;
1167 computed: boolean;
1168 optional: boolean;
1169 params: TsFnParameter[];
1170 typeAnnotation: TsTypeAnnotation;
1171 typeParams: TsTypeParameterDeclaration;
1172}
1173export interface TsIndexSignature extends Node, HasSpan {
1174 type: "TsIndexSignature";
1175 readonly: boolean;
1176 params: TsFnParameter[];
1177 typeAnnotation?: TsTypeAnnotation;
1178}
1179export declare type TsType = TsKeywordType | TsThisType | TsFnOrConstructorType | TsTypeReference | TsTypeQuery | TsTypeLiteral | TsArrayType | TsTupleType | TsOptionalType | TsRestType | TsUnionOrIntersectionType | TsConditionalType | TsInferType | TsParenthesizedType | TsTypeOperator | TsIndexedAccessType | TsMappedType | TsLiteralType | TsImportType | TsTypePredicate;
1180export declare type TsFnOrConstructorType = TsFunctionType | TsConstructorType;
1181export interface TsKeywordType extends Node, HasSpan {
1182 type: "TsKeywordType";
1183 kind: TsKeywordTypeKind;
1184}
1185export declare type TsKeywordTypeKind = "any" | "unknown" | "number" | "object" | "boolean" | "bigint" | "string" | "symbol" | "void" | "undefined" | "null" | "never";
1186export interface TsThisType extends Node, HasSpan {
1187 type: "TsThisType";
1188}
1189export declare type TsFnParameter = Identifier | RestElement | ObjectPattern;
1190export interface TsFunctionType extends Node, HasSpan {
1191 type: "TsFunctionType";
1192 typeParams: TsTypeParameterDeclaration;
1193 typeAnnotation: TsTypeAnnotation;
1194}
1195export interface TsConstructorType extends Node, HasSpan {
1196 type: "TsConstructorType";
1197 params: TsFnParameter[];
1198 typeParams: TsTypeParameterDeclaration;
1199 typeAnnotation: TsTypeAnnotation;
1200}
1201export interface TsTypeReference extends Node, HasSpan {
1202 type: "TsTypeReference";
1203 typeName: TsEntityName;
1204 typeParams: TsTypeParameterInstantiation;
1205}
1206export interface TsTypePredicate extends Node, HasSpan {
1207 type: "TsTypePredicate";
1208 asserts: boolean;
1209 paramName: TsThisTypeOrIdent;
1210 typeAnnotation: TsTypeAnnotation;
1211}
1212export declare type TsThisTypeOrIdent = TsThisType | Identifier;
1213export interface TsImportType extends Node, HasSpan {
1214 argument: StringLiteral;
1215 qualifier?: TsEntityName;
1216 typeArguments?: TsTypeParameterInstantiation;
1217}
1218/**
1219 * `typeof` operator
1220 */
1221export interface TsTypeQuery extends Node, HasSpan {
1222 type: "TsTypeQuery";
1223 exprName: TsTypeQueryExpr;
1224}
1225export declare type TsTypeQueryExpr = TsEntityName | TsImportType;
1226export interface TsTypeLiteral extends Node, HasSpan {
1227 type: "TsTypeLiteral";
1228 members: TsTypeElement[];
1229}
1230export interface TsArrayType extends Node, HasSpan {
1231 type: "TsArrayType";
1232 elemType: TsType;
1233}
1234export interface TsTupleType extends Node, HasSpan {
1235 type: "TsTupleType";
1236 elemTypes: TsType[];
1237}
1238export interface TsOptionalType extends Node, HasSpan {
1239 type: "TsOptionalType";
1240 typeAnnotation: TsType;
1241}
1242export interface TsRestType extends Node, HasSpan {
1243 type: "TsRestType";
1244 typeAnnotation: TsType;
1245}
1246export declare type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType;
1247export interface TsUnionType extends Node, HasSpan {
1248 type: "TsUnionType";
1249 types: TsType[];
1250}
1251export interface TsIntersectionType extends Node, HasSpan {
1252 type: "TsIntersectionType";
1253 types: TsType[];
1254}
1255export interface TsConditionalType extends Node, HasSpan {
1256 type: "TsConditionalType";
1257 checkType: TsType;
1258 extendsType: TsType;
1259 trueType: TsType;
1260 falseType: TsType;
1261}
1262export interface TsInferType extends Node, HasSpan {
1263 type: "TsInferType";
1264 typeParam: TsTypeParameter;
1265}
1266export interface TsParenthesizedType extends Node, HasSpan {
1267 type: "TsParenthesizedType";
1268 typeAnnotation: TsType;
1269}
1270export interface TsTypeOperator extends Node, HasSpan {
1271 type: "TsTypeOperator";
1272 op: TsTypeOperatorOp;
1273 typeAnnotation: TsType;
1274}
1275export declare type TsTypeOperatorOp = "keyof" | "unique";
1276export interface TsIndexedAccessType extends Node, HasSpan {
1277 type: "TsIndexedAccessType";
1278 objectType: TsType;
1279 indexType: TsType;
1280}
1281export declare type TruePlusMinus = true | "+" | "-";
1282export interface TsMappedType extends Node, HasSpan {
1283 type: "TsMappedType";
1284 readonly: TruePlusMinus;
1285 typeParam: TsTypeParameter;
1286 optional: TruePlusMinus;
1287 typeAnnotation: TsType;
1288}
1289export interface TsLiteralType extends Node, HasSpan {
1290 type: "TsLiteralType";
1291 literal: TsLiteral;
1292}
1293export declare type TsLiteral = NumericLiteral | StringLiteral | BooleanLiteral | TemplateLiteral;
1294export interface TsInterfaceDeclaration extends Node, HasSpan {
1295 type: "TsInterfaceDeclaration";
1296 id: Identifier;
1297 declare: boolean;
1298 typeParams?: TsTypeParameterDeclaration;
1299 extends: TsExpressionWithTypeArguments[];
1300 body: TsInterfaceBody;
1301}
1302export interface TsInterfaceBody extends Node, HasSpan {
1303 type: "TsInterfaceBody";
1304 body: TsTypeElement[];
1305}
1306export interface TsExpressionWithTypeArguments extends Node, HasSpan {
1307 type: "TsExpressionWithTypeArguments";
1308 expression: TsEntityName;
1309 typeArguments?: TsTypeParameterInstantiation;
1310}
1311export interface TsTypeAliasDeclaration extends Node, HasSpan {
1312 type: "TsTypeAliasDeclaration";
1313 declare: boolean;
1314 id: Identifier;
1315 typeParams?: TsTypeParameterDeclaration;
1316 typeAnnotation: TsType;
1317}
1318export interface TsEnumDeclaration extends Node, HasSpan {
1319 type: "TsEnumDeclaration";
1320 declare: boolean;
1321 is_const: boolean;
1322 id: Identifier;
1323 member: TsEnumMember[];
1324}
1325export interface TsEnumMember extends Node, HasSpan {
1326 type: "TsEnumMember";
1327 id: TsEnumMemberId;
1328 init?: Expression;
1329}
1330export declare type TsEnumMemberId = Identifier | StringLiteral;
1331export interface TsModuleDeclaration extends Node, HasSpan {
1332 type: "TsModuleDeclaration";
1333 declare: boolean;
1334 global: boolean;
1335 id: TsModuleName;
1336 body?: TsNamespaceBody;
1337}
1338/**
1339 * `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as its body.
1340 */
1341export declare type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration;
1342export interface TsModuleBlock extends Node, HasSpan {
1343 type: "TsModuleBlock";
1344 body: ModuleItem[];
1345}
1346export interface TsNamespaceDeclaration extends Node, HasSpan {
1347 type: "TsNamespaceDeclaration";
1348 declare: boolean;
1349 global: boolean;
1350 id: Identifier;
1351 body: TsNamespaceBody;
1352}
1353export declare type TsModuleName = Identifier | StringLiteral;
1354export interface TsImportEqualsDeclaration extends Node, HasSpan {
1355 type: "TsImportEqualsDeclaration";
1356 declare: boolean;
1357 is_export: boolean;
1358 id: Identifier;
1359 moduleRef: TsModuleReference;
1360}
1361export declare type TsModuleReference = TsEntityName | TsExternalModuleReference;
1362export interface TsExternalModuleReference extends Node, HasSpan {
1363 type: "TsExternalModuleReference";
1364 expression: Expression;
1365}
1366export interface TsExportAssignment extends Node, HasSpan {
1367 type: "TsExportAssignment";
1368 expression: Expression;
1369}
1370export interface TsNamespaceExportDeclaration extends Node, HasSpan {
1371 type: "TsNamespaceExportDeclaration";
1372 id: Identifier;
1373}
1374export interface TsAsExpression extends ExpressionBase {
1375 type: "TsAsExpression";
1376 expression: Expression;
1377 typeAnnotation: TsType;
1378}
1379export interface TsTypeAssertion extends ExpressionBase {
1380 type: "TsTypeAssertion";
1381 expression: Expression;
1382 typeAnnotation: TsType;
1383}
1384export interface TsNonNullExpression extends ExpressionBase {
1385 type: "TsNonNullExpression";
1386 expression: Expression;
1387}
1388export declare type Accessibility = "public" | "protected" | "private";
1389export interface Invalid extends Node, HasSpan {
1390 type: "Invalid";
1391}
1392export {};