4
4
*
5
5
* @typedef Options
6
6
* Configuration (optional).
7
- * @property {boolean } [dirty=false]
7
+ * @property {boolean | null | undefined } [dirty=false]
8
8
* Leave discouraged fields in the tree.
9
9
*/
10
10
@@ -14,12 +14,17 @@ import {visit} from 'estree-util-visit'
14
14
const own = { } . hasOwnProperty
15
15
16
16
/**
17
+ * Turn an estree into an esast.
18
+ *
17
19
* @param {EstreeNode } estree
18
- * @param {Options } [options]
20
+ * estree.
21
+ * @param {Options | null | undefined } [options]
22
+ * Configuration (optional).
19
23
* @returns {UnistNode }
24
+ * esast.
20
25
*/
21
26
export function fromEstree ( estree , options = { } ) {
22
- /** @type {UnistNode| undefined } */
27
+ /** @type {UnistNode | undefined } */
23
28
let tail
24
29
25
30
visit ( estree , {
@@ -29,7 +34,7 @@ export function fromEstree(estree, options = {}) {
29
34
/** @type {EstreeNode } */
30
35
// @ts -expect-error: indexable.
31
36
const context = field === null || index === null ? parent : parent [ field ]
32
- /** @type {string| number| null } */
37
+ /** @type {string | number | null } */
33
38
const prop = index === null ? field : index
34
39
/** @type {UnistNode } */
35
40
const copy = { }
@@ -39,7 +44,7 @@ export function fromEstree(estree, options = {}) {
39
44
for ( key in node ) {
40
45
if (
41
46
own . call ( node , key ) &&
42
- ( options . dirty ||
47
+ ( ( options && options . dirty ) ||
43
48
( key !== 'start' &&
44
49
key !== 'end' &&
45
50
key !== 'loc' &&
@@ -58,7 +63,7 @@ export function fromEstree(estree, options = {}) {
58
63
59
64
// If this is a bigint or regex literal, reset value.
60
65
if (
61
- ! options . dirty &&
66
+ ( ! options || ! options . dirty ) &&
62
67
node . type === 'Literal' &&
63
68
key === 'value' &&
64
69
( 'bigint' in node || 'regex' in node )
0 commit comments