@astrojs/compiler 0.12.0 → 0.12.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @astrojs/compiler
2
2
 
3
+ ## 0.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 097ac47: Parser: Always output the `attribute` property in an element node, even if empty
8
+ - ad62437: Add `serialize` util
9
+ - eb7eb95: Parse: fix escaping of `&` characters in AST output
10
+
3
11
  ## 0.12.0
4
12
 
5
13
  ### Minor Changes
package/astro.wasm CHANGED
Binary file
@@ -19,3 +19,4 @@ export declare const is: {
19
19
  frontmatter: (node: Node) => node is FrontmatterNode;
20
20
  };
21
21
  export declare function walk(node: ParentNode, callback: Visitor): void;
22
+ export declare function serialize(root: Node): string;
package/browser/utils.js CHANGED
@@ -45,3 +45,32 @@ export function walk(node, callback) {
45
45
  const walker = new Walker(callback);
46
46
  walker.visit(node);
47
47
  }
48
+ export function serialize(root) {
49
+ let output = '';
50
+ function visitor(node) {
51
+ if (is.root(node)) {
52
+ node.children.forEach((child) => visitor(child));
53
+ }
54
+ else if (is.frontmatter(node)) {
55
+ output += `---${node.value}---\n\n`;
56
+ }
57
+ else if (is.comment(node)) {
58
+ output += `<!--${node.value}-->`;
59
+ }
60
+ else if (is.expression(node)) {
61
+ output += `{`;
62
+ node.children.forEach((child) => visitor(child));
63
+ output += `}`;
64
+ }
65
+ else if (is.literal(node)) {
66
+ output += node.value;
67
+ }
68
+ else if (is.tag(node)) {
69
+ output += `<${node.name}>`;
70
+ node.children.forEach((child) => visitor(child));
71
+ output += `</${node.name}>`;
72
+ }
73
+ }
74
+ visitor(root);
75
+ return output;
76
+ }
package/node/utils.d.ts CHANGED
@@ -19,3 +19,4 @@ export declare const is: {
19
19
  frontmatter: (node: Node) => node is FrontmatterNode;
20
20
  };
21
21
  export declare function walk(node: ParentNode, callback: Visitor): void;
22
+ export declare function serialize(root: Node): string;
package/node/utils.js CHANGED
@@ -45,3 +45,32 @@ export function walk(node, callback) {
45
45
  const walker = new Walker(callback);
46
46
  walker.visit(node);
47
47
  }
48
+ export function serialize(root) {
49
+ let output = '';
50
+ function visitor(node) {
51
+ if (is.root(node)) {
52
+ node.children.forEach((child) => visitor(child));
53
+ }
54
+ else if (is.frontmatter(node)) {
55
+ output += `---${node.value}---\n\n`;
56
+ }
57
+ else if (is.comment(node)) {
58
+ output += `<!--${node.value}-->`;
59
+ }
60
+ else if (is.expression(node)) {
61
+ output += `{`;
62
+ node.children.forEach((child) => visitor(child));
63
+ output += `}`;
64
+ }
65
+ else if (is.literal(node)) {
66
+ output += node.value;
67
+ }
68
+ else if (is.tag(node)) {
69
+ output += `<${node.name}>`;
70
+ node.children.forEach((child) => visitor(child));
71
+ output += `</${node.name}>`;
72
+ }
73
+ }
74
+ visitor(root);
75
+ return output;
76
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "module",
6
6
  "bugs": "https://github.com/withastro/compiler/issues",
7
7
  "homepage": "https://astro.build",
8
- "version": "0.12.0",
8
+ "version": "0.12.1",
9
9
  "scripts": {
10
10
  "build": "tsc -p ."
11
11
  },