UNPKG

4.91 kBTypeScriptView Raw
1import type { Nullable } from '@glimmer/interfaces';
2import type { EndTag, StartTag } from '../parser';
3import type { NodeVisitor } from '../traversal/visitor';
4import type * as ASTv1 from '../v1/api';
5import type * as HBS from '../v1/handlebars-ast';
6import print from '../generation/print';
7import * as src from '../source/api';
8import traverse from '../traversal/traverse';
9import Walker from '../traversal/walker';
10import publicBuilder from '../v1/public-builders';
11import { HandlebarsNodeVisitors } from './handlebars-node-visitors';
12export declare class TokenizerEventHandlers extends HandlebarsNodeVisitors {
13 private tagOpenLine;
14 private tagOpenColumn;
15 reset(): void;
16 beginComment(): void;
17 appendToCommentData(char: string): void;
18 finishComment(): void;
19 beginData(): void;
20 appendToData(char: string): void;
21 finishData(): void;
22 tagOpen(): void;
23 beginStartTag(): void;
24 beginEndTag(): void;
25 finishTag(): void;
26 finishStartTag(): void;
27 finishEndTag(isVoid: boolean): void;
28 markTagAsSelfClosing(): void;
29 appendToTagName(char: string): void;
30 beginAttribute(): void;
31 appendToAttributeName(char: string): void;
32 beginAttributeValue(isQuoted: boolean): void;
33 appendToAttributeValue(char: string): void;
34 finishAttributeValue(): void;
35 private parsePossibleBlockParams;
36 reportSyntaxError(message: string): void;
37 assembleConcatenatedValue(parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[]): ASTv1.ConcatStatement;
38 validateEndTag(tag: StartTag | EndTag, element: ASTv1.ParentNode, selfClosing: boolean): asserts element is ASTv1.ElementNode;
39 assembleAttributeValue(parts: ASTv1.AttrPart[], isQuoted: boolean, isDynamic: boolean, span: src.SourceSpan): ASTv1.AttrValue;
40}
41/**
42 ASTPlugins can make changes to the Glimmer template AST before
43 compilation begins.
44*/
45export interface ASTPluginBuilder<TEnv extends ASTPluginEnvironment = ASTPluginEnvironment> {
46 (env: TEnv): ASTPlugin;
47}
48export interface ASTPlugin {
49 name: string;
50 visitor: NodeVisitor;
51}
52export interface ASTPluginEnvironment {
53 meta?: object | undefined;
54 syntax: Syntax;
55}
56interface HandlebarsParseOptions {
57 srcName?: string;
58 ignoreStandalone?: boolean;
59}
60export interface TemplateIdFn {
61 (src: string): Nullable<string>;
62}
63export interface PrecompileOptions extends PreprocessOptions {
64 id?: TemplateIdFn;
65 /**
66 * Additional non-native keywords.
67 *
68 * Local variables (block params or lexical scope) always takes precedence,
69 * but otherwise, suitable free variable candidates (e.g. those are not part
70 * of a path) are matched against this list and turned into keywords.
71 *
72 * In strict mode compilation, keywords suppresses the undefined reference
73 * error and will be resolved by the runtime environment.
74 *
75 * In loose mode, keywords are currently ignored and since all free variables
76 * are already resolved by the runtime environment.
77 */
78 keywords?: readonly string[];
79 /**
80 * In loose mode, this hook allows embedding environments to customize the name of an
81 * angle-bracket component. In practice, this means that `<HelloWorld />` in Ember is
82 * compiled by Glimmer as an invocation of a component named `hello-world`.
83 *
84 * It's a little weird that this is needed in addition to the resolver, but it's a
85 * classic-only feature and it seems fine to leave it alone for classic consumers.
86 */
87 customizeComponentName?: ((input: string) => string) | undefined;
88}
89export interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {
90 lexicalScope: (variable: string) => boolean;
91 /**
92 * If `emit.debugSymbols` is set to `true`, the name of lexical local variables
93 * will be included in the wire format.
94 */
95 emit?: {
96 debugSymbols?: boolean;
97 } | undefined;
98}
99export interface PreprocessOptions {
100 strictMode?: boolean | undefined;
101 locals?: string[] | undefined;
102 meta?: {
103 moduleName?: string | undefined;
104 } | undefined;
105 plugins?: {
106 ast?: ASTPluginBuilder[] | undefined;
107 } | undefined;
108 parseOptions?: HandlebarsParseOptions | undefined;
109 customizeComponentName?: ((input: string) => string) | undefined;
110 /**
111 Useful for specifying a group of options together.
112
113 When `'codemod'` we disable all whitespace control in handlebars
114 (to preserve as much as possible) and we also avoid any
115 escaping/unescaping of HTML entity codes.
116 */
117 mode?: 'codemod' | 'precompile' | undefined;
118}
119export interface Syntax {
120 parse: typeof preprocess;
121 builders: typeof publicBuilder;
122 print: typeof print;
123 traverse: typeof traverse;
124 Walker: typeof Walker;
125}
126export declare function preprocess(input: string | src.Source | HBS.Program, options?: PreprocessOptions): ASTv1.Template;
127export {};
128
\No newline at end of file