UNPKG

5.97 kBTypeScriptView Raw
1import type { Dict, Maybe, Nullable } from '@glimmer/interfaces';
2import type { SourceLocation, SourcePosition } from '../source/location';
3import type * as ASTv1 from './api';
4import { SourceSpan } from '../source/span';
5export type BuilderHead = string | ASTv1.CallableExpression;
6export type TagDescriptor = string | ASTv1.PathExpression | {
7 path: ASTv1.PathExpression;
8 selfClosing?: boolean;
9} | {
10 name: string;
11 selfClosing?: boolean;
12};
13declare function buildMustache(path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags): ASTv1.MustacheStatement;
14type PossiblyDeprecatedBlock = ASTv1.Block | ASTv1.Template;
15declare function buildBlock(path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags): ASTv1.BlockStatement;
16declare function buildElementModifier(path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation>): ASTv1.ElementModifierStatement;
17declare function buildComment(value: string, loc?: SourceLocation): ASTv1.CommentStatement;
18declare function buildMustacheComment(value: string, loc?: SourceLocation): ASTv1.MustacheCommentStatement;
19declare function buildConcat(parts: (ASTv1.TextNode | ASTv1.MustacheStatement)[], loc?: SourceLocation): ASTv1.ConcatStatement;
20export type ElementParts = ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...ASTv1.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', SourceLocation];
21export type PathSexp = string | ['path', string, LocSexp?];
22export type ModifierSexp = string | [PathSexp, LocSexp?] | [PathSexp, ASTv1.Expression[], LocSexp?] | [PathSexp, ASTv1.Expression[], Dict<ASTv1.Expression>, LocSexp?];
23export type AttrSexp = [string, ASTv1.AttrNode['value'] | string, LocSexp?];
24export type LocSexp = ['loc', SourceLocation];
25export type ElementComment = ASTv1.MustacheCommentStatement | SourceLocation | string;
26export type SexpValue = string | ASTv1.Expression[] | Dict<ASTv1.Expression> | LocSexp | PathSexp | undefined;
27export interface BuildElementOptions {
28 attrs?: ASTv1.AttrNode[];
29 modifiers?: ASTv1.ElementModifierStatement[];
30 children?: ASTv1.Statement[];
31 comments?: ASTv1.MustacheCommentStatement[];
32 blockParams?: ASTv1.VarHead[] | string[];
33 openTag?: SourceLocation;
34 closeTag?: Maybe<SourceLocation>;
35 loc?: SourceLocation;
36}
37declare function buildElement(tag: TagDescriptor, options?: BuildElementOptions): ASTv1.ElementNode;
38declare function buildAttr(name: string, value: ASTv1.AttrValue, loc?: SourceLocation): ASTv1.AttrNode;
39declare function buildText(chars?: string, loc?: SourceLocation): ASTv1.TextNode;
40declare function buildSexpr(path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation): ASTv1.SubExpression;
41declare function buildThis(loc?: SourceLocation): ASTv1.ThisHead;
42declare function buildAtName(name: string, loc?: SourceLocation): ASTv1.AtHead;
43declare function buildVar(name: string, loc?: SourceLocation): ASTv1.VarHead;
44declare function buildHeadFromString(original: string, loc?: SourceLocation): ASTv1.PathHead;
45declare function buildCleanPath(head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation): ASTv1.PathExpression;
46declare function buildPath(path: ASTv1.PathExpression | string | {
47 head: string;
48 tail: string[];
49}, loc?: SourceLocation): ASTv1.PathExpression;
50declare function buildPath(path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression;
51declare function buildPath(path: BuilderHead | ASTv1.Literal | ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression;
52declare function buildLiteral<T extends ASTv1.Literal>(type: T['type'], value: T['value'], loc?: SourceLocation): T;
53declare function buildHash(pairs?: ASTv1.HashPair[], loc?: SourceLocation): ASTv1.Hash;
54declare function buildPair(key: string, value: ASTv1.Expression, loc?: SourceLocation): ASTv1.HashPair;
55declare function buildProgram(body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation): ASTv1.Template | ASTv1.Block;
56declare function buildBlockItself(body?: ASTv1.Statement[], params?: Array<ASTv1.VarHead | string>, chained?: boolean, loc?: SourceLocation): ASTv1.Block;
57declare function buildTemplate(body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation): ASTv1.Template;
58declare function buildPosition(line: number, column: number): SourcePosition;
59declare function buildLoc(loc: Nullable<SourceLocation>): SourceSpan;
60declare function buildLoc(startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string): SourceSpan;
61declare const _default: {
62 mustache: typeof buildMustache;
63 block: typeof buildBlock;
64 comment: typeof buildComment;
65 mustacheComment: typeof buildMustacheComment;
66 element: typeof buildElement;
67 elementModifier: typeof buildElementModifier;
68 attr: typeof buildAttr;
69 text: typeof buildText;
70 sexpr: typeof buildSexpr;
71 concat: typeof buildConcat;
72 hash: typeof buildHash;
73 pair: typeof buildPair;
74 literal: typeof buildLiteral;
75 program: typeof buildProgram;
76 blockItself: typeof buildBlockItself;
77 template: typeof buildTemplate;
78 loc: typeof buildLoc;
79 pos: typeof buildPosition;
80 path: typeof buildPath;
81 fullPath: typeof buildCleanPath;
82 head: typeof buildHeadFromString;
83 at: typeof buildAtName;
84 var: typeof buildVar;
85 this: typeof buildThis;
86 string: (value: string) => ASTv1.StringLiteral;
87 boolean: (value: boolean) => ASTv1.BooleanLiteral;
88 number: (value: number) => ASTv1.NumberLiteral;
89 undefined(): ASTv1.UndefinedLiteral;
90 null(): ASTv1.NullLiteral;
91};
92export default _default;