UNPKG

5.67 kBTypeScriptView Raw
1/**
2 * A free variable is resolved according to a resolution rule:
3 *
4 * 1. Strict resolution
5 * 2. Namespaced resolution
6 * 3. Fallback resolution
7 */
8import { GetContextualFreeOp } from '@glimmer/interfaces';
9/**
10 * Strict resolution is used:
11 *
12 * 1. in a strict mode template
13 * 2. in an unambiguous invocation with dot paths
14 */
15export declare class StrictResolution {
16 resolution(): GetContextualFreeOp;
17 serialize(): SerializedResolution;
18 readonly isAngleBracket = false;
19}
20export declare const STRICT_RESOLUTION: StrictResolution;
21/**
22 * A `LooseModeResolution` includes:
23 *
24 * - 0 or more namespaces to resolve the variable in
25 * - optional fallback behavior
26 *
27 * In practice, there are a limited number of possible combinations of these degrees of freedom,
28 * and they are captured by the `Ambiguity` union below.
29 */
30export declare class LooseModeResolution {
31 readonly ambiguity: Ambiguity;
32 readonly isAngleBracket: boolean;
33 /**
34 * Namespaced resolution is used in an unambiguous syntax position:
35 *
36 * 1. `(sexp)` (namespace: `Helper`)
37 * 2. `{{#block}}` (namespace: `Component`)
38 * 3. `<a {{modifier}}>` (namespace: `Modifier`)
39 * 4. `<Component />` (namespace: `Component`)
40 *
41 * @see {NamespacedAmbiguity}
42 */
43 static namespaced(namespace: FreeVarNamespace, isAngleBracket?: boolean): LooseModeResolution;
44 /**
45 * Fallback resolution is used when no namespaced resolutions are possible, but fallback
46 * resolution is still allowed.
47 *
48 * ```hbs
49 * {{x.y}}
50 * ```
51 *
52 * @see {FallbackAmbiguity}
53 */
54 static fallback(): LooseModeResolution;
55 /**
56 * Append resolution is used when the variable should be resolved in both the `component` and
57 * `helper` namespaces. Fallback resolution is optional.
58 *
59 * ```hbs
60 * {{x}}
61 * ```
62 *
63 * ^ `x` should be resolved in the `component` and `helper` namespaces with fallback resolution.
64 *
65 * ```hbs
66 * {{x y}}
67 * ```
68 *
69 * ^ `x` should be resolved in the `component` and `helper` namespaces without fallback
70 * resolution.
71 *
72 * @see {ComponentOrHelperAmbiguity}
73 */
74 static append({ invoke }: {
75 invoke: boolean;
76 }): LooseModeResolution;
77 /**
78 * Trusting append resolution is used when the variable should be resolved in both the `component` and
79 * `helper` namespaces. Fallback resolution is optional.
80 *
81 * ```hbs
82 * {{{x}}}
83 * ```
84 *
85 * ^ `x` should be resolved in the `component` and `helper` namespaces with fallback resolution.
86 *
87 * ```hbs
88 * {{{x y}}}
89 * ```
90 *
91 * ^ `x` should be resolved in the `component` and `helper` namespaces without fallback
92 * resolution.
93 *
94 * @see {HelperAmbiguity}
95 */
96 static trustingAppend({ invoke }: {
97 invoke: boolean;
98 }): LooseModeResolution;
99 /**
100 * Attribute resolution is used when the variable should be resolved as a `helper` with fallback
101 * resolution.
102 *
103 * ```hbs
104 * <a href={{x}} />
105 * <a href="{{x}}.html" />
106 * ```
107 *
108 * ^ resolved in the `helper` namespace with fallback
109 *
110 * @see {HelperAmbiguity}
111 */
112 static attr(): LooseModeResolution;
113 constructor(ambiguity: Ambiguity, isAngleBracket?: boolean);
114 resolution(): GetContextualFreeOp;
115 serialize(): SerializedResolution;
116}
117export declare const ARGUMENT_RESOLUTION: LooseModeResolution;
118export declare const enum FreeVarNamespace {
119 Helper = "Helper",
120 Modifier = "Modifier",
121 Component = "Component"
122}
123/**
124 * A `ComponentOrHelperAmbiguity` might be a component or a helper, with an optional fallback
125 *
126 * ```hbs
127 * {{x}}
128 * ```
129 *
130 * ^ `x` is resolved in the `component` and `helper` namespaces, with fallback
131 *
132 * ```hbs
133 * {{x y}}
134 * ```
135 *
136 * ^ `x` is resolved in the `component` and `helper` namespaces, without fallback
137 */
138declare type ComponentOrHelperAmbiguity = {
139 namespaces: [FreeVarNamespace.Component, FreeVarNamespace.Helper];
140 fallback: boolean;
141};
142/**
143 * A `HelperAmbiguity` must be a helper, but it has fallback. If it didn't have fallback, it would
144 * be a `NamespacedAmbiguity`.
145 *
146 * ```hbs
147 * <a href={{x}} />
148 * <a href="{{x}}.html" />
149 * ```
150 *
151 * ^ `x` is resolved in the `helper` namespace with fallback
152 */
153declare type HelperAmbiguity = {
154 namespaces: [FreeVarNamespace.Helper];
155 fallback: boolean;
156};
157/**
158 * A `NamespacedAmbiguity` must be resolved in a particular namespace, without fallback.
159 *
160 * ```hbs
161 * <X />
162 * ```
163 *
164 * ^ `X` is resolved in the `component` namespace without fallback
165 *
166 * ```hbs
167 * (x)
168 * ```
169 *
170 * ^ `x` is resolved in the `helper` namespace without fallback
171 *
172 * ```hbs
173 * <a {{x}} />
174 * ```
175 *
176 * ^ `x` is resolved in the `modifier` namespace without fallback
177 */
178declare type NamespacedAmbiguity = {
179 namespaces: [FreeVarNamespace.Component | FreeVarNamespace.Helper | FreeVarNamespace.Modifier];
180 fallback: false;
181};
182declare type FallbackAmbiguity = {
183 namespaces: [];
184 fallback: true;
185};
186declare type Ambiguity = ComponentOrHelperAmbiguity | HelperAmbiguity | NamespacedAmbiguity | FallbackAmbiguity;
187export declare type FreeVarResolution = StrictResolution | LooseModeResolution;
188declare const enum SerializedAmbiguity {
189 Append = "Append",
190 Attr = "Attr",
191 Invoke = "Invoke"
192}
193export declare type SerializedResolution = 'Strict' | 'Loose' | ['ns', FreeVarNamespace] | ['ambiguous', SerializedAmbiguity];
194export declare function loadResolution(resolution: SerializedResolution): FreeVarResolution;
195export {};
196//# sourceMappingURL=resolution.d.ts.map
\No newline at end of file