UNPKG

prettier-plugin-marko

Version:

A prettier plugin for parsing and printing Marko files

236 lines (235 loc) 7.47 kB
import { type Range, type Ranges, TagType } from "htmljs-parser"; export type Repeated<T> = [T, ...T[]] | [...T[], T] | [T, ...T[], T]; export type Repeatable<T> = undefined | Repeated<T>; export declare const UNFINISHED: number; export { getLines, getLocation, getPosition, type Location, type Position, type Range, type Ranges, TagType, } from "htmljs-parser"; export type Parsed = ReturnType<typeof parse>; export declare enum NodeType { Program = 0, Tag = 1, OpenTagName = 2, ShorthandId = 3, ShorthandClassName = 4, TagTypeArgs = 5, TagTypeParams = 6, TagVar = 7, TagArgs = 8, TagParams = 9, AttrNamed = 10, AttrName = 11, AttrArgs = 12, AttrValue = 13, AttrMethod = 14, AttrSpread = 15, AttrTag = 16, Text = 17, CDATA = 18, Doctype = 19, Declaration = 20, Comment = 21, Placeholder = 22, Scriptlet = 23, Import = 24, Export = 25, Class = 26, Style = 27, Static = 28 } export declare enum CommentType { line = 0, block = 1, html = 2 } export declare namespace Node { type AnyNode = Program | Tag | OpenTagName | ShorthandId | ShorthandClassName | TagTypeArgs | TagTypeParams | TagVar | TagArgs | TagParams | AttrNamed | AttrName | AttrArgs | AttrValue | AttrMethod | AttrSpread | AttrTag | Text | CDATA | Doctype | Declaration | Comment | Placeholder | Scriptlet | Import | Export | Class | Style | Static; type ParentNode = Program | Tag | AttrTag; type StaticNode = Import | Export | Class | Style | Static; type ParentTag = Tag | AttrTag; type AttrNode = AttrNamed | AttrSpread; type ControlFlowTag = Tag & { nameText: "if" | "else" | "else-if" | "for" | "while"; bodyType: TagType.html; }; type ChildNode = Tag | AttrTag | Text | Doctype | Declaration | CDATA | Placeholder | Scriptlet | Comment; interface Program extends Range { type: NodeType.Program; parent: undefined; body: (ChildNode | StaticNode)[]; } interface Tag extends Range { type: NodeType.Tag; parent: ParentNode; owner: undefined; concise: boolean; selfClosed: boolean; hasAttrTags: boolean; open: Range; close: Range | undefined; nameText: string | undefined; bodyType: Exclude<TagType, "statement">; name: OpenTagName; var: TagVar | undefined; args: TagArgs | undefined; params: TagParams | undefined; shorthandId: ShorthandId | undefined; shorthandClassNames: Repeatable<ShorthandClassName>; typeArgs: TagTypeArgs | undefined; typeParams: TagTypeParams | undefined; attrs: Repeatable<AttrNode>; body: Repeatable<ChildNode>; } interface AttrTag extends Range { type: NodeType.AttrTag; parent: ParentTag; owner: Tag | undefined; concise: boolean; selfClosed: boolean; hasAttrTags: boolean; open: Range; close: Range | undefined; nameText: string; bodyType: TagType.html; name: OpenTagName; var: TagVar | undefined; args: TagArgs | undefined; params: TagParams | undefined; shorthandId: ShorthandId | undefined; shorthandClassNames: Repeatable<ShorthandClassName>; typeArgs: TagTypeArgs | undefined; typeParams: TagTypeParams | undefined; attrs: Repeatable<AttrNode>; body: Repeatable<ChildNode>; } interface OpenTagName extends Ranges.Template { type: NodeType.OpenTagName; parent: ParentTag; } interface ShorthandId extends Ranges.Template { type: NodeType.ShorthandId; parent: ParentTag; } interface ShorthandClassName extends Ranges.Template { type: NodeType.ShorthandClassName; parent: ParentTag; } interface TagTypeArgs extends Ranges.Value { type: NodeType.TagTypeArgs; parent: ParentTag; } interface TagTypeParams extends Ranges.Value { type: NodeType.TagTypeParams; parent: ParentTag; } interface TagVar extends Ranges.Value { type: NodeType.TagVar; parent: ParentTag; } interface TagArgs extends Ranges.Value { type: NodeType.TagArgs; parent: ParentTag; } interface TagParams extends Ranges.Value { type: NodeType.TagParams; parent: ParentTag; } interface Text extends Range { type: NodeType.Text; parent: ParentNode; } interface CDATA extends Ranges.Value { type: NodeType.CDATA; parent: ParentNode; } interface Doctype extends Ranges.Value { type: NodeType.Doctype; parent: ParentNode; } interface Declaration extends Ranges.Value { type: NodeType.Declaration; parent: ParentNode; } interface Comment extends Ranges.Value { type: NodeType.Comment; parent: ParentNode; commentType: CommentType; } interface Placeholder extends Ranges.Value { type: NodeType.Placeholder; parent: ParentNode; escape: boolean; } interface Scriptlet extends Ranges.Value { type: NodeType.Scriptlet; parent: ParentNode; block: boolean; } interface AttrNamed extends Range { type: NodeType.AttrNamed; parent: ParentTag; name: AttrName; args: undefined | AttrArgs; value: undefined | AttrValue | AttrMethod; } interface AttrName extends Range { type: NodeType.AttrName; parent: AttrNamed; } interface AttrArgs extends Ranges.Value { type: NodeType.AttrArgs; parent: AttrNamed; } interface AttrValue extends Range { type: NodeType.AttrValue; parent: AttrNamed; value: Range; bound: boolean; } interface AttrMethod extends Range { type: NodeType.AttrMethod; parent: AttrNamed; typeParams: undefined | Ranges.Value; params: Range; body: Range; } interface AttrSpread extends Ranges.Value { type: NodeType.AttrSpread; parent: ParentTag; } interface Import extends Range { type: NodeType.Import; parent: ParentNode; } interface Export extends Range { type: NodeType.Export; parent: ParentNode; } interface Class extends Range { type: NodeType.Class; parent: ParentNode; } interface Style extends Range { type: NodeType.Style; parent: ParentNode; ext: string | undefined; value: Range; } interface Static extends Range { type: NodeType.Static; parent: ParentNode; target: "client" | "server" | "static"; } } export declare function parse(code: string, filename?: string): { read: (range: Range) => string; locationAt: (range: Range) => import("htmljs-parser").Location; positionAt: (offset: number) => import("htmljs-parser").Position; filename: string; program: Node.Program; code: string; }; /** * Used to check if a node should be ignored as the parent of an attribute tag. * When control flow is the parent of an attribute tag, we add the attribute tag to * the closest non control flow ancestor attrs instead. */ export declare function isControlFlowTag(node: Node.Tag): node is Node.ControlFlowTag;