Skip to content

Commit cdb014e

Browse files
committed
Refactor code-style
1 parent 5a51ab3 commit cdb014e

File tree

3 files changed

+32
-44
lines changed

3 files changed

+32
-44
lines changed

lib/index.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
* When a typed array, must be UTF-8.
1313
*
1414
* @typedef AcornErrorFields
15+
* Extra fields in acorn errors.
1516
* @property {number} pos
17+
* Index.
1618
* @property {Position} loc
19+
* Acorn position.
1720
*
1821
* @typedef {Error & AcornErrorFields} AcornError
22+
* Acorn error.
1923
*
2024
* @callback Plugin
2125
* Acorn plugin.
@@ -25,36 +29,39 @@
2529
* Resulting parser class.
2630
*
2731
* @typedef {2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 'latest'} Version
32+
* JavaScript version.
33+
*
34+
* `'latest'` is equivalent to the latest supported year.
2835
*
2936
* @typedef Options
30-
* Configuration (optional).
37+
* Configuration.
3138
* @property {Version | null | undefined} [version='latest']
32-
* JavaScript version (year between 2015 and 2022 or `'latest'`).
39+
* JavaScript version (year between 2015 and 2023 or `'latest'`,
40+
* default: `'latest'`).
3341
*
34-
* When a number, must be a year in the range `2015` and `2022` (both
42+
* When a number, must be a year in the range `2015` and `2023` (both
3543
* including).
3644
* `'latest'` is the same as passing the latest supported year.
3745
*
3846
* > ☢️ **Danger**: `'latest'` is a sliding thing, you could consider it as
3947
* > breaking semver.
4048
* > Pass an actual year to lock that down.
4149
* @property {boolean | null | undefined} [module=false]
42-
* Whether this is a module (ESM) or a script.
50+
* Whether this is a module (ESM) or a script (default: `false`).
4351
* @property {boolean | null | undefined} [allowReturnOutsideFunction=false]
44-
* Whether a return statement is allowed in the top scope.
52+
* Whether a return statement is allowed in the top scope (default: `false`).
4553
* @property {boolean | null | undefined} [allowImportExportEverywhere=false]
46-
* Whether import/export statements are allowed in the every scope.
54+
* Whether import/export statements are allowed in the every scope (default:
55+
* `false`).
4756
* @property {boolean | null | undefined} [allowAwaitOutsideFunction]
48-
* Whether `await` is allowed in the top scope.
49-
* Defaults to `version >= 2022`.
57+
* Whether `await` is allowed in the top scope (default: `version >= 2022`).
5058
* @property {boolean | null | undefined} [allowSuperOutsideMethod=false]
51-
* Whether `super` is allowed outside methods.
59+
* Whether `super` is allowed outside methods (default: `false`).
5260
* @property {boolean | null | undefined} [allowHashBang=false]
53-
* Whether a shell hasbang is allowed.
61+
* Whether a shell hasbang is allowed (default: `false`).
5462
* @property {Array<Plugin> | null | undefined} [plugins=[]]
55-
* List of acorn plugins.
56-
*
57-
* Examples are `acorn-jsx` and `acorn-stage3`.
63+
* List of acorn plugins (default: `[]`); examples are `acorn-jsx` and
64+
* `acorn-stage3`.
5865
*/
5966

6067
import {Parser} from 'acorn'
@@ -127,6 +134,6 @@ export function fromJs(value, options) {
127134

128135
tree.comments = comments
129136

130-
// @ts-expect-error: similar enough.
137+
// @ts-expect-error: Program in, program out.
131138
return fromEstree(tree)
132139
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Configuration (TypeScript type).
154154

155155
JavaScript version ([`Version`][version], default: `'latest'`).
156156

157-
When a number, must be a year in the range `2015` and `2022` (both including).
157+
When a number, must be a year in the range `2015` and `2023` (both including).
158158
`'latest'` is the same as passing the latest supported year.
159159

160160
> ☢️ **Danger**: `'latest'` is a sliding thing, you could consider it as
@@ -224,7 +224,7 @@ JavaScript version (TypeScript type).
224224
###### Type
225225
226226
```ts
227-
type Version = 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 'latest'
227+
type Version = 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 'latest'
228228
```
229229
230230
## Types

test/index.js

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ test('fromJs', async function (t) {
186186
})
187187
})
188188

189-
assert.deepEqual(
190-
fromJs(new Uint8Array()),
191-
{
189+
await t.test('should support empty typed arrays', async function () {
190+
assert.deepEqual(fromJs(new Uint8Array()), {
192191
type: 'Program',
193192
body: [],
194193
sourceType: 'script',
@@ -197,13 +196,11 @@ test('fromJs', async function (t) {
197196
start: {line: 1, column: 1, offset: 0},
198197
end: {line: 1, column: 1, offset: 0}
199198
}
200-
},
201-
'should support empty typed arrays'
202-
)
199+
})
200+
})
203201

204-
assert.deepEqual(
205-
fromJs(new TextEncoder().encode('let a = 1')),
206-
{
202+
await t.test('should support typed arrays', async function () {
203+
assert.deepEqual(fromJs(new TextEncoder().encode('let a = 1')), {
207204
type: 'Program',
208205
body: [
209206
{
@@ -246,24 +243,8 @@ test('fromJs', async function (t) {
246243
start: {line: 1, column: 1, offset: 0},
247244
end: {line: 1, column: 10, offset: 9}
248245
}
249-
},
250-
'should support typed arrays'
251-
)
252-
253-
assert.deepEqual(
254-
fromJs(new Uint8Array()),
255-
{
256-
type: 'Program',
257-
body: [],
258-
sourceType: 'script',
259-
comments: [],
260-
position: {
261-
start: {line: 1, column: 1, offset: 0},
262-
end: {line: 1, column: 1, offset: 0}
263-
}
264-
},
265-
'should support empty typed arrays'
266-
)
246+
})
247+
})
267248
})
268249

269250
test('fixtures', async function (t) {
@@ -302,7 +283,7 @@ test('fixtures', async function (t) {
302283
expected = JSON.parse(String(await fs.readFile(treeUrl)))
303284
} catch {
304285
// New fixture.
305-
expected = JSON.stringify(actual, null, 2) + '\n'
286+
expected = JSON.stringify(actual, undefined, 2) + '\n'
306287
await fs.writeFile(treeUrl, expected)
307288
}
308289

0 commit comments

Comments
 (0)