@quenk/wml 2.11.2 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,18 +2,15 @@
2
2
  /// <reference path='generated.d.ts' />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.parse = void 0;
5
- var parser = require("./generated");
6
- var nodes = require("./ast");
7
- var error_1 = require("@quenk/noni/lib/control/error");
5
+ const parser = require("./generated");
6
+ const nodes = require("./ast");
7
+ const error_1 = require("@quenk/noni/lib/control/error");
8
8
  /**
9
9
  * parse a string containing WML returning the resulting AST.
10
10
  */
11
- var parse = function (str, ast) {
12
- if (ast === void 0) { ast = nodes; }
13
- return (0, error_1.attempt)(function () {
14
- parser.parser.yy = { ast: ast };
15
- return parser.parser.parse(str);
16
- });
17
- };
11
+ const parse = (str, ast = nodes) => (0, error_1.attempt)(() => {
12
+ parser.parser.yy = { ast };
13
+ return parser.parser.parse(str);
14
+ });
18
15
  exports.parse = parse;
19
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,uCAAuC;;;AAEvC,oCAAsC;AACtC,6BAA+B;AAE/B,uDAAgE;AAEhE;;GAEG;AACI,IAAM,KAAK,GAAG,UAAC,GAAW,EAAE,GAAgB;IAAhB,oBAAA,EAAA,WAAgB;IAC/C,OAAA,IAAA,eAAO,EAAC;QAEJ,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,KAAA,EAAE,CAAC;QAE3B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEpC,CAAC,CAAC;AANF,CAME,CAAC;AAPM,QAAA,KAAK,SAOX"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,uCAAuC;;;AAEvC,sCAAsC;AACtC,+BAA+B;AAE/B,yDAAgE;AAEhE;;GAEG;AACI,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,MAAW,KAAK,EAAwB,EAAE,CACzE,IAAA,eAAO,EAAC,GAAG,EAAE;IAET,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAE3B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAEpC,CAAC,CAAC,CAAC;AAPM,QAAA,KAAK,SAOX"}
package/lib/parse/test.js CHANGED
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tests = void 0;
4
4
  exports.tests = {
5
5
  'should parse qualified import': {
6
- input: "{% import * as lib from \"path/to/libs\" %}"
6
+ input: `{% import * as lib from "path/to/libs" %}`
7
7
  },
8
8
  'should parse named import': {
9
- input: "{% import (B) from \"path/to/a/b\" %}"
9
+ input: `{% import (B) from "path/to/a/b" %}`
10
10
  },
11
11
  'should detect exact duplicate imports': {
12
- input: "{% import (A) from \"b\" %} {% import (A) from \"b\" %}"
12
+ input: `{% import (A) from "b" %} {% import (A) from "b" %}`
13
13
  },
14
14
  'should parse a self closing tag': {
15
15
  input: '<simple/>'
@@ -70,6 +70,15 @@ exports.tests = {
70
70
  '{% endfor %}' +
71
71
  '</root>'
72
72
  },
73
+ 'should parse for from statements': {
74
+ input: `
75
+ <root>
76
+ {% for value=1 to 30 %}
77
+ <b>{{value}}</b>
78
+ {% endfor %}
79
+ </root>
80
+ `
81
+ },
73
82
  'should parse if then expressions': {
74
83
  input: '<Html id={{@id}}>{{ if @check() then a else b }}</Html>'
75
84
  },
@@ -92,7 +101,16 @@ exports.tests = {
92
101
  input: '<Tag>{% if value %}<text>Text</text>{% else %}<text>else</text>{% endif %}</Tag>'
93
102
  },
94
103
  'should parse if else if statements': {
95
- input: "\n <Tag>\n {% if value %}\n <text>Text</text>\n {% else if value %}\n <text>else</text>\n {% else %}\n no\n {% endif %}\n </Tag>"
104
+ input: `
105
+ <Tag>
106
+ {% if value %}
107
+ <text>Text</text>
108
+ {% else if value %}
109
+ <text>else</text>
110
+ {% else %}
111
+ no
112
+ {% endif %}
113
+ </Tag>`
96
114
  },
97
115
  'should parse short fun statements': {
98
116
  input: '{% fun vue () = <View/> %}'
@@ -143,7 +161,11 @@ exports.tests = {
143
161
  '[view] should parse typed views with type parameters': {
144
162
  input: '{% view Main [A,B] (Context[A,B]) %} <p>{{@values}}</p>'
145
163
  },
146
- '[view] should allow the where syntax': "\n\n {% view HeadView where title: String %}\n <title>{{@title}}</title>\n ",
164
+ '[view] should allow the where syntax': `
165
+
166
+ {% view HeadView where title: String %}
167
+ <title>{{@title}}</title>
168
+ `,
147
169
  'should parse context variables': {
148
170
  input: '<Input name={{@level.name}}/>'
149
171
  },
@@ -151,7 +173,10 @@ exports.tests = {
151
173
  input: '{% view MyView (Context from "./") %} <div>{{@text}}</div>'
152
174
  },
153
175
  '[view] should allow multiple inline context imports': {
154
- input: "\n {% view MyView (Context from \"./\") %} <div>{{@text}}</div>\n {% view YourView (Context from \"./\") %} <div/>\n "
176
+ input: `
177
+ {% view MyView (Context from "./") %} <div>{{@text}}</div>
178
+ {% view YourView (Context from "./") %} <div/>
179
+ `
155
180
  },
156
181
  'should allow construct expression': {
157
182
  input: '<TextView android:thing={value=1}>{{Person(@value)}}</TextView>'
@@ -172,10 +197,78 @@ exports.tests = {
172
197
  input: '<div>{{ <@action()> }}</div>'
173
198
  },
174
199
  'should allow view statements after short fun': {
175
- input: "\n\n{% fun template [A] (d: Date[A], o:A, _:String, __:A[]) = {{String(o)}} %}\n\n{% view Results [A](Date[A]) %}\n\n <ul>\n\n {% for option,index in [1,3,4] %}\n\n <li>{{option}}and{{index}}</li>\n\n {% else %}\n\n <p>De nada!</p>\n\n {% endfor %}\n\n </ul>"
200
+ input: `
201
+
202
+ {% fun template [A] (d: Date[A], o:A, _:String, __:A[]) = {{String(o)}} %}
203
+
204
+ {% view Results [A](Date[A]) %}
205
+
206
+ <ul>
207
+
208
+ {% for option,index in [1,3,4] %}
209
+
210
+ <li>{{option}}and{{index}}</li>
211
+
212
+ {% else %}
213
+
214
+ <p>De nada!</p>
215
+
216
+ {% endfor %}
217
+
218
+ </ul>`
176
219
  },
177
220
  'should allow actual code': {
178
- input: "\n {% import (Table) from \"@quenk/wml-widgets/lib/data/table\" %}\n {% import (TextField) from \"@quenk/wml-widgets/lib/control/text-field\" %}\n {% import (Panel) from \"@quenk/wml-widgets/lib/layout/panel\" %}\n {% import (PanelHeader) from \"@quenk/wml-widgets/lib/layout/panel\" %}\n {% import (Tab) from \"@quenk/wml-widgets/lib/control/tab-bar\" %}\n {% import (TabBar) from \"@quenk/wml-widgets/lib/control/tab-bar\" %}\n {% import (TabSpec) from \"..\" %}\n {% import (TabbedPanel) from \"..\" %}\n\n {% view Main (TabbedPanel) %}\n\n <Panel ww:class={{@values.root.class}}>\n\n {% if (@values.header.tabs.length > 0) || (@values.header.additionalTabs) %}\n\n <PanelHeader>\n\n <TabBar>\n\n {% for tab in @values.header.tabs %}\n\n <Tab\n ww:name={{tab.name}}\n ww:onClick={{tab.onClick}} />\n\n {% endfor %}\n\n {% if @values.header.additionalTabs %}\n\n {{<(@values.header.additionalTabs)(@)>}}\n\n {% else %}\n\n {{''}}\n\n {% endif %}\n\n </TabBar>\n\n </PanelHeader>\n\n {% else %}\n\n {{''}}\n\n {% endif %}\n\n {{@children}}\n\n</Panel>"
221
+ input: `
222
+ {% import (Table) from "@quenk/wml-widgets/lib/data/table" %}
223
+ {% import (TextField) from "@quenk/wml-widgets/lib/control/text-field" %}
224
+ {% import (Panel) from "@quenk/wml-widgets/lib/layout/panel" %}
225
+ {% import (PanelHeader) from "@quenk/wml-widgets/lib/layout/panel" %}
226
+ {% import (Tab) from "@quenk/wml-widgets/lib/control/tab-bar" %}
227
+ {% import (TabBar) from "@quenk/wml-widgets/lib/control/tab-bar" %}
228
+ {% import (TabSpec) from ".." %}
229
+ {% import (TabbedPanel) from ".." %}
230
+
231
+ {% view Main (TabbedPanel) %}
232
+
233
+ <Panel ww:class={{@values.root.class}}>
234
+
235
+ {% if (@values.header.tabs.length > 0) || (@values.header.additionalTabs) %}
236
+
237
+ <PanelHeader>
238
+
239
+ <TabBar>
240
+
241
+ {% for tab in @values.header.tabs %}
242
+
243
+ <Tab
244
+ ww:name={{tab.name}}
245
+ ww:onClick={{tab.onClick}} />
246
+
247
+ {% endfor %}
248
+
249
+ {% if @values.header.additionalTabs %}
250
+
251
+ {{<(@values.header.additionalTabs)(@)>}}
252
+
253
+ {% else %}
254
+
255
+ {{''}}
256
+
257
+ {% endif %}
258
+
259
+ </TabBar>
260
+
261
+ </PanelHeader>
262
+
263
+ {% else %}
264
+
265
+ {{''}}
266
+
267
+ {% endif %}
268
+
269
+ {{@children}}
270
+
271
+ </Panel>`
179
272
  },
180
273
  'should recognize type parameters': {
181
274
  input: '{% fun test[A:String] (a:A) %} {{a}} {% endfun %}'
@@ -191,57 +284,190 @@ exports.tests = {
191
284
  },
192
285
  '[context] should parse constructors': '{% context Test where name: String %}',
193
286
  '[context] should parse generic constructors': '{% context Test where table.name: Text[A] %}',
194
- '[context] should parse record types': "{% context Test[A] where\n \n table.data.record: { \n\n name: String,\n table.name: Text[A],\n table.data.list: A[] \n } \n %}",
195
- '[context] should parse list types': "{% context Test[A] where table.data.list: A[] %}",
196
- '[context] should parse 2d list types': "{% context Test[A,B] where table.data.list2: A[][] %}",
197
- '[context] should parse 3d list types': "{% context Test[A, B, C] where table.data.list3: A[][][] %}",
198
- '[context] should parse func with no args or parens': "{% context Test where value: Test -> Number %}",
199
- '[context] should parse func with no args': "{% context Test where value: () -> Number %}",
200
- '[context] should parse no-parens func with constructor': "{% context Test where value: String -> String %}",
201
- '[context] should parse no-parens func with generic constructor': "{% context Test where value: Text[A] -> Text[A] %}",
202
- '[context] should parse no-parens func with record arg': "{% context Test where value: {} -> { } %}",
203
- '[context] should parse no-parens func with list arg': "{% context Test where value: String[] -> String[] %}",
204
- '[context] should parse func with cons arg': "{% context Test where value: (String) -> String %}",
205
- '[context] should parse func with 2 cons args': "{% context Test where value: (String, String) -> String %}",
206
- '[context] should parse func with 3 cons args': "{% context Test where value: (String, String, String) -> String %}",
207
- '[context] should parse func with generic cons arg': "{% context Test[A] where value: (Text[A]) -> Text[A] %}",
208
- '[context] should parse func with 2 generic cons args': "{% context Test[A] where value: (Text[A], Text[A]) -> Text[A] %}",
209
- '[context] should parse func with 3 generic cons args': "{% context Test[A] where value: (Text[A], Text[A], Text[A]) -> Text[A] %}",
210
- '[context] should parse func with record arg': "{% context Test where value: ({ }) -> { } %}",
211
- '[context] should parse func with 2 record args': "{% context Test where value: ({ }, { name: String }) -> { } %}",
212
- '[context] should parse func with 3 record args': "{% context Test where value: ({ }, { name: String }, { value: A[]}) -> { } %}",
213
- '[context] should parse func with list arg': "{% context Test where value: (String[]) -> String[] %}",
214
- '[context] should parse func with 2 list args': "{% context Test where value: (String[], String[]) -> String[] %}",
215
- '[context] should parse func with 3 list args': "{% context Test where value: (String[], String[], String[]) -> String[] %}",
216
- '[context] should parse func with func arg': "{% context Test where value: (String -> String) -> String %}",
217
- '[context] should parse func with 2 func args': "{% context Test where value: ((String -> String), (String -> String)) -> String %}",
218
- '[context] should parse func with 3 func args': "{% context Test where\n value: ((String -> String), (String -> String), (String -> String)) -> String \n %}",
219
- '[context] should parse func that return array of generic type': "{% context Test[A] where value: Number -> Text[A][] %}",
220
- '[context] should parse funct that return array of array': "{% context Test where value: String -> Number[][] %}",
287
+ '[context] should parse record types': `{% context Test[A] where
288
+
289
+ table.data.record: {
290
+
291
+ name: String,
292
+ table.name: Text[A],
293
+ table.data.list: A[]
294
+ }
295
+ %}`,
296
+ '[context] should parse list types': `{% context Test[A] where table.data.list: A[] %}`,
297
+ '[context] should parse 2d list types': `{% context Test[A,B] where table.data.list2: A[][] %}`,
298
+ '[context] should parse 3d list types': `{% context Test[A, B, C] where table.data.list3: A[][][] %}`,
299
+ '[context] should parse func with no args or parens': `{% context Test where value: Test -> Number %}`,
300
+ '[context] should parse func with no args': `{% context Test where value: () -> Number %}`,
301
+ '[context] should parse no-parens func with constructor': `{% context Test where value: String -> String %}`,
302
+ '[context] should parse no-parens func with generic constructor': `{% context Test where value: Text[A] -> Text[A] %}`,
303
+ '[context] should parse no-parens func with record arg': `{% context Test where value: {} -> { } %}`,
304
+ '[context] should parse no-parens func with list arg': `{% context Test where value: String[] -> String[] %}`,
305
+ '[context] should parse func with cons arg': `{% context Test where value: (String) -> String %}`,
306
+ '[context] should parse func with 2 cons args': `{% context Test where value: (String, String) -> String %}`,
307
+ '[context] should parse func with 3 cons args': `{% context Test where value: (String, String, String) -> String %}`,
308
+ '[context] should parse func with generic cons arg': `{% context Test[A] where value: (Text[A]) -> Text[A] %}`,
309
+ '[context] should parse func with 2 generic cons args': `{% context Test[A] where value: (Text[A], Text[A]) -> Text[A] %}`,
310
+ '[context] should parse func with 3 generic cons args': `{% context Test[A] where value: (Text[A], Text[A], Text[A]) -> Text[A] %}`,
311
+ '[context] should parse func with record arg': `{% context Test where value: ({ }) -> { } %}`,
312
+ '[context] should parse func with 2 record args': `{% context Test where value: ({ }, { name: String }) -> { } %}`,
313
+ '[context] should parse func with 3 record args': `{% context Test where value: ({ }, { name: String }, { value: A[]}) -> { } %}`,
314
+ '[context] should parse func with list arg': `{% context Test where value: (String[]) -> String[] %}`,
315
+ '[context] should parse func with 2 list args': `{% context Test where value: (String[], String[]) -> String[] %}`,
316
+ '[context] should parse func with 3 list args': `{% context Test where value: (String[], String[], String[]) -> String[] %}`,
317
+ '[context] should parse func with func arg': `{% context Test where value: (String -> String) -> String %}`,
318
+ '[context] should parse func with 2 func args': `{% context Test where value: ((String -> String), (String -> String)) -> String %}`,
319
+ '[context] should parse func with 3 func args': `{% context Test where
320
+ value: ((String -> String), (String -> String), (String -> String)) -> String
321
+ %}`,
322
+ '[context] should parse func that return array of generic type': `{% context Test[A] where value: Number -> Text[A][] %}`,
323
+ '[context] should parse funct that return array of array': `{% context Test where value: String -> Number[][] %}`,
221
324
  '[context] should parse context definitions': {
222
- input: "{% context Manager[A] where\n\n name: String,\n\n table.name: Text[A],\n\n table.data.record: { name: String, table.name: Text[A], table.data.list: A[] },\n\n table.data.list: A[],\n\n table.data.list2: A[][],\n\n table.data.list3: A[][][],\n\n noArgsFunc1: -> Number,\n\n noArgsFunc0: () -> Number,\n\n noParensConsArgFunc: String -> String,\n\n noParensConsGenericArgFunc: Text[A] -> Text[A],\n\n noParensRecordArgFunc: { } -> { },\n\n noParensListArgFunc: String[] -> String[],\n\n parensConsArgFunc: (String) -> String,\n\n parensConsArg2Func: (String, String) -> String,\n\n parensConsArg3Func: (String, String, String) -> String,\n\n parensConsGenericArgFunc: (Text[A]) -> Text[A],\n\n parensConsGenericArg2Func: (Text[A], Text[A]) -> Text[A],\n\n parensConsGenericArg3Func: (Text[A], Text[A], Text[A]) -> Text[A],\n\n parensRecordArgFunc: ({ }) -> { },\n\n parensRecordArg2Func: ({ }, { name: String }) -> { },\n\n parensRecordArgFunc: ({ }, { name: String }, { value: A[]}) -> { },\n\n parensListArgFunc: (String[]) -> String[],\n\n parensListArg2Func: (String[], String[]) -> String[],\n\n parensListArg3Func: (String[], String[], String[]) -> String[],\n\n funcArgFunc1: (String -> String) -> String,\n\n funcArgFunc2: (String -> String -> String) -> String,\n\n funcArg2Func: ((String -> String), (String -> String)) -> String,\n\n funcArg3Func: ((String -> String), (String -> String), (String -> String)) -> String,\n\n funcRetGenArray: Number -> Text[A][],\n\n funcRetMultiArray: String -> Number[][]\n\n\n %} "
325
+ input: `{% context Manager[A] where
326
+
327
+ name: String,
328
+
329
+ table.name: Text[A],
330
+
331
+ table.data.record: { name: String, table.name: Text[A], table.data.list: A[] },
332
+
333
+ table.data.list: A[],
334
+
335
+ table.data.list2: A[][],
336
+
337
+ table.data.list3: A[][][],
338
+
339
+ noArgsFunc1: -> Number,
340
+
341
+ noArgsFunc0: () -> Number,
342
+
343
+ noParensConsArgFunc: String -> String,
344
+
345
+ noParensConsGenericArgFunc: Text[A] -> Text[A],
346
+
347
+ noParensRecordArgFunc: { } -> { },
348
+
349
+ noParensListArgFunc: String[] -> String[],
350
+
351
+ parensConsArgFunc: (String) -> String,
352
+
353
+ parensConsArg2Func: (String, String) -> String,
354
+
355
+ parensConsArg3Func: (String, String, String) -> String,
356
+
357
+ parensConsGenericArgFunc: (Text[A]) -> Text[A],
358
+
359
+ parensConsGenericArg2Func: (Text[A], Text[A]) -> Text[A],
360
+
361
+ parensConsGenericArg3Func: (Text[A], Text[A], Text[A]) -> Text[A],
362
+
363
+ parensRecordArgFunc: ({ }) -> { },
364
+
365
+ parensRecordArg2Func: ({ }, { name: String }) -> { },
366
+
367
+ parensRecordArgFunc: ({ }, { name: String }, { value: A[]}) -> { },
368
+
369
+ parensListArgFunc: (String[]) -> String[],
370
+
371
+ parensListArg2Func: (String[], String[]) -> String[],
372
+
373
+ parensListArg3Func: (String[], String[], String[]) -> String[],
374
+
375
+ funcArgFunc1: (String -> String) -> String,
376
+
377
+ funcArgFunc2: (String -> String -> String) -> String,
378
+
379
+ funcArg2Func: ((String -> String), (String -> String)) -> String,
380
+
381
+ funcArg3Func: ((String -> String), (String -> String), (String -> String)) -> String,
382
+
383
+ funcRetGenArray: Number -> Text[A][],
384
+
385
+ funcRetMultiArray: String -> Number[][]
386
+
387
+
388
+ %} `
223
389
  },
224
390
  '[context] should allow optional properties': {
225
- input: "{% context AContract where \n \n id?: Number,\n\n name.first: String,\n\n name.middle?: String,\n\n name.last?: String\n\n %}"
391
+ input: `{% context AContract where
392
+
393
+ id?: Number,
394
+
395
+ name.first: String,
396
+
397
+ name.middle?: String,
398
+
399
+ name.last?: String
400
+
401
+ %}`
226
402
  },
227
403
  '[context] should allow extending': {
228
- input: "{% context AContract where :BContract %}\n {% context CContract where :AContract, :BContract %}\n {% context DContract[Type] where :CContract, member: Type %}\n {% context EContract[A,B,C,D] where \n :BContract, \n :CContract, \n :DContract[D],\n member0: A,\n member1: B,\n member2: C\n %}\n {% context DContract where :AContract, member: DType %}"
229
- },
230
- '[context] should mark nested properties as optional if all are': "{% context Paper where object.\"type\"?: String %}",
231
- 'should parse type statements': "{% type Type = String | Number | Boolean | Type[] | Type -> Type %}",
232
- 'should parse tupe types': "{% type Tuple = [Number, String, Number] %}",
404
+ input: `{% context AContract where :BContract %}
405
+ {% context CContract where :AContract, :BContract %}
406
+ {% context DContract[Type] where :CContract, member: Type %}
407
+ {% context EContract[A,B,C,D] where
408
+ :BContract,
409
+ :CContract,
410
+ :DContract[D],
411
+ member0: A,
412
+ member1: B,
413
+ member2: C
414
+ %}
415
+ {% context DContract where :AContract, member: DType %}`
416
+ },
417
+ '[context] should mark nested properties as optional if all are': `{% context Paper where object."type"?: String %}`,
418
+ 'should parse type statements': `{% type Type = String | Number | Boolean | Type[] | Type -> Type %}`,
419
+ 'should parse tupe types': `{% type Tuple = [Number, String, Number] %}`,
233
420
  'should parse type assertion': '<Panel onClick={{ \e -> [*User]foo(e) }} />',
234
421
  'should parse partial application in expression': '<Link ww:text={{truncate(50)(@text)}} />',
235
- 'should transform special primitives': "<div>\n {% for kind in [\n String,\n Boolean,\n Number,\n Object,\n Undefined,\n Null,\n Void,\n Never,\n Any] %}\n {{ kind | text }}\n {% endfor %}\n </div>",
236
- 'should allow casting': "\n {% view Test (Object) %}\n <Widget\n val1={{String(@value)}}\n val2={{Number(@value)}}\n val3={{Boolean(@value)}} />\n ",
237
- 'should parse null query operator': "<div>{% if value ?? %}<b>True</b>{% else %}<b>False</b>{% endif %}</div>",
238
- '[let] should parse let statements': "{% let head:HeadCtx = {title = \"Foo\"} %}\n {% let head2:HeadCtx = {title = \"My Title\"} %}\n ",
239
- '[let] should be usable in a view': "\n {% view MyView(Object) %}\n {% let head:HeadViewContext = {title = \"My Title\"} %}\n <h1>{{<HeadView(head)>}}</h1>\n ",
240
- '[comment] should parse html comments': "<!-- This is an html comment. -->",
241
- '[comment] should parse wml comments': "{# This is a wml comment #}",
242
- '[comment] should parse wml comments in statements': "{% view Name {# This is a comment! #} (Object) %} <div/> %}",
243
- '[fun] should parse multi dimensional array parameters': "\n {% fun test (value:List[][]) %}<p/>{% endfun %}",
244
- 'should allow index access on context properties': "{% view Test (Object) %}\n <div>\n {% if @[\"type\"]?? %}\n <div/>\n {% endif %}\n </div>",
245
- 'should allow paths to use brackets': "\n {% view Test (Object) %} \n <div>\n {% if @values.controls[\"@type\"] %} value {% endif %}\n {% if @values.controls[\"@type\"].value %} value {% endif %}\n </div>"
422
+ 'should transform special primitives': `<div>
423
+ {% for kind in [
424
+ String,
425
+ Boolean,
426
+ Number,
427
+ Object,
428
+ Undefined,
429
+ Null,
430
+ Void,
431
+ Never,
432
+ Any] %}
433
+ {{ kind | text }}
434
+ {% endfor %}
435
+ </div>`,
436
+ 'should allow casting': `
437
+ {% view Test (Object) %}
438
+ <Widget
439
+ val1={{String(@value)}}
440
+ val2={{Number(@value)}}
441
+ val3={{Boolean(@value)}} />
442
+ `,
443
+ 'should parse null query operator': `<div>{% if value ?? %}<b>True</b>{% else %}<b>False</b>{% endif %}</div>`,
444
+ '[let] should parse let statements': `{% let head:HeadCtx = {title = "Foo"} %}
445
+ {% let head2:HeadCtx = {title = "My Title"} %}
446
+ `,
447
+ '[let] should be usable in a view': `
448
+ {% view MyView(Object) %}
449
+ {% let head:HeadViewContext = {title = "My Title"} %}
450
+ <h1>{{<HeadView(head)>}}</h1>
451
+ `,
452
+ '[comment] should parse html comments': `<!-- This is an html comment. -->`,
453
+ '[comment] should parse wml comments': `{# This is a wml comment #}`,
454
+ '[comment] should parse wml comments in statements': `{% view Name {# This is a comment! #} (Object) %} <div/> %}`,
455
+ '[fun] should parse multi dimensional array parameters': `
456
+ {% fun test (value:List[][]) %}<p/>{% endfun %}`,
457
+ 'should allow index access on context properties': `{% view Test (Object) %}
458
+ <div>
459
+ {% if @["type"]?? %}
460
+ <div/>
461
+ {% endif %}
462
+ </div>`,
463
+ 'should allow paths to use brackets': `
464
+ {% view Test (Object) %}
465
+ <div>
466
+ {% if @values.controls["@type"] %} value {% endif %}
467
+ {% if @values.controls["@type"].value %} value {% endif %}
468
+ </div>`,
469
+ 'should allow 2nd level bracket access': `<div>{% for item in our."items" %} <div/>{% endfor %}</div> `,
470
+ 'should allow type to be used in if statement expression': `<div>{% if item."type" == 1 %}<p/>{% endif %}</div>`,
471
+ 'should support the special wml:attrs attribute': `<Panel wml:attrs={{@panelAttrs}}><div wml:attrs={{divAttrs}}/></Panel>`
246
472
  };
247
473
  //# sourceMappingURL=test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":";;;AAAa,QAAA,KAAK,GAA2B;IAEzC,+BAA+B,EAAE;QAC7B,KAAK,EAAE,6CAA2C;KACrD;IACD,2BAA2B,EAAE;QACzB,KAAK,EAAE,uCAAqC;KAC/C;IACD,uCAAuC,EAAE;QACrC,KAAK,EAAE,yDAAqD;KAC/D;IACD,iCAAiC,EAAE;QAC/B,KAAK,EAAE,WAAW;KACrB;IACD,mDAAmD,EAAE;QACjD,KAAK,EAAE,6DAA6D;KACvE;IACD,mDAAmD,EAAE;QACjD,KAAK,EAAE,4BAA4B;KACtC;IACD,mDAAmD,EAAE;QACjD,KAAK,EAAE,8CAA8C;KACxD;IACD,2BAA2B,EAAE;QACzB,KAAK,EAAE,uCAAuC;KACjD;IACD,2CAA2C,EAAE;QACzC,KAAK,EAAE,wDAAwD;KAClE;IACD,8CAA8C,EAAE;QAC5C,KAAK,EAAE,oEAAoE;KAC9E;IACD,iDAAiD,EAAE;QAC/C,KAAK,EAAE,wBAAwB;KAClC;IACD,iDAAiD,EAAE;QAC/C,KAAK,EAAE,uDAAuD;YAC1D,gCAAgC;KACvC;IACD,iDAAiD,EAAE;QAC/C,KAAK,EAAE,8CAA8C;YACjD,gCAAgC;KACvC;IACD,+BAA+B,EAAE;QAE7B,KAAK,EAAE,oCAAoC;YACvC,uCAAuC;YACvC,cAAc;YACd,oDAAoD;YACpD,gBAA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;IAEjD,gDAAgD,EAC5C,0CAA0C;IAE9C,qCAAqC,EACjC;;;;;;;;;;;;;eAaO;IAEX,sBAAsB,EAAE;;;;;;OAMrB;IAEH,kCAAkC,EAC9B,0EAA0E;IAE9E,mCAAmC,EAC/B;;KAEH;IAED,kCAAkC,EAAE;;;;KAInC;IAED,sCAAsC,EAAE,mCAAmC;IAE3E,qCAAqC,EAAE,6BAA6B;IAEpE,mDAAmD,EAC/C,6DAA6D;IAEjE,uDAAuD,EAAE;oDACT;IAEhD,iDAAiD,EAC7C;;;;;aAKK;IAET,oCAAoC,EAAE;;;;;WAK/B;IAEP,uCAAuC,EACnC,8DAA8D;IAElE,yDAAyD,EACrD,qDAAqD;IAE3D,gDAAgD,EAChD,wEAAwE;CAEzE,CAAA"}
package/lib/parse/test.ts CHANGED
@@ -74,6 +74,16 @@ export const tests: { [key: string]: any } = {
74
74
  '</root>'
75
75
 
76
76
  },
77
+ 'should parse for from statements': {
78
+
79
+ input: `
80
+ <root>
81
+ {% for value=1 to 30 %}
82
+ <b>{{value}}</b>
83
+ {% endfor %}
84
+ </root>
85
+ `
86
+ },
77
87
  'should parse if then expressions': {
78
88
 
79
89
  input: '<Html id={{@id}}>{{ if @check() then a else b }}</Html>'
@@ -638,6 +648,15 @@ export const tests: { [key: string]: any } = {
638
648
  <div>
639
649
  {% if @values.controls["@type"] %} value {% endif %}
640
650
  {% if @values.controls["@type"].value %} value {% endif %}
641
- </div>`
651
+ </div>`,
652
+
653
+ 'should allow 2nd level bracket access':
654
+ `<div>{% for item in our."items" %} <div/>{% endfor %}</div> `,
655
+
656
+ 'should allow type to be used in if statement expression':
657
+ `<div>{% if item."type" == 1 %}<p/>{% endif %}</div>`,
658
+
659
+ 'should support the special wml:attrs attribute':
660
+ `<Panel wml:attrs={{@panelAttrs}}><div wml:attrs={{divAttrs}}/></Panel>`
642
661
 
643
662
  }