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 +1 -1
- package/src/index.d.ts +9 -0
- package/src/index.js +1 -0
- package/src/transforms.js +0 -5
- package/src/utils.js +22 -0
package/package.json
CHANGED
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
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
|
+
}
|