Skip to content

Commit 2ecf174

Browse files
committed
fix(mf2): Fix attributes on reserved & private annotation expressions
1 parent a020a84 commit 2ecf174

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

packages/mf2-messageformat/src/__fixtures/syntax-errors.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"missing space {|foo|:func}",
1818
"missing space {|foo|@bar}",
1919
"missing space {:func@bar}",
20+
"missing space {:func @bar@baz}",
21+
"missing space {:func @bar=42@baz}",
22+
"missing space {+reserved@bar}",
23+
"missing space {&private@bar}",
2024
"bad {:} placeholder",
2125
"bad {\\u0000placeholder}",
2226
"no-equal {|42| :number minimumFractionDigits 2}",

packages/mf2-messageformat/src/__fixtures/test-core.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@
114114
}
115115
]
116116
},
117+
{
118+
"src": "{#tag foo=bar/}",
119+
"cleanSrc": "{#tag foo=bar /}",
120+
"exp": "",
121+
"parts": [
122+
{
123+
"type": "markup",
124+
"kind": "standalone",
125+
"name": "tag",
126+
"options": { "foo": "bar" }
127+
}
128+
]
129+
},
117130
{
118131
"src": "{#tag a:foo=|foo| b:bar=$bar}",
119132
"params": { "bar": "b a r" },
@@ -136,5 +149,32 @@
136149
"src": "{42 @foo=$bar}",
137150
"exp": "42",
138151
"parts": [{ "type": "string", "value": "42" }]
152+
},
153+
{
154+
"src": "foo {+reserved}",
155+
"exp": "foo {+}",
156+
"parts": [
157+
{ "type": "literal", "value": "foo " },
158+
{ "type": "fallback", "source": "+" }
159+
],
160+
"errors": [{ "type": "unsupported-annotation" }]
161+
},
162+
{
163+
"src": "foo {&private}",
164+
"exp": "foo {&}",
165+
"parts": [
166+
{ "type": "literal", "value": "foo " },
167+
{ "type": "fallback", "source": "&" }
168+
],
169+
"errors": [{ "type": "unsupported-annotation" }]
170+
},
171+
{
172+
"src": "foo {?reserved @a @b=$c}",
173+
"exp": "foo {?}",
174+
"parts": [
175+
{ "type": "literal", "value": "foo " },
176+
{ "type": "fallback", "source": "?" }
177+
],
178+
"errors": [{ "type": "unsupported-annotation" }]
139179
}
140180
]

packages/mf2-messageformat/src/cst/expression.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export function parseReservedBody(
259259
case '|':
260260
pos = parseQuotedLiteral(ctx, pos).end;
261261
break;
262+
case '@':
262263
case '}':
263264
break loop;
264265
default: {

packages/mf2-messageformat/src/cst/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export interface FunctionRef {
151151
/** @beta */
152152
export interface ReservedAnnotation {
153153
type: 'reserved-annotation';
154-
open: Syntax<'!' | '#' | '%' | '^' | '&' | '*' | '<' | '>' | '?' | '~'>;
154+
open: Syntax<'!' | '%' | '^' | '&' | '*' | '+' | '<' | '>' | '?' | '~'>;
155155
source: Syntax<string>;
156156
start: number;
157157
end: number;

packages/mf2-messageformat/src/data-model/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export interface FunctionAnnotation {
222222
*/
223223
export interface UnsupportedAnnotation {
224224
type: 'unsupported-annotation';
225-
sigil: '!' | '#' | '%' | '^' | '&' | '*' | '<' | '>' | '?' | '~' | '�';
225+
sigil: '!' | '%' | '^' | '&' | '*' | '+' | '<' | '>' | '?' | '~' | '�';
226226
source: string;
227227
name?: never;
228228
options?: never;

packages/mf2-xliff/src/xliff-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ export interface MessageOption extends Element {
12341234
export interface MessageUnsupported extends Element {
12351235
name: 'mf:unsupported';
12361236
attributes: {
1237-
sigil: '!' | '#' | '%' | '^' | '&' | '*' | '<' | '>' | '?' | '~' | '�';
1237+
sigil: '!' | '%' | '^' | '&' | '*' | '+' | '<' | '>' | '?' | '~' | '�';
12381238
};
12391239
elements: (Text | CharCode)[];
12401240
}

0 commit comments

Comments
 (0)