Skip to content

Commit

Permalink
Add some examples & explicitly allow wrapping input values
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Jul 13, 2024
1 parent ecb071c commit 28cb811
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion spec/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,23 @@ whether its value was originally _quoted_ or _unquoted_.
> For example,
> the _option_ `foo=42` and the _option_ `foo=|42|` are treated as identical.
The resolution of a _text_ or _literal_ MUST resolve to a string.
The resolution of a _text_ or _literal_ MUST resolve with a string value.
> For example, in a JavaScript formatter
> the _resolved value_ of a _text_ or a _literal_ could have the following implementation:
>
> ```ts
> class MessageLiteral implements MessageValue {
> constructor(value: string) {
> this.formatToString = () => value;
> this.getValue = () => value;
> }
> resolvedOptions: () => ({});
> selectKeys(_keys: string[]) {
> throw Error("Selection on unannotated literals is not supported");
> }
> }
> ```
### Variable Resolution
Expand All @@ -226,6 +242,9 @@ If a _declaration_ exists for the _variable_, its _resolved value_ is used.
Otherwise, the _variable_ is an implicit reference to an input value,
and its value is looked up from the _formatting context_ _input mapping_.
An implemementation MAY choose to wrap or otherwise represent all input values
using the same representation it uses for all _resolved values_.
The resolution of a _variable_ MAY fail if no value is identified for its _name_.
If this happens, an _Unresolved Variable_ error MUST be emitted.
If a _variable_ would resolve to a _fallback value_,
Expand Down Expand Up @@ -467,6 +486,23 @@ _Option_ _identifiers_ and values are not included in the _fallback value_.
_Pattern selection_ is not supported for _fallback values_.
> For example, in a JavaScript formatter
> the _fallback value_ could have the following implementation,
> where `source` is one of the above-defined strings:
>
> ```ts
> class MessageFallback implements MessageValue {
> constructor(source: string) {
> this.formatToString = () => `{${source}}`;
> this.getValue = () => undefined;
> }
> resolvedOptions: () => ({});
> selectKeys(_keys: string[]) {
> throw Error("Selection on fallback values is not supported");
> }
> }
> ```
## Pattern Selection
When a _message_ contains a _matcher_ with one or more _selectors_,
Expand Down

0 comments on commit 28cb811

Please sign in to comment.