Skip to content

Commit 240be0b

Browse files
committed
Improve documentation for AST nodes
1 parent 536444c commit 240be0b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

scripts/ast-types.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
/** @typedef {'Node'|'OptionalNode'|'NodeList'|'Annotations'|'InvalidAnnotations'|'String'|'FixedString'|'OptionalString'|'Float'} FieldType */
1+
/**
2+
* This file contains the AST node descriptions for the ESTree AST.
3+
* From this file, "npm run build:ast:converters" will generate
4+
* - /rust/parse_ast/src/convert_ast/converter/ast_constants.rs:
5+
* Constants that describe how the AST nodes are encoded in Rust.
6+
* - /src/utils/bufferToAst.ts:
7+
* Helper functions that are used by this.parse in plugins to convert a buffer
8+
* to a JSON AST.
9+
* - /src/ast/bufferParsers.ts
10+
* Helper functions that are used by Module.ts to convert a buffer to an
11+
* internal Rollup AST. While this uses roughly the same AST format, it
12+
* instantiates the classes in /src/ast/nodes instead.
13+
* - /src/ast/childNodeKeys.ts
14+
* A list of which AST nodes keys represent child nodes. This is used by the
15+
* legacy parser to instantiate a Rollup AST from a JSON AST.
16+
*
17+
* JavaScript AST nodes follow the ESTree format specified here
18+
* https://github.com/estree/estree. While the binary buffer format could
19+
* theoretically deviate from this, it should be either a one-to-one or a
20+
* many-to-one mapping (Example: All Literal* nodes in the buffer are encoded
21+
* as "type: Literal" in the JSON AST).
22+
*
23+
* For encoded non-JavaScript AST nodes like TypeScript or JSX, we try to follow
24+
* the format of typescript-eslint, which can be derived from their playground
25+
* https://typescript-eslint.io/play/#showAST=es&fileType=.tsx
26+
*/
27+
28+
/** @typedef {"Node"|"OptionalNode"|"NodeList"|"Annotations"|"InvalidAnnotations"|"String"|"FixedString"|"OptionalString"|"Float"} FieldType */
229

330
/** @typedef {[name:string, type:FieldType]} FieldWithType */
431

0 commit comments

Comments
 (0)