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 1
1
export enum NodeType {
2
2
Identifer = "Identifier" ,
3
+ StringLiteral = "StringLiteral" ,
3
4
MessageReference = "MessageReference" ,
4
5
TextElement = "TextElement" ,
5
6
Placeable = "Placeable" ,
@@ -18,13 +19,19 @@ export interface Identifier extends SyntaxNode {
18
19
readonly name : string ;
19
20
}
20
21
22
+ export interface StringLiteral extends SyntaxNode {
23
+ readonly type : NodeType . StringLiteral ;
24
+ readonly value : string ;
25
+ parse ( ) : { value : string } ;
26
+ }
27
+
21
28
export interface MessageReference extends SyntaxNode {
22
29
readonly type : NodeType . MessageReference ;
23
30
readonly id : Identifier ;
24
31
readonly attribute : Identifier | null ;
25
32
}
26
33
27
- export type InlineExpression = MessageReference ;
34
+ export type InlineExpression = StringLiteral | MessageReference ;
28
35
29
36
export type Expression = InlineExpression ;
30
37
Original file line number Diff line number Diff line change @@ -16,13 +16,20 @@ export class Scope {
16
16
17
17
resolveExpression ( node : ast . Expression ) : Value {
18
18
switch ( node . type ) {
19
+ case ast . NodeType . StringLiteral :
20
+ return this . resolveStringLiteral ( node as ast . StringLiteral ) ;
19
21
case ast . NodeType . MessageReference :
20
22
return this . resolveMessageReference ( node as ast . MessageReference ) ;
21
23
default :
22
24
throw new TypeError ( "Unknown node type." ) ;
23
25
}
24
26
}
25
27
28
+ resolveStringLiteral ( node : ast . StringLiteral ) : Value {
29
+ let { value} = node . parse ( ) ;
30
+ return new StringValue ( value ) ;
31
+ }
32
+
26
33
resolveMessageReference ( node : ast . MessageReference ) : Value {
27
34
let message = this . messages . get ( node . id . name ) ;
28
35
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 =
30
30
"errors" : []
31
31
}
32
32
```
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