UNPKG

3.5 kBTypeScriptView Raw
1/**
2 * A free variable is resolved according to a resolution rule:
3 *
4 * 1. Strict resolution
5 * 2. Namespaced resolution
6 */
7import type { GetContextualFreeOpcode } from '@glimmer/interfaces';
8import type { FreeVarNamespace } from './constants';
9import { COMPONENT_VAR_NS, HELPER_VAR_NS, MODIFIER_VAR_NS } from './constants';
10/**
11 * Strict resolution is used:
12 *
13 * 1. in a strict mode template
14 * 2. in an local variable invocation with dot paths
15 */
16export declare const STRICT_RESOLUTION: {
17 resolution: () => GetContextualFreeOpcode;
18 serialize: () => SerializedResolution;
19 isAngleBracket: false;
20};
21export type StrictResolution = typeof STRICT_RESOLUTION;
22export declare const HTML_RESOLUTION: {
23 isAngleBracket: true;
24 resolution: () => GetContextualFreeOpcode;
25 serialize: () => SerializedResolution;
26};
27export type HtmlResolution = typeof HTML_RESOLUTION;
28export declare function isStrictResolution(value: unknown): value is StrictResolution;
29/**
30 * A `LooseModeResolution` includes one or more namespaces to resolve the variable in
31 *
32 * In practice, there are a limited number of possible combinations of these degrees of freedom,
33 * and they are captured by the `Namespaces` union below.
34 */
35export declare class LooseModeResolution {
36 readonly namespaces: Namespaces;
37 readonly isAngleBracket: boolean;
38 /**
39 * Namespaced resolution is used in an unambiguous syntax position:
40 *
41 * 1. `(sexp)` (namespace: `Helper`)
42 * 2. `{{#block}}` (namespace: `Component`)
43 * 3. `<a {{modifier}}>` (namespace: `Modifier`)
44 * 4. `<Component />` (namespace: `Component`)
45 */
46 static namespaced(namespace: FreeVarNamespace, isAngleBracket?: boolean): LooseModeResolution;
47 /**
48 * Append resolution is used when the variable should be resolved in both the `component` and
49 * `helper` namespaces.
50 *
51 * ```hbs
52 * {{x}}
53 * ```
54 *
55 * ```hbs
56 * {{x y}}
57 * ```
58 *
59 * ^ In either case, `x` should be resolved in the `component` and `helper` namespaces.
60 */
61 static append(): LooseModeResolution;
62 /**
63 * Trusting append resolution is used when the variable should be resolved only in the
64 * `helper` namespaces.
65 *
66 * ```hbs
67 * {{{x}}}
68 * ```
69 *
70 * ```hbs
71 * {{{x y}}}
72 * ```
73 *
74 * ^ In either case, `x` should be resolved in the `helper` namespace.
75 */
76 static trustingAppend(): LooseModeResolution;
77 constructor(namespaces: Namespaces, isAngleBracket?: boolean);
78 resolution(): GetContextualFreeOpcode;
79 serialize(): SerializedResolution;
80}
81export declare const HELPER_NAMESPACE: "Helper";
82export declare const MODIFIER_NAMESPACE: "Modifier";
83export declare const COMPONENT_NAMESPACE: "Component";
84/**
85 * A `Namespaced` must be resolved in one or more namespaces.
86 *
87 * ```hbs
88 * <X />
89 * ```
90 *
91 * ^ `X` is resolved in the `component` namespace
92 *
93 * ```hbs
94 * (x)
95 * ```
96 *
97 * ^ `x` is resolved in the `helper` namespace
98 *
99 * ```hbs
100 * <a {{x}} />
101 * ```
102 *
103 * ^ `x` is resolved in the `modifier` namespace
104 */
105type Namespaces = [HELPER_VAR_NS] | [MODIFIER_VAR_NS] | [COMPONENT_VAR_NS] | [COMPONENT_VAR_NS, HELPER_VAR_NS];
106export type FreeVarResolution = StrictResolution | HtmlResolution | LooseModeResolution;
107export type SerializedResolution = 'Strict' | 'Helper' | 'Modifier' | 'Component' | 'ComponentOrHelper';
108export declare function loadResolution(resolution: SerializedResolution): FreeVarResolution;
109export {};
110
\No newline at end of file