File tree Expand file tree Collapse file tree 5 files changed +12
-16
lines changed
packages/message-compiler Expand file tree Collapse file tree 5 files changed +12
-16
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,6 @@ export function baseCompile(
2626 // transform ASTs
2727 transform ( ast , assignedOptions )
2828
29- // optimize ASTs
30- doOptimize && optimize ( ast )
31-
3229 // generate javascript codes
3330 return generate ( ast , assignedOptions )
3431 } else {
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ type MessageElementNode =
5050
5151export interface TextNode extends Node {
5252 type : NodeTypes . Text
53- value : string
53+ value ? : string
5454}
5555
5656export interface NamedNode extends Node {
@@ -65,7 +65,7 @@ export interface ListNode extends Node {
6565
6666export interface LiteralNode extends Node {
6767 type : NodeTypes . Literal
68- value : string
68+ value ? : string
6969}
7070
7171export interface LinkedNode extends Node {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ function optimizeMessageNode(message: MessageNode) {
1818 const item = message . items [ 0 ]
1919 if ( item . type === NodeTypes . Text || item . type === NodeTypes . Literal ) {
2020 message . static = item . value
21+ delete item . value // optimization for size
2122 }
2223 } else {
2324 const values : string [ ] = [ ]
@@ -26,10 +27,19 @@ function optimizeMessageNode(message: MessageNode) {
2627 if ( ! ( item . type === NodeTypes . Text || item . type === NodeTypes . Literal ) ) {
2728 break
2829 }
30+ if ( item . value == null ) {
31+ break
32+ }
2933 values . push ( item . value )
3034 }
3135 if ( values . length === message . items . length ) {
3236 message . static = join ( values )
37+ for ( let i = 0 ; i < message . items . length ; i ++ ) {
38+ const item = message . items [ i ]
39+ if ( item . type === NodeTypes . Text || item . type === NodeTypes . Literal ) {
40+ delete item . value // optimization for size
41+ }
42+ }
3343 }
3444 }
3545}
Original file line number Diff line number Diff line change @@ -263,7 +263,6 @@ exports[`compiler options > jit: true > ast 1`] = `
263263 " items" : [
264264 {
265265 " type" : 3 ,
266- " value" : " hello world" ,
267266 },
268267 ],
269268 " static" : " hello world" ,
@@ -282,7 +281,6 @@ exports[`compiler options > location: false > ast 1`] = `
282281 " value" : " hello world" ,
283282 },
284283 ],
285- " static" : " hello world" ,
286284 " type" : 2 ,
287285 },
288286 " type" : 0 ,
Original file line number Diff line number Diff line change @@ -6,15 +6,12 @@ exports[`full text items: foo{'@'}domain.com 1`] = `
66 " items" : [
77 {
88 " type" : 3 ,
9- " value" : " foo" ,
109 },
1110 {
1211 " type" : 9 ,
13- " value" : " @" ,
1412 },
1513 {
1614 " type" : 3 ,
17- " value" : " domain.com" ,
1815 },
1916 ],
2017@@ -32,7 +29,6 @@ exports[`full text message on plural: no apples | one apple | many apples 1`] =
3229 " items" : [
3330 {
3431 " type" : 3 ,
35- " value" : " no apples" ,
3632 },
3733 ],
3834 " static" : " no apples" ,
@@ -42,7 +38,6 @@ exports[`full text message on plural: no apples | one apple | many apples 1`] =
4238 " items" : [
4339 {
4440 " type" : 3 ,
45- " value" : " one apple" ,
4641 },
4742 ],
4843 " static" : " one apple" ,
@@ -52,7 +47,6 @@ exports[`full text message on plural: no apples | one apple | many apples 1`] =
5247 " items" : [
5348 {
5449 " type" : 3 ,
55- " value" : " many apples" ,
5650 },
5751 ],
5852 " static" : " many apples" ,
@@ -73,7 +67,6 @@ exports[`incldue dynamic node in pluarl: no apples | {0} apple | {n} apples 1`]
7367 " items" : [
7468 {
7569 " type" : 3 ,
76- " value" : " no apples" ,
7770 },
7871 ],
7972 " static" : " no apples" ,
@@ -141,7 +134,6 @@ exports[`literal only: {'hello world'} 1`] = `
141134 " items" : [
142135 {
143136 " type" : 9 ,
144- " value" : " hello world" ,
145137 },
146138 ],
147139 " static" : " hello world" ,
@@ -157,7 +149,6 @@ exports[`text only: hello world 1`] = `
157149 " items" : [
158150 {
159151 " type" : 3 ,
160- " value" : " hello world" ,
161152 },
162153 ],
163154 " static" : " hello world" ,
You can’t perform that action at this time.
0 commit comments