Skip to content

Commit c515597

Browse files
committed
Add improved docs
1 parent a9c3661 commit c515597

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

lib/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
* Configuration (optional).
2929
* @property {Version | null | undefined} [version='latest']
3030
* JavaScript version (year between 2015 and 2022 or `'latest'`).
31+
*
32+
* When a number, must be a year in the range `2015` and `2022` (both
33+
* including).
34+
* `'latest'` is the same as passing the latest supported year.
35+
*
36+
* > ☢️ **Danger**: `'latest'` is a sliding thing, you could consider it as
37+
* > breaking semver.
38+
* > Pass an actual year to lock that down.
3139
* @property {boolean | null | undefined} [module=false]
3240
* Whether this is a module (ESM) or a script.
3341
* @property {boolean | null | undefined} [allowReturnOutsideFunction=false]
@@ -43,16 +51,20 @@
4351
* Whether a shell hasbang is allowed.
4452
* @property {Array<Plugin> | null | undefined} [plugins=[]]
4553
* List of acorn plugins.
54+
*
55+
* Examples are `acorn-jsx` and `acorn-stage3`.
4656
*/
4757

4858
import {Parser} from 'acorn'
4959
import {fromEstree} from 'esast-util-from-estree'
5060
import {VFileMessage} from 'vfile-message'
5161

5262
/**
63+
* Parse JavaScript to an esast.
64+
*
5365
* @param {Value} value
5466
* Serialized JavaScript to parse.
55-
* @param {Options | null | undefined} [options={}]
67+
* @param {Options | null | undefined} [options]
5668
* Configuration (optional).
5769
* @returns {Program}
5870
* Program node (as esast).

readme.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* [`Options`](#options)
2222
* [`Plugin`](#plugin)
2323
* [`Value`](#value)
24-
* [`Version`](#version)
24+
* [`Version`](#version-1)
2525
* [Types](#types)
2626
* [Compatibility](#compatibility)
2727
* [Contribute](#contribute)
@@ -45,7 +45,7 @@ It turns the tree into a string of JavaScript.
4545
## Install
4646

4747
This package is [ESM only][esm].
48-
In Node.js (version 14.14+ or 16.0+), install with [npm][]:
48+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4949

5050
```sh
5151
npm install esast-util-from-js
@@ -54,14 +54,14 @@ npm install esast-util-from-js
5454
In Deno with [`esm.sh`][esmsh]:
5555

5656
```js
57-
import {fromJs} from "https://esm.sh/esast-util-from-js@1"
57+
import {fromJs} from 'https://esm.sh/esast-util-from-js@1'
5858
```
5959

6060
In browsers with [`esm.sh`][esmsh]:
6161

6262
```html
6363
<script type="module">
64-
import {fromJs} from "https://esm.sh/esast-util-from-js@1?bundle"
64+
import {fromJs} from 'https://esm.sh/esast-util-from-js@1?bundle'
6565
</script>
6666
```
6767

@@ -117,12 +117,12 @@ Yields:
117117

118118
## API
119119

120-
This package exports the identifier `fromJs`.
120+
This package exports the identifier [`fromJs`][fromjs].
121121
There is no default export.
122122

123123
### `fromJs(value[, options])`
124124

125-
Parse a JavaScript (`string` or `Buffer` in UTF-8) to an esast ([`Node`][node]).
125+
Parse JavaScript to an esast.
126126

127127
###### Parameters
128128

@@ -133,13 +133,15 @@ Parse a JavaScript (`string` or `Buffer` in UTF-8) to an esast ([`Node`][node]).
133133

134134
###### Returns
135135

136-
Tree (`Program`).
136+
Tree ([`Node`][node]).
137137

138138
### `Options`
139139

140140
Configuration (TypeScript type).
141141

142-
###### `options.version`
142+
##### Fields
143+
144+
###### `version`
143145

144146
JavaScript version ([`Version`][version], default: `'latest'`).
145147

@@ -150,34 +152,34 @@ When a number, must be a year in the range `2015` and `2022` (both including).
150152
> breaking semver.
151153
> Pass an actual year to lock that down.
152154
153-
###### `options.module`
155+
###### `module`
154156

155157
Whether this is a module (ESM) or a script (`boolean`, default: `false`).
156158

157-
###### `options.allowReturnOutsideFunction`
159+
###### `allowReturnOutsideFunction`
158160

159161
Whether a return statement is allowed in the top scope (`boolean`, default:
160162
`false`).
161163

162-
###### `options.allowImportExportEverywhere`
164+
###### `allowImportExportEverywhere`
163165

164166
Whether import/export statements are allowed in the every scope (`boolean`,
165167
default: `false`).
166168

167-
###### `options.allowAwaitOutsideFunction`
169+
###### `allowAwaitOutsideFunction`
168170

169171
Whether `await` is allowed in the top scope (`boolean`, default: depends).
170172
Defaults to `version >= 2022`.
171173

172-
###### `options.allowSuperOutsideMethod`
174+
###### `allowSuperOutsideMethod`
173175

174176
Whether `super` is allowed outside methods (`boolean`, default: `false`).
175177

176-
###### `options.allowHashBang`
178+
###### `allowHashBang`
177179

178180
Whether a shell hasbang is allowed (`boolean`, default: `false`).
179181

180-
###### `options.plugins`
182+
###### `plugins`
181183

182184
List of acorn plugins ([`Array<Plugin>`][plugin], default: `[]`).
183185
Examples are [`acorn-jsx`][acorn-jsx] and [`acorn-stage3`][acorn-stage3].
@@ -217,7 +219,8 @@ type Version = 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 'latest'
217219
## Types
218220
219221
This package is fully typed with [TypeScript][].
220-
It exports the additional types `Options`, `Plugin`, `Value`, and `Version`.
222+
It exports the additional types [`Options`][options], [`Plugin`][plugin],
223+
[`Value`][value], and [`Version`][version].
221224
222225
## Compatibility
223226
@@ -306,10 +309,12 @@ abide by its terms.
306309
307310
[estree-util-to-js]: https://github.com/syntax-tree/estree-util-to-js
308311
312+
[fromjs]: #fromjsvalue-options
313+
309314
[options]: #options
310315
311316
[plugin]: #plugin
312317
313318
[value]: #value
314319
315-
[version]: #version
320+
[version]: #version-1

0 commit comments

Comments
 (0)