@@ -42,19 +42,22 @@ This specification is written in a [Web IDL][webidl]-like grammar.
42
42
43
43
### Where this specification fits
44
44
45
- esast extends [ unist] [ ] , a format for syntax trees, to benefit from its
46
- [ ecosystem of utilities] [ utilities ] .
45
+ esast extends [ unist] [ ] ,
46
+ a format for syntax trees,
47
+ to benefit from its [ ecosystem of utilities] [ utilities ] .
47
48
There is one important difference with other implementations of unist: children
48
49
are added at fields other than the ` children ` array and the ` children ` field is
49
50
not used.
50
51
51
52
esast relates to [ ESTree] [ ] in that the first is a superset of the latter.
52
53
Any tool that accepts an ESTree also supports esast.
53
54
54
- esast relates to [ JavaScript] [ ] , other than that it represents it, in that it
55
- has an [ ecosystem of utilities] [ list-of-utilities ] for working with compliant
56
- syntax trees in JavaScript.
57
- However, esast is not limited to JavaScript and can be used in other programming
55
+ esast relates to [ JavaScript] [ ] ,
56
+ other than that it represents it,
57
+ in that it has an [ ecosystem of utilities] [ list-of-utilities ] for working with
58
+ compliantsyntax trees in JavaScript.
59
+ However,
60
+ esast is not limited to JavaScript and can be used in other programming
58
61
languages.
59
62
60
63
esast relates to the [ unified] [ ] project in that esast syntax trees are used
@@ -64,17 +67,21 @@ throughout its ecosystem.
64
67
65
68
ESTree is great but it is missing some things:
66
69
67
- * Trees can’t be roundtripped through ` JSON.parse(JSON.stringify(s)) ` ,
70
+ * trees can’t be roundtripped through ` JSON.parse(JSON.stringify(s)) ` ,
68
71
leading to cache troubles
69
- * Columns are 0-indexed, whereas most text editors display 1-indexed
70
- columns, leading to a tiny discrepancy or some math to display warnings
71
- * There is no recommendation for range-based positional info,
72
+ * columns are 0-indexed,
73
+ whereas most text editors display 1-indexed columns,
74
+ leading to a tiny discrepancy or some math to display warnings
75
+ * there is no recommendation for range-based positional info,
72
76
leading implementations to scatter them in different places
73
- * There is no safe space for metadata,
77
+ * there is no safe space for metadata,
74
78
leading implementations to scatter them in different places
75
- * There are no recommendations for how to handle JSX, comments, or raw values
79
+ * there are no recommendations for how to handle JSX,
80
+ comments,
81
+ or raw values
76
82
77
- These are minor nits, which is why esast is a superset.
83
+ These are minor nits,
84
+ which is why esast is a superset.
78
85
79
86
## Nodes
80
87
@@ -85,8 +92,8 @@ extend interface Node <: UnistNode {}
85
92
```
86
93
87
94
All esast nodes inherit from unist’s [ Node] [ unist-node ] and are otherwise the
88
- same as their ESTree counterparts, with the exception of ` RegExpLiteral ` and
89
- ` BigIntLiteral ` .
95
+ same as their ESTree counterparts,
96
+ with the exception of ` RegExpLiteral ` and ` BigIntLiteral ` .
90
97
91
98
### ` RegExpLiteral `
92
99
@@ -104,22 +111,27 @@ must be ignored.
104
111
105
112
## Recommendations
106
113
107
- For JSX, follow the
114
+ For JSX,
115
+ follow the
108
116
[ JSX extension] ( https://github.com/facebook/jsx/blob/master/AST.md )
109
117
maintained in ` facebook/jsx ` .
110
118
111
- For type annotations, follow the
119
+ For type annotations,
120
+ follow the
112
121
[ Type annotations extension] ( https://github.com/estree/estree/blob/master/extensions/type-annotations.md )
113
122
maintained in ` estree/estree ` .
114
123
115
124
` raw ` fields (added by most parsers) should not be used: they create an extra
116
- source of truth, which is often not maintained.
125
+ source of truth,
126
+ which is often not maintained.
117
127
118
- ` start ` , ` end ` , and ` range ` fields should not be used.
128
+ ` start ` ,
129
+ ` end ` ,
130
+ and ` range ` fields should not be used.
119
131
120
132
` comments ` should not be added on nodes other that ` Program ` .
121
- When adding comments, use the ` 'Block' ` (for ` /**/ ` ) or ` 'Line' ` (for ` // ` )
122
- types.
133
+ When adding comments,
134
+ use the ` 'Block' ` (for ` /**/ ` ) or ` 'Line' ` (for ` // ` ) types.
123
135
Do not use ` leading ` or ` trailing ` fields on comment nodes.
124
136
125
137
` tokens ` should not be used.
@@ -130,13 +142,15 @@ See the [unist glossary][glossary] but note of the following deviating terms.
130
142
131
143
###### Child
132
144
133
- Node X is ** child** of node Y, if X is either referenced directly or referenced
134
- in an array at a field on node Y.
145
+ Node X is ** child** of node Y,
146
+ if X is either referenced directly or referenced in an array at a field on
147
+ node Y.
135
148
136
149
###### Sibling
137
150
138
- Node X is a ** sibling** of node Y, if X and Y have the same parent (if any) and
139
- X and Y are both referenced in an array at a field on node Y.
151
+ Node X is a ** sibling** of node Y,
152
+ if X and Y have the same parent (if any) and X and Y are both referenced in an
153
+ array at a field on node Y.
140
154
141
155
## List of utilities
142
156
@@ -159,7 +173,8 @@ See the [unist list of utilities][utilities] for more utilities.
159
173
* [ ` esast-util-from-js ` ] ( https://github.com/syntax-tree/esast-util-from-js )
160
174
— parse from JavaScript
161
175
162
- Please use either ` estree-util- ` (if it works with all ESTrees, preferred)
176
+ Please use either ` estree-util- ` (if it works with all ESTrees,
177
+ preferred)
163
178
or ` esast-util- ` (if it uses on esast specific features) as a prefix.
164
179
165
180
See also the [ ` estree ` ] ( https://github.com/search?q=topic%3Aestree\& s=stars\& o=desc )
@@ -184,8 +199,9 @@ topic on GitHub.
184
199
185
200
## Security
186
201
187
- As esast represents JS, and JS can open you up to a bunch of problems, esast is
188
- also unsafe.
202
+ As esast represents JS,
203
+ and JS can open you up to a bunch of problems,
204
+ esast is also unsafe.
189
205
Always be careful with user input.
190
206
191
207
## Related
@@ -202,12 +218,17 @@ ways to get started.
202
218
See [ ` support.md ` ] [ support ] for ways to get help.
203
219
Ideas for new utilities and tools can be posted in [ ` syntax-tree/ideas ` ] [ ideas ] .
204
220
205
- A curated list of awesome syntax-tree, unist, mdast, esast, xast, and nlcst
206
- resources can be found in [ awesome syntax-tree] [ awesome ] .
221
+ A curated list of awesome ` syntax-tree ` ,
222
+ unist,
223
+ mdast,
224
+ esast,
225
+ xast,
226
+ and nlcst resources can be found in [ awesome syntax-tree] [ awesome ] .
207
227
208
228
This project has a [ code of conduct] [ coc ] .
209
- By interacting with this repository, organization, or community you agree to
210
- abide by its terms.
229
+ By interacting with this repository,
230
+ organization,
231
+ or community you agree to abide by its terms.
211
232
212
233
## Acknowledgments
213
234
0 commit comments