@astrojs/compiler 0.12.0-next.8 → 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 +40 -0
- package/astro.wasm +0 -0
- package/browser/utils.d.ts +3 -1
- package/browser/utils.js +31 -1
- package/node/utils.d.ts +3 -1
- package/node/utils.js +31 -1
- package/package.json +6 -3
- package/shared/ast.d.ts +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.12.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- c6dd41d: Do not render implicit tags created during the parsing process
|
|
16
|
+
- c6dd41d: Remove "as" option, treats all documents as fragments that generate no implicit tags
|
|
17
|
+
- c6dd41d: Add `parse` function which generates an AST
|
|
18
|
+
- 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)).
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- c6dd41d: Add `fragment` node types to AST definitions, expose Fragment helper to utils
|
|
23
|
+
- c6dd41d: Adds metadata on client:only components
|
|
24
|
+
- c6dd41d: Expose AST types via `@astrojs/compiler/types`
|
|
25
|
+
- c6dd41d: Export `./types` rather than `./types.d.ts`
|
|
26
|
+
- c6dd41d: Fix edge case with Fragment parsing in head, add `fragment` node to AST output
|
|
27
|
+
- c6dd41d: Fix <slot> behavior inside of head
|
|
28
|
+
- c6dd41d: Improve head injection behavior
|
|
29
|
+
- ef0b4b3: Move `typescript` dependency to development dependencies, as it is not needed in the package runtime.
|
|
30
|
+
- c6dd41d: Update exposed types
|
|
31
|
+
- c6dd41d: Remove usage of `escapeHTML` util
|
|
32
|
+
- c6dd41d: Export all types from shared types
|
|
33
|
+
- c6dd41d: Fix `head` behavior and a bug related to ParseFragment
|
|
34
|
+
- c6dd41d: Adds a warning when using an expression with a hoisted script
|
|
35
|
+
|
|
36
|
+
## 0.12.0-next.9
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- 95ec808: Fix <slot> behavior inside of head
|
|
41
|
+
- 95ec808: Remove usage of `escapeHTML` util
|
|
42
|
+
|
|
3
43
|
## 0.12.0-next.8
|
|
4
44
|
|
|
5
45
|
### Patch Changes
|
package/astro.wasm
CHANGED
|
Binary file
|
package/browser/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/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.
|
|
8
|
+
"version": "0.12.1",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc -p ."
|
|
11
11
|
},
|
|
@@ -30,10 +30,13 @@
|
|
|
30
30
|
"./types": "./types.d.ts"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"tsm": "^2.2.1",
|
|
34
|
+
"uvu": "^0.5.3"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^16.4.12"
|
|
37
|
+
"@types/node": "^16.4.12",
|
|
38
|
+
"@types/sass": "^1.43.1",
|
|
39
|
+
"typescript": "^4.4.3"
|
|
37
40
|
},
|
|
38
41
|
"volta": {
|
|
39
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;
|