@astrojs/compiler 0.12.0-next.9 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @astrojs/compiler
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ce3f1a5: Update CSS parser to use `esbuild`, adding support for CSS nesting, `@container`, `@layer`, and other modern syntax features
8
+
9
+ ### Patch Changes
10
+
11
+ - 24a1185: Parser: Always output the `children` property in an element node, even if it has no children
12
+
13
+ ## 0.12.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 097ac47: Parser: Always output the `attribute` property in an element node, even if empty
18
+ - ad62437: Add `serialize` util
19
+ - eb7eb95: Parse: fix escaping of `&` characters in AST output
20
+
21
+ ## 0.12.0
22
+
23
+ ### Minor Changes
24
+
25
+ - c6dd41d: Do not render implicit tags created during the parsing process
26
+ - c6dd41d: Remove "as" option, treats all documents as fragments that generate no implicit tags
27
+ - c6dd41d: Add `parse` function which generates an AST
28
+ - c6dd41d: Adds support for `Astro.self` (as accepted in the [Recursive Components RFC](https://github.com/withastro/rfcs/blob/main/active-rfcs/0000-recursive-components.md)).
29
+
30
+ ### Patch Changes
31
+
32
+ - c6dd41d: Add `fragment` node types to AST definitions, expose Fragment helper to utils
33
+ - c6dd41d: Adds metadata on client:only components
34
+ - c6dd41d: Expose AST types via `@astrojs/compiler/types`
35
+ - c6dd41d: Export `./types` rather than `./types.d.ts`
36
+ - c6dd41d: Fix edge case with Fragment parsing in head, add `fragment` node to AST output
37
+ - c6dd41d: Fix <slot> behavior inside of head
38
+ - c6dd41d: Improve head injection behavior
39
+ - ef0b4b3: Move `typescript` dependency to development dependencies, as it is not needed in the package runtime.
40
+ - c6dd41d: Update exposed types
41
+ - c6dd41d: Remove usage of `escapeHTML` util
42
+ - c6dd41d: Export all types from shared types
43
+ - c6dd41d: Fix `head` behavior and a bug related to ParseFragment
44
+ - c6dd41d: Adds a warning when using an expression with a hoisted script
45
+
3
46
  ## 0.12.0-next.9
4
47
 
5
48
  ### Patch Changes
package/astro.wasm CHANGED
Binary file
@@ -1,4 +1,4 @@
1
- import { Node, ParentNode, RootNode, ElementNode, CustomElementNode, ComponentNode, LiteralNode, ExpressionNode, TextNode, CommentNode, DoctypeNode, FrontmatterNode } from '../shared/ast';
1
+ import { Node, ParentNode, RootNode, ElementNode, CustomElementNode, ComponentNode, FragmentNode, LiteralNode, ExpressionNode, TextNode, CommentNode, DoctypeNode, FrontmatterNode } from '../shared/ast';
2
2
  export interface Visitor {
3
3
  (node: Node, parent?: ParentNode, index?: number): void | Promise<void>;
4
4
  }
@@ -11,6 +11,7 @@ export declare const is: {
11
11
  element: (node: Node) => node is ElementNode;
12
12
  customElement: (node: Node) => node is CustomElementNode;
13
13
  component: (node: Node) => node is ComponentNode;
14
+ fragment: (node: Node) => node is FragmentNode;
14
15
  expression: (node: Node) => node is ExpressionNode;
15
16
  text: (node: Node) => node is TextNode;
16
17
  doctype: (node: Node) => node is DoctypeNode;
@@ -18,3 +19,4 @@ export declare const is: {
18
19
  frontmatter: (node: Node) => node is FrontmatterNode;
19
20
  };
20
21
  export declare function walk(node: ParentNode, callback: Visitor): void;
22
+ export declare function serialize(root: Node): string;
package/browser/utils.js CHANGED
@@ -9,7 +9,7 @@ export const is = {
9
9
  return typeof node.value === 'string';
10
10
  },
11
11
  tag(node) {
12
- return node.type === 'element' || node.type === 'custom-element' || node.type === 'component';
12
+ return node.type === 'element' || node.type === 'custom-element' || node.type === 'component' || node.type === 'fragment';
13
13
  },
14
14
  whitespace(node) {
15
15
  return node.type === 'text' && node.value.trim().length === 0;
@@ -18,6 +18,7 @@ export const is = {
18
18
  element: guard('element'),
19
19
  customElement: guard('custom-element'),
20
20
  component: guard('component'),
21
+ fragment: guard('fragment'),
21
22
  expression: guard('expression'),
22
23
  text: guard('text'),
23
24
  doctype: guard('doctype'),
@@ -44,3 +45,32 @@ export function walk(node, callback) {
44
45
  const walker = new Walker(callback);
45
46
  walker.visit(node);
46
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
@@ -1,4 +1,4 @@
1
- import { Node, ParentNode, RootNode, ElementNode, CustomElementNode, ComponentNode, LiteralNode, ExpressionNode, TextNode, CommentNode, DoctypeNode, FrontmatterNode } from '../shared/ast';
1
+ import { Node, ParentNode, RootNode, ElementNode, CustomElementNode, ComponentNode, FragmentNode, LiteralNode, ExpressionNode, TextNode, CommentNode, DoctypeNode, FrontmatterNode } from '../shared/ast';
2
2
  export interface Visitor {
3
3
  (node: Node, parent?: ParentNode, index?: number): void | Promise<void>;
4
4
  }
@@ -11,6 +11,7 @@ export declare const is: {
11
11
  element: (node: Node) => node is ElementNode;
12
12
  customElement: (node: Node) => node is CustomElementNode;
13
13
  component: (node: Node) => node is ComponentNode;
14
+ fragment: (node: Node) => node is FragmentNode;
14
15
  expression: (node: Node) => node is ExpressionNode;
15
16
  text: (node: Node) => node is TextNode;
16
17
  doctype: (node: Node) => node is DoctypeNode;
@@ -18,3 +19,4 @@ export declare const is: {
18
19
  frontmatter: (node: Node) => node is FrontmatterNode;
19
20
  };
20
21
  export declare function walk(node: ParentNode, callback: Visitor): void;
22
+ export declare function serialize(root: Node): string;
package/node/utils.js CHANGED
@@ -9,7 +9,7 @@ export const is = {
9
9
  return typeof node.value === 'string';
10
10
  },
11
11
  tag(node) {
12
- return node.type === 'element' || node.type === 'custom-element' || node.type === 'component';
12
+ return node.type === 'element' || node.type === 'custom-element' || node.type === 'component' || node.type === 'fragment';
13
13
  },
14
14
  whitespace(node) {
15
15
  return node.type === 'text' && node.value.trim().length === 0;
@@ -18,6 +18,7 @@ export const is = {
18
18
  element: guard('element'),
19
19
  customElement: guard('custom-element'),
20
20
  component: guard('component'),
21
+ fragment: guard('fragment'),
21
22
  expression: guard('expression'),
22
23
  text: guard('text'),
23
24
  doctype: guard('doctype'),
@@ -44,3 +45,32 @@ export function walk(node, callback) {
44
45
  const walker = new Walker(callback);
45
46
  walker.visit(node);
46
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-next.9",
8
+ "version": "0.13.0",
9
9
  "scripts": {
10
10
  "build": "tsc -p ."
11
11
  },
@@ -31,12 +31,12 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "tsm": "^2.2.1",
34
- "typescript": "^4.3.5",
35
34
  "uvu": "^0.5.3"
36
35
  },
37
36
  "devDependencies": {
38
37
  "@types/node": "^16.4.12",
39
- "@types/sass": "^1.43.1"
38
+ "@types/sass": "^1.43.1",
39
+ "typescript": "^4.4.3"
40
40
  },
41
41
  "volta": {
42
42
  "node": "16.6.2"
package/shared/ast.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export declare type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | ExpressionNode;
2
- export declare type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;
1
+ export declare type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode;
2
+ export declare type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;
3
3
  export interface Position {
4
4
  start: Point;
5
5
  end?: Point;
@@ -17,7 +17,7 @@ export interface BaseNode {
17
17
  position?: Position;
18
18
  }
19
19
  export interface ParentLikeNode extends BaseNode {
20
- type: 'element' | 'component' | 'custom-element' | 'expression' | 'root';
20
+ type: 'element' | 'component' | 'custom-element' | 'fragment' | 'expression' | 'root';
21
21
  children: Node[];
22
22
  }
23
23
  export interface LiteralNode extends BaseNode {
@@ -45,6 +45,12 @@ export interface ElementNode extends ParentLikeNode {
45
45
  attributes: AttributeNode[];
46
46
  directives: DirectiveNode[];
47
47
  }
48
+ export interface FragmentNode extends ParentLikeNode {
49
+ type: 'fragment';
50
+ name: string;
51
+ attributes: AttributeNode[];
52
+ directives: DirectiveNode[];
53
+ }
48
54
  export interface ComponentNode extends ParentLikeNode {
49
55
  type: 'component';
50
56
  name: string;