UNPKG

5.89 kBTypeScriptView Raw
1import * as AST from './types/nodes';
2import { Option, Dict } from '@glimmer/interfaces';
3import { StringLiteral, BooleanLiteral, NumberLiteral } from './types/handlebars-ast';
4export declare type BuilderHead = string | AST.Expression;
5export declare type TagDescriptor = string | {
6 name: string;
7 selfClosing: boolean;
8};
9declare function buildMustache(path: BuilderHead | AST.Literal, params?: AST.Expression[], hash?: AST.Hash, raw?: boolean, loc?: AST.SourceLocation, strip?: AST.StripFlags): AST.MustacheStatement;
10declare function buildBlock(path: BuilderHead, params: Option<AST.Expression[]>, hash: Option<AST.Hash>, _defaultBlock: AST.PossiblyDeprecatedBlock, _elseBlock?: Option<AST.PossiblyDeprecatedBlock>, loc?: AST.SourceLocation, openStrip?: AST.StripFlags, inverseStrip?: AST.StripFlags, closeStrip?: AST.StripFlags): AST.BlockStatement;
11declare function buildElementModifier(path: BuilderHead, params?: AST.Expression[], hash?: AST.Hash, loc?: Option<AST.SourceLocation>): AST.ElementModifierStatement;
12declare function buildPartial(name: AST.PathExpression, params?: AST.Expression[], hash?: AST.Hash, indent?: string, loc?: AST.SourceLocation): AST.PartialStatement;
13declare function buildComment(value: string, loc?: AST.SourceLocation): AST.CommentStatement;
14declare function buildMustacheComment(value: string, loc?: AST.SourceLocation): AST.MustacheCommentStatement;
15declare function buildConcat(parts: (AST.TextNode | AST.MustacheStatement)[], loc?: AST.SourceLocation): AST.ConcatStatement;
16export declare type ElementArgs = ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...AST.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', AST.SourceLocation];
17export declare type PathSexp = string | ['path', string, LocSexp?];
18export declare type ModifierSexp = string | [PathSexp, LocSexp?] | [PathSexp, AST.Expression[], LocSexp?] | [PathSexp, AST.Expression[], Dict<AST.Expression>, LocSexp?];
19export declare type AttrSexp = [string, AST.AttrNode['value'] | string, LocSexp?];
20export declare type LocSexp = ['loc', AST.SourceLocation];
21export declare type ElementComment = AST.MustacheCommentStatement | AST.SourceLocation | string;
22export declare type SexpValue = string | AST.Expression[] | Dict<AST.Expression> | LocSexp | PathSexp | undefined;
23export declare function isLocSexp(value: SexpValue): value is LocSexp;
24export declare function isParamsSexp(value: SexpValue): value is AST.Expression[];
25export declare function isHashSexp(value: SexpValue): value is Dict<AST.Expression>;
26export declare function normalizeModifier(sexp: ModifierSexp): AST.ElementModifierStatement;
27export declare function normalizeAttr(sexp: AttrSexp): AST.AttrNode;
28export declare function normalizeHash(hash: Dict<AST.Expression>, loc?: AST.SourceLocation): AST.Hash;
29export declare function normalizeHead(path: PathSexp): AST.Expression;
30export declare function normalizeElementOptions(...args: ElementArgs[]): BuildElementOptions;
31export interface BuildElementOptions {
32 attrs?: AST.AttrNode[];
33 modifiers?: AST.ElementModifierStatement[];
34 children?: AST.Statement[];
35 comments?: ElementComment[];
36 blockParams?: string[];
37 loc?: AST.SourceLocation;
38}
39declare function buildElement(tag: TagDescriptor, options?: BuildElementOptions): AST.ElementNode;
40declare function buildElement(tag: TagDescriptor, ...options: ElementArgs[]): AST.ElementNode;
41declare function buildAttr(name: string, value: AST.AttrNode['value'], loc?: AST.SourceLocation): AST.AttrNode;
42declare function buildText(chars?: string, loc?: AST.SourceLocation): AST.TextNode;
43declare function buildSexpr(path: BuilderHead, params?: AST.Expression[], hash?: AST.Hash, loc?: AST.SourceLocation): AST.SubExpression;
44declare function buildHead(original: BuilderHead, loc?: AST.SourceLocation): AST.Expression;
45declare function buildLiteral<T extends AST.Literal>(type: T['type'], value: T['value'], loc?: AST.SourceLocation): T;
46declare function buildHash(pairs?: AST.HashPair[], loc?: AST.SourceLocation): AST.Hash;
47declare function buildPair(key: string, value: AST.Expression, loc?: AST.SourceLocation): AST.HashPair;
48declare function buildProgram(body?: AST.Statement[], blockParams?: string[], loc?: AST.SourceLocation): AST.Template;
49declare function buildBlockItself(body?: AST.Statement[], blockParams?: string[], chained?: boolean, loc?: AST.SourceLocation): AST.Block;
50declare function buildTemplate(body?: AST.Statement[], blockParams?: string[], loc?: AST.SourceLocation): AST.Template;
51declare function buildPosition(line: number, column: number): {
52 line: number;
53 column: number;
54};
55export declare const SYNTHETIC: AST.SourceLocation;
56declare function buildLoc(loc: Option<AST.SourceLocation>): AST.SourceLocation;
57declare function buildLoc(startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string): AST.SourceLocation;
58declare const _default: {
59 mustache: typeof buildMustache;
60 block: typeof buildBlock;
61 partial: typeof buildPartial;
62 comment: typeof buildComment;
63 mustacheComment: typeof buildMustacheComment;
64 element: typeof buildElement;
65 elementModifier: typeof buildElementModifier;
66 attr: typeof buildAttr;
67 text: typeof buildText;
68 sexpr: typeof buildSexpr;
69 path: typeof buildHead;
70 concat: typeof buildConcat;
71 hash: typeof buildHash;
72 pair: typeof buildPair;
73 literal: typeof buildLiteral;
74 program: typeof buildProgram;
75 blockItself: typeof buildBlockItself;
76 template: typeof buildTemplate;
77 loc: typeof buildLoc;
78 pos: typeof buildPosition;
79 string: (value: string) => StringLiteral;
80 boolean: (value: boolean) => BooleanLiteral;
81 number: (value: number) => NumberLiteral;
82 undefined(): AST.Literal;
83 null(): AST.Literal;
84};
85export default _default;
86//# sourceMappingURL=builders.d.ts.map
\No newline at end of file