ember-estree 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-estree",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "ESTree generator for gjs and gts file used by ember",
5
5
  "keywords": [
6
6
  "AST",
package/src/index.d.ts CHANGED
@@ -93,3 +93,12 @@ export function print(node: ASTNode): string;
93
93
  * @returns A map of Glimmer node type names to arrays of child-property names.
94
94
  */
95
95
  export function buildGlimmerVisitorKeys(): Record<string, string[]>;
96
+
97
+ /**
98
+ * Recursively remove all `parent` references from an AST.
99
+ * Useful when you need to serialize the tree to JSON,
100
+ * since parent back-references create circular structures.
101
+ *
102
+ * Mutates the tree in place and returns it.
103
+ */
104
+ export function removeParentReferences(ast: ASTNode): ASTNode;
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { toTree, parse } from "./parse.js";
2
2
  export { print } from "./print.js";
3
3
  export { buildGlimmerVisitorKeys, DocumentLines } from "./transforms.js";
4
+ export { removeParentReferences } from "./utils.js";
package/src/transforms.js CHANGED
@@ -221,10 +221,5 @@ export function processGlimmerTemplate(templateAST, { contentOffset, templateRan
221
221
  comment.type = "Block";
222
222
  }
223
223
 
224
- // Clear parent references (they cause circular JSON issues)
225
- for (const n of allNodes) {
226
- n.parent = null;
227
- }
228
-
229
224
  return templateAST;
230
225
  }
package/src/utils.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Optional utility functions for working with ESTree ASTs
3
+ * produced by ember-estree.
4
+ */
5
+
6
+ import { walk } from "zimmerframe";
7
+
8
+ /**
9
+ * Recursively remove all `parent` references from an AST.
10
+ * Useful when you need to serialize the tree to JSON (e.g. for zmod),
11
+ * since parent back-references create circular structures.
12
+ *
13
+ * Mutates the tree in place and returns it.
14
+ */
15
+ export function removeParentReferences(ast) {
16
+ return walk(ast, null, {
17
+ _(node, { next }) {
18
+ delete node.parent;
19
+ next();
20
+ },
21
+ });
22
+ }