File tree Expand file tree Collapse file tree 4 files changed +118
-1
lines changed Expand file tree Collapse file tree 4 files changed +118
-1
lines changed Original file line number Diff line number Diff line change 11export enum NodeType {
22 Identifer = "Identifier" ,
3+ StringLiteral = "StringLiteral" ,
34 MessageReference = "MessageReference" ,
45 TextElement = "TextElement" ,
56 Placeable = "Placeable" ,
@@ -18,13 +19,19 @@ export interface Identifier extends SyntaxNode {
1819 readonly name : string ;
1920}
2021
22+ export interface StringLiteral extends SyntaxNode {
23+ readonly type : NodeType . StringLiteral ;
24+ readonly value : string ;
25+ parse ( ) : { value : string } ;
26+ }
27+
2128export interface MessageReference extends SyntaxNode {
2229 readonly type : NodeType . MessageReference ;
2330 readonly id : Identifier ;
2431 readonly attribute : Identifier | null ;
2532}
2633
27- export type InlineExpression = MessageReference ;
34+ export type InlineExpression = StringLiteral | MessageReference ;
2835
2936export type Expression = InlineExpression ;
3037
Original file line number Diff line number Diff line change @@ -16,13 +16,20 @@ export class Scope {
1616
1717 resolveExpression ( node : ast . Expression ) : Value {
1818 switch ( node . type ) {
19+ case ast . NodeType . StringLiteral :
20+ return this . resolveStringLiteral ( node as ast . StringLiteral ) ;
1921 case ast . NodeType . MessageReference :
2022 return this . resolveMessageReference ( node as ast . MessageReference ) ;
2123 default :
2224 throw new TypeError ( "Unknown node type." ) ;
2325 }
2426 }
2527
28+ resolveStringLiteral ( node : ast . StringLiteral ) : Value {
29+ let { value} = node . parse ( ) ;
30+ return new StringValue ( value ) ;
31+ }
32+
2633 resolveMessageReference ( node : ast . MessageReference ) : Value {
2734 let message = this . messages . get ( node . id . name ) ;
2835 if ( message == undefined ) {
Original file line number Diff line number Diff line change 1+ # StringLiteral
2+
3+ ` StringLiterals ` can be interpolated as ` Placeables ` inside ` Patterns ` . They
4+ format to their text content.
5+
6+ ``` properties
7+ test = {" Text" }
8+ ```
9+
10+ ``` json
11+ {
12+ "value" : " Text" ,
13+ "errors" : []
14+ }
15+ ```
16+
17+ All whitespace is preserved in ` StringLiterals ` .
18+
19+ ``` properties
20+ test = A {" " } B
21+ ```
22+
23+ ``` json
24+ {
25+ "value" : " A B" ,
26+ "errors" : []
27+ }
28+ ```
29+
30+ When positioned at the front or at the end of a ` Pattern ` , ` StringLiterals `
31+ can be used to preserve leading and trailing whitespace which would be
32+ otherwise trimmed inside ` TextElement ` .
33+
34+ ``` properties
35+ test = {" " }Text
36+ ```
37+
38+ ``` json
39+ {
40+ "value" : " Text" ,
41+ "errors" : []
42+ }
43+ ```
44+
45+ ## Escape Sequences
46+
47+ Escape sequences are supported in ` StringLiterals ` .
48+
49+ Characters from the Basic Multilingual Plane (BMP) can be escaped using the
50+ four-hexdigits escape sequences, starting with ` \u ` .
51+
52+ ``` properties
53+ test = {" \u0041" }
54+ ```
55+
56+ ``` json
57+ {
58+ "value" : " A" ,
59+ "errors" : []
60+ }
61+ ```
62+
63+ Astral characters can be escaped using the six-hexdigit escape sequences,
64+ starting with ` \U ` .
65+
66+ ``` properties
67+ test = {" \U01F602" }
68+ ```
69+
70+ ``` json
71+ {
72+ "value" : " 😂" ,
73+ "errors" : []
74+ }
75+ ```
76+
77+ A double-backslash can be used to obtain a single backslash in the formatting output.
78+
79+ ``` properties
80+ test = {" \\U01F602" }
81+ ```
82+
83+ ``` json
84+ {
85+ "value" : " \\ U01F602" ,
86+ "errors" : []
87+ }
88+ ```
Original file line number Diff line number Diff line change @@ -30,3 +30,18 @@ test =
3030 "errors" : []
3131}
3232```
33+
34+ ## Escape Sequences
35+
36+ Escape sequences are not supported in ` TextElements ` .
37+
38+ ``` properties
39+ test = \U01F602
40+ ```
41+
42+ ``` json
43+ {
44+ "value" : " \\ U01F602" ,
45+ "errors" : []
46+ }
47+ ```
You can’t perform that action at this time.
0 commit comments