44 *
55 * @typedef Options
66 * Configuration (optional).
7- * @property {boolean } [dirty=false]
7+ * @property {boolean | null | undefined } [dirty=false]
88 * Leave discouraged fields in the tree.
99 */
1010
@@ -14,12 +14,17 @@ import {visit} from 'estree-util-visit'
1414const own = { } . hasOwnProperty
1515
1616/**
17+ * Turn an estree into an esast.
18+ *
1719 * @param {EstreeNode } estree
18- * @param {Options } [options]
20+ * estree.
21+ * @param {Options | null | undefined } [options]
22+ * Configuration (optional).
1923 * @returns {UnistNode }
24+ * esast.
2025 */
2126export function fromEstree ( estree , options = { } ) {
22- /** @type {UnistNode| undefined } */
27+ /** @type {UnistNode | undefined } */
2328 let tail
2429
2530 visit ( estree , {
@@ -29,7 +34,7 @@ export function fromEstree(estree, options = {}) {
2934 /** @type {EstreeNode } */
3035 // @ts -expect-error: indexable.
3136 const context = field === null || index === null ? parent : parent [ field ]
32- /** @type {string| number| null } */
37+ /** @type {string | number | null } */
3338 const prop = index === null ? field : index
3439 /** @type {UnistNode } */
3540 const copy = { }
@@ -39,7 +44,7 @@ export function fromEstree(estree, options = {}) {
3944 for ( key in node ) {
4045 if (
4146 own . call ( node , key ) &&
42- ( options . dirty ||
47+ ( ( options && options . dirty ) ||
4348 ( key !== 'start' &&
4449 key !== 'end' &&
4550 key !== 'loc' &&
@@ -58,7 +63,7 @@ export function fromEstree(estree, options = {}) {
5863
5964 // If this is a bigint or regex literal, reset value.
6065 if (
61- ! options . dirty &&
66+ ( ! options || ! options . dirty ) &&
6267 node . type === 'Literal' &&
6368 key === 'value' &&
6469 ( 'bigint' in node || 'regex' in node )
0 commit comments