diff --git a/.changeset/afraid-elephants-live.md b/.changeset/afraid-elephants-live.md new file mode 100644 index 000000000..b4527682d --- /dev/null +++ b/.changeset/afraid-elephants-live.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Add `fragment` node types to AST definitions, expose Fragment helper to utils diff --git a/lib/compiler/browser/utils.ts b/lib/compiler/browser/utils.ts index e62a94178..db2cdaf63 100644 --- a/lib/compiler/browser/utils.ts +++ b/lib/compiler/browser/utils.ts @@ -5,6 +5,7 @@ import { ElementNode, CustomElementNode, ComponentNode, + FragmentNode, LiteralNode, ExpressionNode, TextNode, @@ -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; @@ -38,6 +39,7 @@ export const is = { element: guard('element'), customElement: guard('custom-element'), component: guard('component'), + fragment: guard('fragment'), expression: guard('expression'), text: guard('text'), doctype: guard('doctype'), diff --git a/lib/compiler/node/utils.ts b/lib/compiler/node/utils.ts index e62a94178..db2cdaf63 100644 --- a/lib/compiler/node/utils.ts +++ b/lib/compiler/node/utils.ts @@ -5,6 +5,7 @@ import { ElementNode, CustomElementNode, ComponentNode, + FragmentNode, LiteralNode, ExpressionNode, TextNode, @@ -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; @@ -38,6 +39,7 @@ export const is = { element: guard('element'), customElement: guard('custom-element'), component: guard('component'), + fragment: guard('fragment'), expression: guard('expression'), text: guard('text'), doctype: guard('doctype'), diff --git a/lib/compiler/shared/ast.ts b/lib/compiler/shared/ast.ts index 25f70a498..674ee8509 100644 --- a/lib/compiler/shared/ast.ts +++ b/lib/compiler/shared/ast.ts @@ -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; @@ -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[]; } @@ -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;