Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-elephants-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Add `fragment` node types to AST definitions, expose Fragment helper to utils
4 changes: 3 additions & 1 deletion lib/compiler/browser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ElementNode,
CustomElementNode,
ComponentNode,
FragmentNode,
LiteralNode,
ExpressionNode,
TextNode,
Expand All @@ -29,7 +30,7 @@ export const is = {
return typeof (node as any).value === 'string';
},
tag(node: Node): node is ElementNode | CustomElementNode | ComponentNode {
return node.type === 'element' || node.type === 'custom-element' || node.type === 'component';
return node.type === 'element' || node.type === 'custom-element' || node.type === 'component' || node.type === 'fragment';
},
whitespace(node: Node): node is TextNode {
return node.type === 'text' && node.value.trim().length === 0;
Expand All @@ -38,6 +39,7 @@ export const is = {
element: guard<ElementNode>('element'),
customElement: guard<CustomElementNode>('custom-element'),
component: guard<ComponentNode>('component'),
fragment: guard<FragmentNode>('fragment'),
expression: guard<ExpressionNode>('expression'),
text: guard<TextNode>('text'),
doctype: guard<DoctypeNode>('doctype'),
Expand Down
4 changes: 3 additions & 1 deletion lib/compiler/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ElementNode,
CustomElementNode,
ComponentNode,
FragmentNode,
LiteralNode,
ExpressionNode,
TextNode,
Expand All @@ -29,7 +30,7 @@ export const is = {
return typeof (node as any).value === 'string';
},
tag(node: Node): node is ElementNode | CustomElementNode | ComponentNode {
return node.type === 'element' || node.type === 'custom-element' || node.type === 'component';
return node.type === 'element' || node.type === 'custom-element' || node.type === 'component' || node.type === 'fragment';
},
whitespace(node: Node): node is TextNode {
return node.type === 'text' && node.value.trim().length === 0;
Expand All @@ -38,6 +39,7 @@ export const is = {
element: guard<ElementNode>('element'),
customElement: guard<CustomElementNode>('custom-element'),
component: guard<ComponentNode>('component'),
fragment: guard<FragmentNode>('fragment'),
expression: guard<ExpressionNode>('expression'),
text: guard<TextNode>('text'),
doctype: guard<DoctypeNode>('doctype'),
Expand Down
13 changes: 10 additions & 3 deletions lib/compiler/shared/ast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | ExpressionNode;
export type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;
export type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode;
export type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;

export interface Position {
start: Point;
Expand All @@ -19,7 +19,7 @@ export interface BaseNode {
}

export interface ParentLikeNode extends BaseNode {
type: 'element' | 'component' | 'custom-element' | 'expression' | 'root';
type: 'element' | 'component' | 'custom-element' | 'fragment' | 'expression' | 'root';
children: Node[];
}

Expand Down Expand Up @@ -54,6 +54,13 @@ export interface ElementNode extends ParentLikeNode {
directives: DirectiveNode[];
}

export interface FragmentNode extends ParentLikeNode {
type: 'fragment';
name: string;
attributes: AttributeNode[];
directives: DirectiveNode[];
}

export interface ComponentNode extends ParentLikeNode {
type: 'component';
name: string;
Expand Down