18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
20
* [ ` fromJs(value[, options]) ` ] ( #fromjsvalue-options )
21
+ * [ ` Options ` ] ( #options )
22
+ * [ ` Plugin ` ] ( #plugin )
23
+ * [ ` Value ` ] ( #value )
24
+ * [ ` Version ` ] ( #version )
21
25
* [ Types] ( #types )
22
26
* [ Compatibility] ( #compatibility )
23
27
* [ Contribute] ( #contribute )
@@ -41,7 +45,7 @@ It turns the tree into a string of JavaScript.
41
45
## Install
42
46
43
47
This package is [ ESM only] [ esm ] .
44
- In Node.js (version 14.14+, 16.0+, or 18 .0+), install with [ npm] [ ] :
48
+ In Node.js (version 14.14+ or 16 .0+), install with [ npm] [ ] :
45
49
46
50
``` sh
47
51
npm install esast-util-from-js
@@ -105,8 +109,8 @@ Yields:
105
109
sourceType: ' module' ,
106
110
comments: [],
107
111
position: {
108
- start: { line: 1 , column: 1 , offset: 0 },
109
- end: { line: 7 , column: 1 , offset: 157 }
112
+ start: {line: 1 , column: 1 , offset: 0 },
113
+ end: {line: 7 , column: 1 , offset: 157 }
110
114
}
111
115
}
112
116
```
@@ -120,13 +124,25 @@ There is no default export.
120
124
121
125
Parse a JavaScript (` string ` or ` Buffer ` in UTF-8) to an esast ([ ` Node ` ] [ node ] ).
122
126
123
- ##### ` options `
127
+ ###### Parameters
124
128
125
- Configuration (optional).
129
+ * ` value ` ([ ` Value ` ] [ value ] )
130
+ — serialized JavaScript to parse
131
+ * ` options ` ([ ` Options ` ] [ options ] , optional)
132
+ — configuration
133
+
134
+ ###### Returns
135
+
136
+ Tree (` Program ` ).
137
+
138
+ ### ` Options `
139
+
140
+ Configuration (TypeScript type).
126
141
127
142
###### ` options.version `
128
143
129
- JavaScript version (` number ` or ` 'latest' ` , default: ` 'latest' ` ).
144
+ JavaScript version ([ ` Version ` ] [ version ] , default: ` 'latest' ` ).
145
+
130
146
When a number, must be a year in the range ` 2015 ` and ` 2022 ` (both including).
131
147
` 'latest' ` is the same as passing the latest supported year.
132
148
@@ -163,23 +179,51 @@ Whether a shell hasbang is allowed (`boolean`, default: `false`).
163
179
164
180
###### ` options.plugins `
165
181
166
- List of acorn plugins (` Array<Plugin> ` ).
182
+ List of acorn plugins ([ ` Array<Plugin> ` ] [ plugin ] , default: ` [] ` ).
167
183
Examples are [ ` acorn-jsx ` ] [ acorn-jsx ] and [ ` acorn-stage3 ` ] [ acorn-stage3 ] .
168
184
169
- ##### Returns
185
+ ### ` Plugin `
186
+
187
+ Acorn plugin (TypeScript type).
170
188
171
- Tree ([ ` Node ` ] [ node ] ).
189
+ ###### Type
190
+
191
+ ``` ts
192
+ type Plugin = (Parser : ParserClass ) => ParserClass
193
+ ` ` `
194
+
195
+ ### ` Value `
196
+
197
+ Input value (TypeScript type).
198
+
199
+ ###### Type
200
+
201
+ ` ` ` ts
202
+ type Value = string | Buffer // `Buffer` is added when Node.js types ere used.
203
+ ` ` `
204
+
205
+ ### ` Version `
206
+
207
+ JavaScript version (TypeScript type).
208
+
209
+ ` ' latest' ` is equivalent to the latest supported year.
210
+
211
+ ###### Type
212
+
213
+ ` ` ` ts
214
+ type Version = 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | ' latest'
215
+ ` ` `
172
216
173
217
## Types
174
218
175
219
This package is fully typed with [TypeScript][].
176
- It exports the additional types ` Value ` , ` Options ` , ` Version ` , and ` Plugin ` .
220
+ It exports the additional types ` Options ` , ` Plugin ` , ` Value ` , and ` Version ` .
177
221
178
222
## Compatibility
179
223
180
224
Projects maintained by the unified collective are compatible with all maintained
181
225
versions of Node.js.
182
- As of now, that is Node.js 14.14+, 16.0+, and 18 .0+.
226
+ As of now, that is Node.js 14.14+ and 16 .0+.
183
227
Our projects sometimes work with older versions, but this is not guaranteed.
184
228
185
229
## Contribute
@@ -261,3 +305,11 @@ abide by its terms.
261
305
[acorn-stage3]: https://github.com/acornjs/acorn-stage3
262
306
263
307
[estree-util-to-js]: https://github.com/syntax-tree/estree-util-to-js
308
+
309
+ [options]: #options
310
+
311
+ [plugin]: #plugin
312
+
313
+ [value]: #value
314
+
315
+ [version]: #version
0 commit comments