Skip to content

Commit 28cb811

Browse files
committed
Add some examples & explicitly allow wrapping input values
1 parent ecb071c commit 28cb811

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

spec/formatting.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,23 @@ whether its value was originally _quoted_ or _unquoted_.
216216
> For example,
217217
> the _option_ `foo=42` and the _option_ `foo=|42|` are treated as identical.
218218
219-
The resolution of a _text_ or _literal_ MUST resolve to a string.
219+
The resolution of a _text_ or _literal_ MUST resolve with a string value.
220+
221+
> For example, in a JavaScript formatter
222+
> the _resolved value_ of a _text_ or a _literal_ could have the following implementation:
223+
>
224+
> ```ts
225+
> class MessageLiteral implements MessageValue {
226+
> constructor(value: string) {
227+
> this.formatToString = () => value;
228+
> this.getValue = () => value;
229+
> }
230+
> resolvedOptions: () => ({});
231+
> selectKeys(_keys: string[]) {
232+
> throw Error("Selection on unannotated literals is not supported");
233+
> }
234+
> }
235+
> ```
220236
221237
### Variable Resolution
222238
@@ -226,6 +242,9 @@ If a _declaration_ exists for the _variable_, its _resolved value_ is used.
226242
Otherwise, the _variable_ is an implicit reference to an input value,
227243
and its value is looked up from the _formatting context_ _input mapping_.
228244
245+
An implemementation MAY choose to wrap or otherwise represent all input values
246+
using the same representation it uses for all _resolved values_.
247+
229248
The resolution of a _variable_ MAY fail if no value is identified for its _name_.
230249
If this happens, an _Unresolved Variable_ error MUST be emitted.
231250
If a _variable_ would resolve to a _fallback value_,
@@ -467,6 +486,23 @@ _Option_ _identifiers_ and values are not included in the _fallback value_.
467486
468487
_Pattern selection_ is not supported for _fallback values_.
469488
489+
> For example, in a JavaScript formatter
490+
> the _fallback value_ could have the following implementation,
491+
> where `source` is one of the above-defined strings:
492+
>
493+
> ```ts
494+
> class MessageFallback implements MessageValue {
495+
> constructor(source: string) {
496+
> this.formatToString = () => `{${source}}`;
497+
> this.getValue = () => undefined;
498+
> }
499+
> resolvedOptions: () => ({});
500+
> selectKeys(_keys: string[]) {
501+
> throw Error("Selection on fallback values is not supported");
502+
> }
503+
> }
504+
> ```
505+
470506
## Pattern Selection
471507
472508
When a _message_ contains a _matcher_ with one or more _selectors_,

0 commit comments

Comments
 (0)