@quenk/wml 2.11.3 → 2.12.1

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,52 +2,43 @@
2
2
  /**
3
3
  * Typescript code generator.
4
4
  */
5
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
6
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
7
- if (ar || !(i in from)) {
8
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
9
- ar[i] = from[i];
10
- }
11
- }
12
- return to.concat(ar || Array.prototype.slice.call(from));
13
- };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.forOfStatement2TS = exports.forInStatement2TS = exports.ifStatement2TS = exports.interpolation2TS = exports.groupAttrs = exports.attrs2String = exports.attributeName2TS = exports.attributeValue2TS = exports.attribute2TS = exports.node2TS = exports.widget2TS = exports.tag2TS = exports.child2TS = exports.children2TS = exports.untypedParameter2TS = exports.typedParameter2TS = exports.parameter2TS = exports.parameters2TS = exports.typeMap2TS = exports.expandTypeMap = exports.typeMapFromRecordType = exports.typeMapFromMemberDecs = exports.memberDeclarations2TS = exports.recordType2Ts = exports.tupleType2TS = exports.listType2TS = exports.functionType2TS = exports.constructorType2TS = exports.type2TS = exports.typeParameter2TS = exports.typeParameters2TS = exports.viewStatement2TS = exports.funStatement2TS = exports.letStatement2TS = exports.contextStatement2TS = exports.aliasStatement2TS = exports.export2TS = exports.exports2TS = exports.compositeMember2TS = exports.aliasedMember2TS = exports.aggregateMember2TS = exports.importMember2TS = exports.importStatement2TS = exports.importStatements2TS = exports.CodeGenerator = exports.THIS = exports.DOCUMENT = exports.WML = exports.VIEW = exports.CONTEXT = void 0;
16
- exports.unqualifiedIdentifier2TS = exports.qualifiedIdentifier2TS = exports.identifier2TS = exports.qualifiedConstructor2TS = exports.unqualifiedConstructor2TS = exports.constructor2TS = exports.identifierOrConstructor2TS = exports.contextVariable2TS = exports.contextProperty2TS = exports.key2TS = exports.property2TS = exports.list2TS = exports.record2TS = exports.number2TS = exports.string2TS = exports.boolean2TS = exports.literal2TS = exports.functionExpression2TS = exports.memberExpression2TS = exports.args2TS = exports.typeArgs2TS = exports.callExpression2TS = exports.constructExpression2TS = exports.funApplication2TS = exports.viewConstruction2TS = exports.typeAssertion2TS = exports.unaryExpression2TS = exports.binaryExpression2TS = exports.ifThenExpression2TS = exports.expression2TS = exports.characters2TS = exports.forFromStatement2TS = void 0;
6
+ exports.forFromStatement2TS = exports.forOfStatement2TS = exports.forInStatement2TS = exports.ifStatement2TS = exports.interpolation2TS = exports.attrs2String = exports.attributeName2TS = exports.attributeValue2TS = exports.attribute2TS = exports.node2TS = exports.widget2TS = exports.tag2TS = exports.child2TS = exports.children2TS = exports.untypedParameter2TS = exports.typedParameter2TS = exports.parameter2TS = exports.parameters2TS = exports.typeMap2TS = exports.expandTypeMap = exports.typeMapFromRecordType = exports.typeMapFromMemberDecs = exports.memberDeclarations2TS = exports.recordType2Ts = exports.tupleType2TS = exports.listType2TS = exports.functionType2TS = exports.constructorType2TS = exports.type2TS = exports.typeParameter2TS = exports.typeParameters2TS = exports.viewStatement2TS = exports.funStatement2TS = exports.letStatement2TS = exports.contextStatement2TS = exports.aliasStatement2TS = exports.export2TS = exports.exports2TS = exports.compositeMember2TS = exports.aliasedMember2TS = exports.aggregateMember2TS = exports.importMember2TS = exports.importStatement2TS = exports.importStatements2TS = exports.CodeGenerator = exports.THIS = exports.DOCUMENT = exports.WML = exports.VIEW = exports.CONTEXT = void 0;
7
+ exports.unqualifiedIdentifier2TS = exports.qualifiedIdentifier2TS = exports.identifier2TS = exports.qualifiedConstructor2TS = exports.unqualifiedConstructor2TS = exports.constructor2TS = exports.identifierOrConstructor2TS = exports.contextVariable2TS = exports.contextProperty2TS = exports.key2TS = exports.property2TS = exports.list2TS = exports.record2TS = exports.number2TS = exports.string2TS = exports.boolean2TS = exports.literal2TS = exports.functionExpression2TS = exports.memberExpression2TS = exports.args2TS = exports.typeArgs2TS = exports.callExpression2TS = exports.constructExpression2TS = exports.funApplication2TS = exports.viewConstruction2TS = exports.typeAssertion2TS = exports.unaryExpression2TS = exports.binaryExpression2TS = exports.ifThenExpression2TS = exports.expression2TS = exports.characters2TS = void 0;
17
8
  /** imports */
18
- var ast = require("../parse/ast");
19
- var path_1 = require("@quenk/noni/lib/data/record/path");
20
- var record_1 = require("@quenk/noni/lib/data/record");
21
- var array_1 = require("@quenk/noni/lib/data/array");
22
- var transform_1 = require("./transform");
9
+ const ast = require("../parse/ast");
10
+ const path_1 = require("@quenk/noni/lib/data/record/path");
11
+ const record_1 = require("@quenk/noni/lib/data/record");
12
+ const array_1 = require("@quenk/noni/lib/data/array");
13
+ const transform_1 = require("./transform");
23
14
  exports.CONTEXT = '__context';
24
15
  exports.VIEW = '__view';
25
16
  exports.WML = '__wml';
26
17
  exports.DOCUMENT = '__document';
27
18
  exports.THIS = '__this';
28
- var MAYBE = '__Maybe';
29
- var FROM_NULLABLE = '__fromNullable';
30
- var FROM_ARRAY = '__fromArray';
31
- var NODE_PARAMS = "tag:string, attrs:".concat(exports.WML, ".Attrs, ") +
32
- "children: ".concat(exports.WML, ".Content[]");
33
- var WIDGET_PARAMS = "w: ".concat(exports.WML, ".Widget, attrs:").concat(exports.WML, ".Attrs");
34
- var REGISTER_VIEW_PARAMS = "v:".concat(exports.WML, ".View");
35
- var REGISTER_PARAMS = "e:".concat(exports.WML, ".WMLElement, ") +
36
- "attrs:".concat(exports.WML, ".Attributes<any>");
37
- var THROW_CHILD_ERR = ' throw new TypeError(`Can not adopt ' +
19
+ const MAYBE = '__Maybe';
20
+ const FROM_NULLABLE = '__fromNullable';
21
+ const FROM_ARRAY = '__fromArray';
22
+ const NODE_PARAMS = `tag:string, attrs:${exports.WML}.Attrs, ` +
23
+ `children: ${exports.WML}.Content[]`;
24
+ const WIDGET_PARAMS = `w: ${exports.WML}.Widget, attrs:${exports.WML}.Attrs`;
25
+ const REGISTER_VIEW_PARAMS = `v:${exports.WML}.View`;
26
+ const REGISTER_PARAMS = `e:${exports.WML}.WMLElement, ` +
27
+ `attrs:${exports.WML}.Attributes<any>`;
28
+ const THROW_CHILD_ERR = ' throw new TypeError(`Can not adopt ' +
38
29
  'child ${c} of type \${typeof c}`);';
39
- var THROW_INVALIDATE_ERR = " throw new Error('invalidate(): cannot " +
40
- "invalidate this view, it has no parent node!');";
41
- var IGNORE_UNUSED = '//@ts-ignore:6192';
42
- var RECORD = '__Record<A>';
43
- var IF = '__if';
44
- var IFARG = "__IfArg";
45
- var FOR_OF = '__forOf';
46
- var FOR_IN = '__forIn';
47
- var FOR_ALT_TYPE = '__ForAlt';
48
- var FOR_IN_BODY = '__ForInBody<A>';
49
- var FOR_OF_BODY = '__ForOfBody<A>';
50
- var prims = [
30
+ const THROW_INVALIDATE_ERR = ` throw new Error('invalidate(): cannot ` +
31
+ `invalidate this view, it has no parent node!');`;
32
+ const IGNORE_UNUSED = '//@ts-ignore:6192';
33
+ const RECORD = '__Record<A>';
34
+ const IF = '__if';
35
+ const IFARG = `__IfArg`;
36
+ const FOR_OF = '__forOf';
37
+ const FOR_IN = '__forIn';
38
+ const FOR_ALT_TYPE = '__ForAlt';
39
+ const FOR_IN_BODY = '__ForInBody<A>';
40
+ const FOR_OF_BODY = '__ForOfBody<A>';
41
+ const prims = [
51
42
  'String',
52
43
  'Boolean',
53
44
  'Number',
@@ -58,8 +49,8 @@ var prims = [
58
49
  'Never',
59
50
  'Any'
60
51
  ];
61
- var casters = ['String', 'Boolean', 'Number', 'Object'];
62
- var operators = {
52
+ const casters = ['String', 'Boolean', 'Number', 'Object'];
53
+ const operators = {
63
54
  '==': '===',
64
55
  '!=': '!=='
65
56
  };
@@ -70,125 +61,120 @@ var operators = {
70
61
  * Given a parsed tree (starting at ast.Module), its generate method will
71
62
  * provide a typescript module.
72
63
  */
73
- var CodeGenerator = /** @class */ (function () {
74
- function CodeGenerator(options) {
64
+ class CodeGenerator {
65
+ constructor(options) {
75
66
  this.options = options;
76
67
  }
77
68
  /**
78
69
  * create a new CodeGenerator instance.
79
70
  */
80
- CodeGenerator.create = function (opts) {
71
+ static create(opts) {
81
72
  return new CodeGenerator(opts);
82
- };
73
+ }
83
74
  /**
84
75
  * generate a Typescript module from an WML AST.
85
76
  */
86
- CodeGenerator.prototype.generate = function (tree) {
87
- var newTree = (0, transform_1.transformTree)(tree);
77
+ generate(tree) {
78
+ let newTree = (0, transform_1.transformTree)(tree);
88
79
  return [
89
- "import * as ".concat(exports.WML, " from '").concat(this.options.module, "';"),
90
- "import * as ".concat(exports.DOCUMENT, " from '").concat(this.options.dom, "';"),
80
+ `import * as ${exports.WML} from '${this.options.module}';`,
81
+ `import * as ${exports.DOCUMENT} from '${this.options.dom}';`,
91
82
  imports(this),
92
83
  (0, exports.importStatements2TS)(this, newTree.imports),
93
84
  eol(this),
94
85
  typeDefinitions(this),
95
86
  eol(this),
96
- "// @ts-ignore 6192",
97
- "const text = ".concat(exports.DOCUMENT, ".text;"),
98
- "// @ts-ignore 6192",
99
- "const unsafe = ".concat(exports.DOCUMENT, ".unsafe"),
100
- "// @ts-ignore 6192",
101
- "const isSet = (value:any) => value != null",
87
+ `// @ts-ignore 6192`,
88
+ `const text = ${exports.DOCUMENT}.text;`,
89
+ `// @ts-ignore 6192`,
90
+ `const unsafe = ${exports.DOCUMENT}.unsafe`,
91
+ `// @ts-ignore 6192`,
92
+ `const isSet = (value:any) => value != null`,
102
93
  (0, exports.exports2TS)(this, newTree.exports)
103
94
  ].join(eol(this));
104
- };
105
- return CodeGenerator;
106
- }());
95
+ }
96
+ }
107
97
  exports.CodeGenerator = CodeGenerator;
108
- var eol = function (ctx) { return "".concat(ctx.options.EOL); };
109
- var imports = function (ctx) { return [
110
- "//@ts-ignore: 6192",
111
- "import {",
112
- "Maybe as ".concat(MAYBE, ","),
113
- "fromNullable as ".concat(FROM_NULLABLE, ","),
114
- "fromArray as ".concat(FROM_ARRAY),
115
- "}",
116
- "from '@quenk/noni/lib/data/maybe';"
117
- ].join(eol(ctx)); };
118
- var typeDefinitions = function (ctx) { return [
119
- "".concat(IGNORE_UNUSED),
120
- "type ".concat(IFARG, " = ()=>").concat(exports.WML, ".Content[]"),
121
- "",
122
- "".concat(IGNORE_UNUSED),
123
- "type ".concat(FOR_ALT_TYPE, " = ()=> ").concat(exports.WML, ".Content[]"),
124
- "",
125
- "".concat(IGNORE_UNUSED),
126
- "type ".concat(FOR_IN_BODY, " =(val:A, idx:number, all:A[])=>") +
127
- "".concat(exports.WML, ".Content[]"),
128
- "",
129
- "".concat(IGNORE_UNUSED),
130
- "type ".concat(FOR_OF_BODY, " = (val:A, key:string, all:object) =>") +
131
- "".concat(exports.WML, ".Content[]"),
132
- "",
133
- "".concat(IGNORE_UNUSED),
134
- "interface ".concat(RECORD, " {"),
135
- "",
136
- " [key:string]: A",
137
- "",
138
- "}",
139
- "",
140
- "".concat(IGNORE_UNUSED),
141
- "const ".concat(IF, " = (__expr:boolean, __conseq:").concat(IFARG, ",__alt?:").concat(IFARG, ") ") +
142
- ": Content[]=>",
143
- "(__expr) ? __conseq() : __alt ? __alt() : [];",
144
- "",
145
- "".concat(IGNORE_UNUSED),
146
- "const ".concat(FOR_IN, " = <A>(list:A[], f:").concat(FOR_IN_BODY, ", alt:") +
147
- "".concat(FOR_ALT_TYPE, ") : ").concat(exports.WML, ".Content[] => {"),
148
- "",
149
- " let ret:".concat(exports.WML, ".Content[] = [];"),
150
- "",
151
- " for(let i=0; i<list.length; i++)",
152
- " ret = ret.concat(f(list[i], i, list));",
153
- "",
154
- " return ret.length === 0 ? alt() : ret;",
155
- "",
156
- "}",
157
- "".concat(IGNORE_UNUSED),
158
- "const ".concat(FOR_OF, " = <A>(o:").concat(RECORD, ", f:").concat(FOR_OF_BODY, ",") +
159
- "alt:".concat(FOR_ALT_TYPE, ") : ").concat(exports.WML, ".Content[] => {"),
160
- "",
161
- " let ret:".concat(exports.WML, ".Content[] = [];"),
162
- "",
163
- " for(let key in o)",
164
- " \t if(o.hasOwnProperty(key)) ",
165
- "\t ret = ret.concat(f((o)[key], key, o));",
166
- "",
167
- " return ret.length === 0 ? alt(): ret;",
168
- "",
169
- "}"
170
- ].join(eol(ctx)); };
98
+ const eol = (ctx) => `${ctx.options.EOL}`;
99
+ const imports = (ctx) => [
100
+ `//@ts-ignore: 6192`,
101
+ `import {`,
102
+ `Maybe as ${MAYBE},`,
103
+ `fromNullable as ${FROM_NULLABLE},`,
104
+ `fromArray as ${FROM_ARRAY}`,
105
+ `}`,
106
+ `from '@quenk/noni/lib/data/maybe';`
107
+ ].join(eol(ctx));
108
+ const typeDefinitions = (ctx) => [
109
+ `${IGNORE_UNUSED}`,
110
+ `type ${IFARG} = ()=>${exports.WML}.Content[]`,
111
+ ``,
112
+ `${IGNORE_UNUSED}`,
113
+ `type ${FOR_ALT_TYPE} = ()=> ${exports.WML}.Content[]`,
114
+ ``,
115
+ `${IGNORE_UNUSED}`,
116
+ `type ${FOR_IN_BODY} =(val:A, idx:number, all:A[])=>` +
117
+ `${exports.WML}.Content[]`,
118
+ ``,
119
+ `${IGNORE_UNUSED}`,
120
+ `type ${FOR_OF_BODY} = (val:A, key:string, all:object) =>` +
121
+ `${exports.WML}.Content[]`,
122
+ ``,
123
+ `${IGNORE_UNUSED}`,
124
+ `interface ${RECORD} {`,
125
+ ``,
126
+ ` [key:string]: A`,
127
+ ``,
128
+ `}`,
129
+ ``,
130
+ `${IGNORE_UNUSED}`,
131
+ `const ${IF} = (__expr:boolean, __conseq:${IFARG},__alt?:${IFARG}) ` +
132
+ `: Content[]=>`,
133
+ `(__expr) ? __conseq() : __alt ? __alt() : [];`,
134
+ ``,
135
+ `${IGNORE_UNUSED}`,
136
+ `const ${FOR_IN} = <A>(list:A[], f:${FOR_IN_BODY}, alt:` +
137
+ `${FOR_ALT_TYPE}) : ${exports.WML}.Content[] => {`,
138
+ ``,
139
+ ` let ret:${exports.WML}.Content[] = [];`,
140
+ ``,
141
+ ` for(let i=0; i<list.length; i++)`,
142
+ ` ret = ret.concat(f(list[i], i, list));`,
143
+ ``,
144
+ ` return ret.length === 0 ? alt() : ret;`,
145
+ ``,
146
+ `}`,
147
+ `${IGNORE_UNUSED}`,
148
+ `const ${FOR_OF} = <A>(o:${RECORD}, f:${FOR_OF_BODY},` +
149
+ `alt:${FOR_ALT_TYPE}) : ${exports.WML}.Content[] => {`,
150
+ ``,
151
+ ` let ret:${exports.WML}.Content[] = [];`,
152
+ ``,
153
+ ` for(let key in o)`,
154
+ ` if(o.hasOwnProperty(key)) `,
155
+ ` ret = ret.concat(f((o)[key], key, o));`,
156
+ ``,
157
+ ` return ret.length === 0 ? alt(): ret;`,
158
+ ``,
159
+ `}`
160
+ ].join(eol(ctx));
171
161
  /**
172
162
  * importStatements2TS converts a list of ImportStatements into typescript.
173
163
  */
174
- var importStatements2TS = function (ctx, list) {
175
- return list
176
- .map(exports.importStatement2TS)
177
- .filter(function (stmt, idx, list) { return list.indexOf(stmt) == idx; })
178
- .join(";".concat(eol(ctx)));
179
- };
164
+ const importStatements2TS = (ctx, list) => list
165
+ .map(exports.importStatement2TS)
166
+ .filter((stmt, idx, list) => list.indexOf(stmt) == idx)
167
+ .join(`;${eol(ctx)}`);
180
168
  exports.importStatements2TS = importStatements2TS;
181
169
  /**
182
170
  * importStatement2TS
183
171
  */
184
- var importStatement2TS = function (n) {
185
- return "import ".concat((0, exports.importMember2TS)(n.member), " from '").concat(n.module.value.trim(), "'; ");
186
- };
172
+ const importStatement2TS = (n) => `import ${(0, exports.importMember2TS)(n.member)} from '${n.module.value.trim()}'; `;
187
173
  exports.importStatement2TS = importStatement2TS;
188
174
  /**
189
175
  * importMember2TS
190
176
  */
191
- var importMember2TS = function (n) {
177
+ const importMember2TS = (n) => {
192
178
  if (n instanceof ast.AggregateMember)
193
179
  return (0, exports.aggregateMember2TS)(n);
194
180
  else if (n instanceof ast.AliasedMember)
@@ -202,38 +188,30 @@ exports.importMember2TS = importMember2TS;
202
188
  /**
203
189
  * aggregateMember2TS
204
190
  */
205
- var aggregateMember2TS = function (n) {
206
- return "* as ".concat((0, exports.identifierOrConstructor2TS)(n.id), " ");
207
- };
191
+ const aggregateMember2TS = (n) => `* as ${(0, exports.identifierOrConstructor2TS)(n.id)} `;
208
192
  exports.aggregateMember2TS = aggregateMember2TS;
209
193
  /**
210
194
  * aliasedMember2TS
211
195
  */
212
- var aliasedMember2TS = function (n) {
213
- return "".concat((0, exports.identifierOrConstructor2TS)(n.member), " ") +
214
- "as ".concat((0, exports.identifierOrConstructor2TS)(n.alias), " ");
215
- };
196
+ const aliasedMember2TS = (n) => `${(0, exports.identifierOrConstructor2TS)(n.member)} ` +
197
+ `as ${(0, exports.identifierOrConstructor2TS)(n.alias)} `;
216
198
  exports.aliasedMember2TS = aliasedMember2TS;
217
199
  /**
218
200
  * compositeMember2TS
219
201
  */
220
- var compositeMember2TS = function (n) {
221
- return '{' + (n.members.map(function (m) { return (m instanceof ast.AliasedMember) ?
222
- (0, exports.aliasedMember2TS)(m) :
223
- (0, exports.identifierOrConstructor2TS)(m); }).join(',')) + '}';
224
- };
202
+ const compositeMember2TS = (n) => '{' + (n.members.map(m => (m instanceof ast.AliasedMember) ?
203
+ (0, exports.aliasedMember2TS)(m) :
204
+ (0, exports.identifierOrConstructor2TS)(m)).join(',')) + '}';
225
205
  exports.compositeMember2TS = compositeMember2TS;
226
206
  /**
227
207
  * exports2TS converts a list of exports to typescript.
228
208
  */
229
- var exports2TS = function (ctx, list) {
230
- return list.map(function (e) { return (0, exports.export2TS)(ctx, e); }).join(';' + eol(ctx));
231
- };
209
+ const exports2TS = (ctx, list) => list.map(e => (0, exports.export2TS)(ctx, e)).join(';' + eol(ctx));
232
210
  exports.exports2TS = exports2TS;
233
211
  /**
234
212
  * export2TS
235
213
  */
236
- var export2TS = function (ctx, n) {
214
+ const export2TS = (ctx, n) => {
237
215
  if (n instanceof ast.AliasStatement)
238
216
  return (0, exports.aliasStatement2TS)(n);
239
217
  else if (n instanceof ast.ContextStatement)
@@ -253,27 +231,25 @@ exports.export2TS = export2TS;
253
231
  /**
254
232
  * aliasStatement2TS
255
233
  */
256
- var aliasStatement2TS = function (n) {
257
- var typeArgs = (n.typeParameters.length > 0) ?
234
+ const aliasStatement2TS = (n) => {
235
+ let typeArgs = (n.typeParameters.length > 0) ?
258
236
  (0, exports.typeParameters2TS)(n.typeParameters) : '';
259
- var preamble = "export type ".concat(n.id.value).concat(typeArgs);
260
- var members = n.members.map(function (m) { return (0, exports.type2TS)(m); }).join('|');
261
- return "".concat(preamble, " = ").concat(members, ";");
237
+ let preamble = `export type ${n.id.value}${typeArgs}`;
238
+ let members = n.members.map(m => (0, exports.type2TS)(m)).join('|');
239
+ return `${preamble} = ${members};`;
262
240
  };
263
241
  exports.aliasStatement2TS = aliasStatement2TS;
264
242
  /**
265
243
  * contextStatement2TS
266
244
  */
267
- var contextStatement2TS = function (n) {
268
- var preamble = "export interface ".concat(n.id.value);
269
- var typeArgs = (n.typeParameters.length > 0) ?
245
+ const contextStatement2TS = (n) => {
246
+ let preamble = `export interface ${n.id.value}`;
247
+ let typeArgs = (n.typeParameters.length > 0) ?
270
248
  (0, exports.typeParameters2TS)(n.typeParameters) : '';
271
- var _a = (0, array_1.partition)(n.members, function (member) {
272
- return member instanceof ast.ConstructorType;
273
- }), parents = _a[0], members = _a[1];
274
- var parentList = parents
249
+ let [parents, members] = (0, array_1.partition)(n.members, member => member instanceof ast.ConstructorType);
250
+ let parentList = parents
275
251
  .map(exports.constructorType2TS).join(',');
276
- parentList = (parentList !== '') ? " extends ".concat(parentList) : '';
252
+ parentList = (parentList !== '') ? ` extends ${parentList}` : '';
277
253
  return [
278
254
  preamble,
279
255
  typeArgs,
@@ -287,16 +263,14 @@ exports.contextStatement2TS = contextStatement2TS;
287
263
  /**
288
264
  * letStatement2TS
289
265
  */
290
- var letStatement2TS = function (ctx, n) {
291
- return _setStatement2TS(ctx, n, 'export const');
292
- };
266
+ const letStatement2TS = (ctx, n) => _setStatement2TS(ctx, n, 'export const');
293
267
  exports.letStatement2TS = letStatement2TS;
294
- var _setStatement2TS = function (ctx, n, preamble) {
295
- var id = (0, exports.identifier2TS)(n.id);
296
- var cons = (0, exports.constructorType2TS)(n.cons);
297
- preamble = "".concat(preamble, " ").concat(id, ":").concat(cons);
298
- var value = (0, exports.expression2TS)(ctx, n.expression);
299
- return "".concat(preamble, " = ").concat(value);
268
+ const _setStatement2TS = (ctx, n, preamble) => {
269
+ let id = (0, exports.identifier2TS)(n.id);
270
+ let cons = (0, exports.constructorType2TS)(n.cons);
271
+ preamble = `${preamble} ${id}:${cons}`;
272
+ let value = (0, exports.expression2TS)(ctx, n.expression);
273
+ return `${preamble} = ${value}`;
300
274
  };
301
275
  /**
302
276
  * funStatement2TS generates Typescript output for fun statements.
@@ -304,20 +278,20 @@ var _setStatement2TS = function (ctx, n, preamble) {
304
278
  * This is a curried function that first accepts zero or more arguments then
305
279
  * a single Registry, finally the content.
306
280
  */
307
- var funStatement2TS = function (ctx, n) {
308
- var id = (0, exports.unqualifiedIdentifier2TS)(n.id);
309
- var typeParams = (0, exports.typeParameters2TS)(n.typeParameters);
310
- var params = (0, exports.parameters2TS)(n.parameters);
311
- var factory = "(".concat(exports.THIS, ":").concat(exports.WML, ".Registry) : ").concat(exports.WML, ".Content[] =>");
312
- var body = (0, exports.children2TS)(ctx, n.body);
281
+ const funStatement2TS = (ctx, n) => {
282
+ let id = (0, exports.unqualifiedIdentifier2TS)(n.id);
283
+ let typeParams = (0, exports.typeParameters2TS)(n.typeParameters);
284
+ let params = (0, exports.parameters2TS)(n.parameters);
285
+ let factory = `(${exports.THIS}:${exports.WML}.Registry) : ${exports.WML}.Content[] =>`;
286
+ let body = (0, exports.children2TS)(ctx, n.body);
313
287
  return [
314
- "export const ".concat(id, " = "),
315
- "",
316
- "".concat(typeParams, "(").concat(params, ")=>").concat(factory, " {"),
317
- "",
318
- " return ".concat(body, ";"),
319
- "",
320
- "};"
288
+ `export const ${id} = `,
289
+ ``,
290
+ `${typeParams}(${params})=>${factory} {`,
291
+ ``,
292
+ ` return ${body};`,
293
+ ``,
294
+ `};`
321
295
  ].join(eol(ctx));
322
296
  };
323
297
  exports.funStatement2TS = funStatement2TS;
@@ -326,199 +300,197 @@ exports.funStatement2TS = funStatement2TS;
326
300
  *
327
301
  * This is a class with template and various useful helpers.
328
302
  */
329
- var viewStatement2TS = function (ctx, n) {
330
- var instances = n.directives.map(function (i) {
331
- return _setStatement2TS(ctx, i, 'let');
332
- }).join(";".concat(ctx.options.EOL));
333
- var id = n.id ? (0, exports.constructor2TS)(n.id) : 'Main';
334
- var typeParams = (0, exports.typeParameters2TS)(n.typeParameters);
335
- // This should be transformed to what we expect.
336
- var c = (0, exports.type2TS)(n.context);
337
- var template = (0, exports.tag2TS)(ctx, n.root);
303
+ const viewStatement2TS = (ctx, n) => {
304
+ let instances = n.directives.map(i => _setStatement2TS(ctx, i, 'let')).join(`;${ctx.options.EOL}`);
305
+ let id = n.id ? (0, exports.constructor2TS)(n.id) : 'Main';
306
+ let typeParams = (0, exports.typeParameters2TS)(n.typeParameters);
307
+ let context = (0, exports.type2TS)((n.context instanceof ast.ContextFromStatement) ?
308
+ n.context.cons : n.context);
309
+ let template = (0, exports.tag2TS)(ctx, n.root);
338
310
  return [
339
- "export class ".concat(id, " ").concat(typeParams, " implements ").concat(exports.WML, ".View {"),
340
- "",
341
- " constructor(".concat(exports.CONTEXT, ": ").concat(c, ") {"),
342
- "",
343
- " this.template = (".concat(exports.THIS, ":").concat(exports.WML, ".Registry) => {"),
344
- "",
345
- " ".concat(instances),
346
- "",
347
- " return ".concat(template, ";"),
348
- "",
349
- " }",
350
- "",
351
- " }",
352
- "",
353
- " ids: { [key: string]: ".concat(exports.WML, ".WMLElement } = {};"),
354
- "",
355
- " groups: { [key: string]: ".concat(exports.WML, ".WMLElement[] } = {};"),
356
- "",
357
- " views: ".concat(exports.WML, ".View[] = [];"),
358
- "",
359
- " widgets: ".concat(exports.WML, ".Widget[] = [];"),
360
- "",
361
- " tree: Node = <Node>".concat(exports.DOCUMENT, ".createElement('div');"),
362
- "",
363
- " template: ".concat(exports.WML, ".Template;"),
364
- "",
365
- " registerView(".concat(REGISTER_VIEW_PARAMS, ") : ").concat(exports.WML, ".View {"),
366
- "",
367
- " this.views.push(v);",
368
- "",
369
- " return v;",
370
- "",
371
- "}",
372
- " register(".concat(REGISTER_PARAMS, ") : ").concat(exports.WML, ".WMLElement {"),
373
- "",
374
- " let attrsMap = (<".concat(exports.WML, ".Attrs><any>attrs)"),
375
- "",
376
- " if(attrsMap.wml) {",
377
- "",
378
- " let {id, group} = attrsMap.wml;",
379
- "",
380
- " if(id != null) {",
381
- "",
382
- " if (this.ids.hasOwnProperty(id))",
383
- " throw new Error(`Duplicate id '${id}' detected!`);",
384
- "",
385
- " this.ids[id] = e;",
386
- "",
387
- " }",
388
- "",
389
- " if(group != null) {",
390
- "",
391
- " this.groups[group] = this.groups[group] || [];",
392
- " this.groups[group].push(e);",
393
- "",
394
- " }",
395
- "",
396
- " }",
397
- " return e;",
398
- "}",
399
- "",
400
- " node(".concat(NODE_PARAMS, "): ").concat(exports.WML, ".Content {"),
401
- "",
402
- " let e = ".concat(exports.DOCUMENT, ".createElement(tag);"),
403
- "",
404
- " Object.keys(attrs).forEach(key => {",
405
- "",
406
- " let value = (<any>attrs)[key];",
407
- "",
408
- " if (typeof value === 'function') {",
409
- "",
410
- " (<any>e)[key] = value;",
411
- "",
412
- " } else if (typeof value === 'string') {",
413
- "",
414
- " //prevent setting things like disabled=''",
415
- " if (value !== '')",
416
- " e.setAttribute(key, value);",
417
- "",
418
- " } else if (typeof value === 'boolean') {",
419
- "",
420
- " e.setAttribute(key, '');",
421
- "",
422
- " } else if(!".concat(exports.DOCUMENT, ".isBrowser && "),
423
- " value instanceof ".concat(exports.DOCUMENT, ".WMLDOMText) {"),
424
- "",
425
- " e.setAttribute(key, <any>value);",
426
- "",
427
- " }",
428
- "",
429
- " });",
430
- "",
431
- " children.forEach(c => {",
432
- "",
433
- " switch (typeof c) {",
434
- "",
435
- " case 'string':",
436
- " case 'number':",
437
- " case 'boolean':",
438
- " let tn = ".concat(exports.DOCUMENT, ".createTextNode(''+c);"),
439
- " e.appendChild(<Node>tn)",
440
- " case 'object':",
441
- " e.appendChild(<Node>c);",
442
- " break;",
443
- " default:",
444
- " ".concat(THROW_CHILD_ERR),
445
- "",
446
- " }})",
447
- "",
448
- " this.register(e, attrs);",
449
- "",
450
- " return e;",
451
- "",
452
- " }",
453
- "",
454
- "",
455
- " widget(".concat(WIDGET_PARAMS, ") : ").concat(exports.WML, ".Content {"),
456
- "",
457
- " this.register(w, attrs);",
458
- "",
459
- " this.widgets.push(w);",
460
- "",
461
- " return w.render();",
462
- "",
463
- " }",
464
- "",
465
- " findById<E extends ".concat(exports.WML, ".WMLElement>(id: string): ").concat(MAYBE, "<E> {"),
466
- "",
467
- " let mW:".concat(MAYBE, "<E> = ").concat(FROM_NULLABLE, "<E>(<E>this.ids[id])"),
468
- "",
469
- " return this.views.reduce((p,c)=>",
470
- " p.isJust() ? p : c.findById(id), mW);",
471
- "",
472
- " }",
473
- "",
474
- " findByGroup<E extends ".concat(exports.WML, ".WMLElement>(name: string): ") +
475
- "".concat(MAYBE, "<E[]> {"),
476
- "",
477
- " let mGroup:".concat(MAYBE, "<E[]> ="),
478
- " ".concat(FROM_ARRAY, "(this.groups.hasOwnProperty(name) ?"),
479
- " <any>this.groups[name] : ",
480
- " []);",
481
- "",
482
- " return this.views.reduce((p,c) =>",
483
- " p.isJust() ? p : c.findByGroup(name), mGroup);",
484
- "",
485
- " }",
486
- "",
487
- " invalidate() : void {",
488
- "",
489
- " let {tree} = this;",
490
- " let parent = <Node>tree.parentNode;",
491
- "",
492
- " if (tree == null)",
493
- " return console.warn('invalidate(): '+" +
494
- " 'Missing DOM tree!');",
495
- "",
496
- " if (tree.parentNode == null)",
497
- " ".concat(THROW_INVALIDATE_ERR),
498
- "",
499
- " parent.replaceChild(<Node>this.render(), tree) ",
500
- "",
501
- " }",
502
- "",
503
- " render(): ".concat(exports.WML, ".Content {"),
504
- "",
505
- " this.ids = {};",
506
- " this.widgets.forEach(w => w.removed());",
507
- " this.widgets = [];",
508
- " this.views = [];",
509
- " this.tree = <Node>this.template(this);",
510
- "",
511
- " this.ids['root'] = (this.ids['root']) ?",
512
- " this.ids['root'] : ",
513
- " this.tree;",
514
- "",
515
- " this.widgets.forEach(w => w.rendered());",
516
- "",
517
- " return this.tree;",
518
- "",
519
- " }",
520
- "",
521
- "}"
311
+ `export class ${id} ${typeParams} implements ${exports.WML}.View {`,
312
+ ``,
313
+ ` constructor(${exports.CONTEXT}: ${context}) {`,
314
+ ``,
315
+ ` this.template = (${exports.THIS}:${exports.WML}.Registry) => {`,
316
+ ``,
317
+ ` ${instances}`,
318
+ ``,
319
+ ` return ${template};`,
320
+ ``,
321
+ ` }`,
322
+ ``,
323
+ ` }`,
324
+ ``,
325
+ ` ids: { [key: string]: ${exports.WML}.WMLElement } = {};`,
326
+ ``,
327
+ ` groups: { [key: string]: ${exports.WML}.WMLElement[] } = {};`,
328
+ ``,
329
+ ` views: ${exports.WML}.View[] = [];`,
330
+ ``,
331
+ ` widgets: ${exports.WML}.Widget[] = [];`,
332
+ ``,
333
+ ` tree: Node = <Node>${exports.DOCUMENT}.createElement('div');`,
334
+ ``,
335
+ ` template: ${exports.WML}.Template;`,
336
+ ``,
337
+ ` registerView(${REGISTER_VIEW_PARAMS}) : ${exports.WML}.View {`,
338
+ ``,
339
+ ` this.views.push(v);`,
340
+ ``,
341
+ ` return v;`,
342
+ ``,
343
+ `}`,
344
+ ` register(${REGISTER_PARAMS}) : ${exports.WML}.WMLElement {`,
345
+ ``,
346
+ ` let attrsMap = (<${exports.WML}.Attrs><any>attrs)`,
347
+ ``,
348
+ ` if(attrsMap.wml) {`,
349
+ ``,
350
+ ` let {id, group} = attrsMap.wml;`,
351
+ ``,
352
+ ` if(id != null) {`,
353
+ ``,
354
+ ` if (this.ids.hasOwnProperty(id))`,
355
+ ` throw new Error(\`Duplicate id '\${id}' detected!\`);`,
356
+ ``,
357
+ ` this.ids[id] = e;`,
358
+ ``,
359
+ ` }`,
360
+ ``,
361
+ ` if(group != null) {`,
362
+ ``,
363
+ ` this.groups[group] = this.groups[group] || [];`,
364
+ ` this.groups[group].push(e);`,
365
+ ``,
366
+ ` }`,
367
+ ``,
368
+ ` }`,
369
+ ` return e;`,
370
+ `}`,
371
+ ``,
372
+ ` node(${NODE_PARAMS}): ${exports.WML}.Content {`,
373
+ ``,
374
+ ` let e = ${exports.DOCUMENT}.createElement(tag);`,
375
+ ``,
376
+ ` Object.keys(attrs).forEach(key => {`,
377
+ ``,
378
+ ` let value = (<any>attrs)[key];`,
379
+ ``,
380
+ ` if (typeof value === 'function') {`,
381
+ ``,
382
+ ` (<any>e)[key] = value;`,
383
+ ``,
384
+ ` } else if (typeof value === 'string') {`,
385
+ ``,
386
+ ` //prevent setting things like disabled=''`,
387
+ ` if (value !== '')`,
388
+ ` e.setAttribute(key, value);`,
389
+ ``,
390
+ ` } else if (typeof value === 'boolean') {`,
391
+ ``,
392
+ ` e.setAttribute(key, '');`,
393
+ ``,
394
+ ` } else if(!${exports.DOCUMENT}.isBrowser && `,
395
+ ` value instanceof ${exports.DOCUMENT}.WMLDOMText) {`,
396
+ ``,
397
+ ` e.setAttribute(key, <any>value);`,
398
+ ``,
399
+ ` }`,
400
+ ``,
401
+ ` });`,
402
+ ``,
403
+ ` children.forEach(c => {`,
404
+ ``,
405
+ ` switch (typeof c) {`,
406
+ ``,
407
+ ` case 'string':`,
408
+ ` case 'number':`,
409
+ ` case 'boolean':`,
410
+ ` let tn = ${exports.DOCUMENT}.createTextNode(''+c);`,
411
+ ` e.appendChild(<Node>tn)`,
412
+ ` case 'object':`,
413
+ ` e.appendChild(<Node>c);`,
414
+ ` break;`,
415
+ ` default:`,
416
+ ` ${THROW_CHILD_ERR}`,
417
+ ``,
418
+ ` }})`,
419
+ ``,
420
+ ` this.register(e, attrs);`,
421
+ ``,
422
+ ` return e;`,
423
+ ``,
424
+ ` }`,
425
+ ``,
426
+ ``,
427
+ ` widget(${WIDGET_PARAMS}) : ${exports.WML}.Content {`,
428
+ ``,
429
+ ` this.register(w, attrs);`,
430
+ ``,
431
+ ` this.widgets.push(w);`,
432
+ ``,
433
+ ` return w.render();`,
434
+ ``,
435
+ ` }`,
436
+ ``,
437
+ ` findById<E extends ${exports.WML}.WMLElement>(id: string): ${MAYBE}<E> {`,
438
+ ``,
439
+ ` let mW:${MAYBE}<E> = ${FROM_NULLABLE}<E>(<E>this.ids[id])`,
440
+ ``,
441
+ ` return this.views.reduce((p,c)=>`,
442
+ ` p.isJust() ? p : c.findById(id), mW);`,
443
+ ``,
444
+ ` }`,
445
+ ``,
446
+ ` findByGroup<E extends ${exports.WML}.WMLElement>(name: string): ` +
447
+ `${MAYBE}<E[]> {`,
448
+ ``,
449
+ ` let mGroup:${MAYBE}<E[]> =`,
450
+ ` ${FROM_ARRAY}(this.groups.hasOwnProperty(name) ?`,
451
+ ` <any>this.groups[name] : `,
452
+ ` []);`,
453
+ ``,
454
+ ` return this.views.reduce((p,c) =>`,
455
+ ` p.isJust() ? p : c.findByGroup(name), mGroup);`,
456
+ ``,
457
+ ` }`,
458
+ ``,
459
+ ` invalidate() : void {`,
460
+ ``,
461
+ ` let {tree} = this;`,
462
+ ` let parent = <Node>tree.parentNode;`,
463
+ ``,
464
+ ` if (tree == null)`,
465
+ ` return console.warn('invalidate(): '+` +
466
+ ` 'Missing DOM tree!');`,
467
+ ``,
468
+ ` if (tree.parentNode == null)`,
469
+ ` ${THROW_INVALIDATE_ERR}`,
470
+ ``,
471
+ ` parent.replaceChild(<Node>this.render(), tree) `,
472
+ ``,
473
+ ` }`,
474
+ ``,
475
+ ` render(): ${exports.WML}.Content {`,
476
+ ``,
477
+ ` this.ids = {};`,
478
+ ` this.widgets.forEach(w => w.removed());`,
479
+ ` this.widgets = [];`,
480
+ ` this.views = [];`,
481
+ ` this.tree = <Node>this.template(this);`,
482
+ ``,
483
+ ` this.ids['root'] = (this.ids['root']) ?`,
484
+ ` this.ids['root'] : `,
485
+ ` this.tree;`,
486
+ ``,
487
+ ` this.widgets.forEach(w => w.rendered());`,
488
+ ``,
489
+ ` return this.tree;`,
490
+ ``,
491
+ ` }`,
492
+ ``,
493
+ `}`
522
494
  ].join(eol(ctx));
523
495
  };
524
496
  exports.viewStatement2TS = viewStatement2TS;
@@ -526,22 +498,18 @@ exports.viewStatement2TS = viewStatement2TS;
526
498
  * typeParameters2TS converts a list of typeParameters2TS into the a list of
527
499
  * typescript typeParameters2TS.
528
500
  */
529
- var typeParameters2TS = function (ns) {
530
- return (ns.length === 0) ? '' : "<".concat(ns.map(exports.typeParameter2TS).join(','), "> ");
531
- };
501
+ const typeParameters2TS = (ns) => (ns.length === 0) ? '' : `<${ns.map(exports.typeParameter2TS).join(',')}> `;
532
502
  exports.typeParameters2TS = typeParameters2TS;
533
503
  /**
534
504
  * typeParameter2TS converts a type parameter into a typescript type parameter.
535
505
  */
536
- var typeParameter2TS = function (n) {
537
- return "".concat(toPrim((0, exports.identifierOrConstructor2TS)(n.id)), " ") +
538
- "".concat(n.constraint ? 'extends ' + (0, exports.type2TS)(n.constraint) : '', " ");
539
- };
506
+ const typeParameter2TS = (n) => `${toPrim((0, exports.identifierOrConstructor2TS)(n.id))} ` +
507
+ `${n.constraint ? 'extends ' + (0, exports.type2TS)(n.constraint) : ''} `;
540
508
  exports.typeParameter2TS = typeParameter2TS;
541
509
  /**
542
510
  * type2TS
543
511
  */
544
- var type2TS = function (n) {
512
+ const type2TS = (n) => {
545
513
  if (n instanceof ast.ConstructorType)
546
514
  return (0, exports.constructorType2TS)(n);
547
515
  else if (n instanceof ast.RecordType)
@@ -566,8 +534,8 @@ exports.type2TS = type2TS;
566
534
  *
567
535
  * If the node is generic, the type parameters will be generated as well.
568
536
  */
569
- var constructorType2TS = function (n) {
570
- var id = toPrim((0, exports.identifierOrConstructor2TS)(n.id));
537
+ const constructorType2TS = (n) => {
538
+ let id = toPrim((0, exports.identifierOrConstructor2TS)(n.id));
571
539
  return (n.typeParameters.length > 0) ?
572
540
  id + (0, exports.typeParameters2TS)(n.typeParameters) : id;
573
541
  };
@@ -575,33 +543,27 @@ exports.constructorType2TS = constructorType2TS;
575
543
  /**
576
544
  * functionType2TS
577
545
  */
578
- var functionType2TS = function (n) {
579
- var params = n.parameters.map(function (t, k) { return "$".concat(k, ":").concat((0, exports.type2TS)(t)); }).join(',');
580
- var ret = (0, exports.type2TS)(n.returnType);
581
- return "(".concat(params, ") => ").concat(ret);
546
+ const functionType2TS = (n) => {
547
+ let params = n.parameters.map((t, k) => `$${k}:${(0, exports.type2TS)(t)}`).join(',');
548
+ let ret = (0, exports.type2TS)(n.returnType);
549
+ return `(${params}) => ${ret}`;
582
550
  };
583
551
  exports.functionType2TS = functionType2TS;
584
552
  /**
585
553
  * listType2TS
586
554
  */
587
- var listType2TS = function (n) {
588
- return "(".concat((0, exports.type2TS)(n.elementType), ")[]");
589
- };
555
+ const listType2TS = (n) => `(${(0, exports.type2TS)(n.elementType)})[]`;
590
556
  exports.listType2TS = listType2TS;
591
557
  /**
592
558
  * tupleType2TS
593
559
  */
594
- var tupleType2TS = function (n) {
595
- return "[".concat(n.members.map(exports.type2TS).join(','), "]");
596
- };
560
+ const tupleType2TS = (n) => `[${n.members.map(exports.type2TS).join(',')}]`;
597
561
  exports.tupleType2TS = tupleType2TS;
598
562
  /**
599
563
  * recordType2TS converts the RecordType node to the body of a TypeScript
600
564
  * record interface.
601
565
  */
602
- var recordType2Ts = function (n) {
603
- return '{' + (0, exports.memberDeclarations2TS)(n.members) + '}';
604
- };
566
+ const recordType2Ts = (n) => '{' + (0, exports.memberDeclarations2TS)(n.members) + '}';
605
567
  exports.recordType2Ts = recordType2Ts;
606
568
  /**
607
569
  * memberDeclarations2TS converts a list of MemberDeclarations to TypeScript.
@@ -609,29 +571,25 @@ exports.recordType2Ts = recordType2Ts;
609
571
  * The paths of the MemberDeclarations are expanded so that paths
610
572
  * using the "<path1>.<path2>.<path3>" syntax occur as nested records.
611
573
  */
612
- var memberDeclarations2TS = function (n) {
613
- return (0, exports.typeMap2TS)((0, exports.expandTypeMap)((0, exports.typeMapFromMemberDecs)(n)));
614
- };
574
+ const memberDeclarations2TS = (n) => (0, exports.typeMap2TS)((0, exports.expandTypeMap)((0, exports.typeMapFromMemberDecs)(n)));
615
575
  exports.memberDeclarations2TS = memberDeclarations2TS;
616
576
  /**
617
577
  * typeMapFromMemberDecs creates a TypeMap from a list of memberDeclarations.
618
578
  *
619
579
  * This works recursively and any RecordTypes encountered will be flattened.
620
580
  */
621
- var typeMapFromMemberDecs = function (list) {
622
- return list.reduce(function (p, m) {
623
- var paths = m.path.map(function (p) { return p.value; });
624
- if (m.kind instanceof ast.RecordType) {
625
- return (0, exports.typeMapFromRecordType)(m.kind, p, paths);
626
- }
627
- else {
628
- var path = paths2String(paths);
629
- path = m.optional ? "".concat(path, "?") : path;
630
- p[path] = m.kind;
631
- return p;
632
- }
633
- }, {});
634
- };
581
+ const typeMapFromMemberDecs = (list) => list.reduce((p, m) => {
582
+ let paths = m.path.map(p => p.value);
583
+ if (m.kind instanceof ast.RecordType) {
584
+ return (0, exports.typeMapFromRecordType)(m.kind, p, paths);
585
+ }
586
+ else {
587
+ let path = paths2String(paths);
588
+ path = m.optional ? `${path}?` : path;
589
+ p[path] = m.kind;
590
+ return p;
591
+ }
592
+ }, {});
635
593
  exports.typeMapFromMemberDecs = typeMapFromMemberDecs;
636
594
  /**
637
595
  * typeMapFromRecordType produces a map of node.Type instances from
@@ -639,59 +597,47 @@ exports.typeMapFromMemberDecs = typeMapFromMemberDecs;
639
597
  *
640
598
  * Any encountered RecordTypes will be flattened.
641
599
  */
642
- var typeMapFromRecordType = function (n, init, prefix) {
643
- return n.members.reduce(function (p, m) {
644
- var path = __spreadArray(__spreadArray([], prefix, true), (m.path.map(function (p) { return p.value; })), true);
645
- if (m.kind instanceof ast.RecordType) {
646
- return (0, exports.typeMapFromRecordType)(m.kind, init, path);
647
- }
648
- else {
649
- p[paths2String(path)] = m.kind;
650
- return p;
651
- }
652
- }, init);
653
- };
600
+ const typeMapFromRecordType = (n, init, prefix) => n.members.reduce((p, m) => {
601
+ let path = [...prefix, ...(m.path.map(p => p.value))];
602
+ if (m.kind instanceof ast.RecordType) {
603
+ return (0, exports.typeMapFromRecordType)(m.kind, init, path);
604
+ }
605
+ else {
606
+ p[paths2String(path)] = m.kind;
607
+ return p;
608
+ }
609
+ }, init);
654
610
  exports.typeMapFromRecordType = typeMapFromRecordType;
655
- var paths2String = function (paths) { return paths.join('.'); };
611
+ const paths2String = (paths) => paths.join('.');
656
612
  /**
657
613
  * expandTypeMap to an ExpandedTypeMap.
658
614
  */
659
- var expandTypeMap = function (m) {
660
- return (0, record_1.reduce)(m, {}, function (p, c, k) {
661
- return (0, path_1.set)(k, (0, exports.type2TS)(c), p);
662
- });
663
- };
615
+ const expandTypeMap = (m) => (0, record_1.reduce)(m, {}, (p, c, k) => (0, path_1.set)(k, (0, exports.type2TS)(c), p));
664
616
  exports.expandTypeMap = expandTypeMap;
665
617
  /**
666
618
  * typeMap2TS converts a map of type values to TypeScript.
667
619
  */
668
- var typeMap2TS = function (m) {
669
- return (0, record_1.mapTo)(m, function (t, k) {
670
- if ((0, record_1.isRecord)(t)) {
671
- var key = isOptional(t) ? "".concat(k, "?") : "".concat(k);
672
- return "".concat(key, ": {").concat((0, exports.typeMap2TS)(t), "}");
673
- }
674
- else {
675
- return "".concat(k, " : ").concat(t);
676
- }
677
- }).join(',\n');
678
- };
620
+ const typeMap2TS = (m) => (0, record_1.mapTo)(m, (t, k) => {
621
+ if ((0, record_1.isRecord)(t)) {
622
+ let key = isOptional(t) ? `${k}?` : `${k}`;
623
+ return `${key}: {${(0, exports.typeMap2TS)(t)}}`;
624
+ }
625
+ else {
626
+ return `${k} : ${t}`;
627
+ }
628
+ }).join(',\n');
679
629
  exports.typeMap2TS = typeMap2TS;
680
- var isOptional = function (m) {
681
- return (0, record_1.reduce)(m, false, function (p, _, k) { return p ? p : k.indexOf('?') > -1; });
682
- };
630
+ const isOptional = (m) => (0, record_1.reduce)(m, false, (p, _, k) => p ? p : k.indexOf('?') > -1);
683
631
  /**
684
632
  * parameters2TS converts a list Parameter nodes into an parameter list
685
633
  * (without parens).
686
634
  */
687
- var parameters2TS = function (list) {
688
- return list.map(function (p) { return (0, exports.parameter2TS)(p); }).join(',');
689
- };
635
+ const parameters2TS = (list) => list.map(p => (0, exports.parameter2TS)(p)).join(',');
690
636
  exports.parameters2TS = parameters2TS;
691
637
  /**
692
638
  * parameter2TS
693
639
  */
694
- var parameter2TS = function (n) {
640
+ const parameter2TS = (n) => {
695
641
  if (n instanceof ast.TypedParameter)
696
642
  return (0, exports.typedParameter2TS)(n);
697
643
  else if (n instanceof ast.UntypedParameter)
@@ -703,28 +649,24 @@ exports.parameter2TS = parameter2TS;
703
649
  /**
704
650
  * typedParameter2TS
705
651
  */
706
- var typedParameter2TS = function (n) {
707
- return "".concat((0, exports.identifier2TS)(n.id), ": ").concat((0, exports.type2TS)(n.hint), " ");
708
- };
652
+ const typedParameter2TS = (n) => `${(0, exports.identifier2TS)(n.id)}: ${(0, exports.type2TS)(n.hint)} `;
709
653
  exports.typedParameter2TS = typedParameter2TS;
710
654
  /**
711
655
  * untypedParameter2TS
712
656
  */
713
- var untypedParameter2TS = function (n) {
714
- return "".concat((0, exports.identifier2TS)(n.id), " ");
715
- };
657
+ const untypedParameter2TS = (n) => `${(0, exports.identifier2TS)(n.id)} `;
716
658
  exports.untypedParameter2TS = untypedParameter2TS;
717
659
  /**
718
660
  * children2TS
719
661
  */
720
- var children2TS = function (ctx, list) {
721
- return "[".concat(ctx.options.EOL, "\n ").concat(list.map(function (l) { return (0, exports.child2TS)(ctx, l); }).join(',' + ctx.options.EOL), "\n ]");
722
- };
662
+ const children2TS = (ctx, list) => `[${ctx.options.EOL}
663
+ ${list.map(l => (0, exports.child2TS)(ctx, l)).join(',' + ctx.options.EOL)}
664
+ ]`;
723
665
  exports.children2TS = children2TS;
724
666
  /**
725
667
  * child2TS converts children to typescript.
726
668
  */
727
- var child2TS = function (ctx, n) {
669
+ const child2TS = (ctx, n) => {
728
670
  if ((n instanceof ast.Node) || (n instanceof ast.Widget))
729
671
  return (0, exports.tag2TS)(ctx, n);
730
672
  else if (n instanceof ast.Interpolation)
@@ -756,20 +698,20 @@ exports.child2TS = child2TS;
756
698
  /**
757
699
  * tag2TS converts a tag to typescript.
758
700
  */
759
- var tag2TS = function (ctx, n) { return (n.type === 'widget') ?
760
- (0, exports.widget2TS)(ctx, n) : (0, exports.node2TS)(ctx, n); };
701
+ const tag2TS = (ctx, n) => (n.type === 'widget') ?
702
+ (0, exports.widget2TS)(ctx, n) : (0, exports.node2TS)(ctx, n);
761
703
  exports.tag2TS = tag2TS;
762
704
  /**
763
705
  * widget2TS converts a Widget node into its typescript representation.
764
706
  *
765
707
  * This is simply a call to the View's widget method.
766
708
  */
767
- var widget2TS = function (ctx, n) {
768
- var name = (0, exports.constructor2TS)(n.open);
769
- var attrs = (0, exports.attrs2String)((0, exports.groupAttrs)(ctx, n.attributes));
770
- var childs = (0, exports.children2TS)(ctx, n.children);
771
- return "".concat(exports.THIS, ".widget(new ").concat(name, "(").concat(attrs, ", ").concat(childs, "),") +
772
- "<".concat(exports.WML, ".Attrs>").concat(attrs, ")");
709
+ const widget2TS = (ctx, n) => {
710
+ let name = (0, exports.constructor2TS)(n.open);
711
+ let attrs = (0, exports.attrs2String)(ctx, n.attributes);
712
+ let childs = (0, exports.children2TS)(ctx, n.children);
713
+ return `${exports.THIS}.widget(new ${name}(${attrs}, ${childs}),` +
714
+ `<${exports.WML}.Attrs>${attrs})`;
773
715
  };
774
716
  exports.widget2TS = widget2TS;
775
717
  /**
@@ -777,161 +719,140 @@ exports.widget2TS = widget2TS;
777
719
  *
778
720
  * This is simply a call to the View's node method.
779
721
  */
780
- var node2TS = function (ctx, n) {
781
- var name = (0, exports.identifier2TS)(n.open);
782
- var attrs = (0, exports.attrs2String)((0, exports.groupAttrs)(ctx, n.attributes));
783
- var childs = (0, exports.children2TS)(ctx, n.children);
784
- return "".concat(exports.THIS, ".node('").concat(name, "', <").concat(exports.WML, ".Attrs>").concat(attrs, ", ").concat(childs, ")");
722
+ const node2TS = (ctx, n) => {
723
+ let name = (0, exports.identifier2TS)(n.open);
724
+ let attrs = (0, exports.attrs2String)(ctx, n.attributes);
725
+ let childs = (0, exports.children2TS)(ctx, n.children);
726
+ return `${exports.THIS}.node('${name}', <${exports.WML}.Attrs>${attrs}, ${childs})`;
785
727
  };
786
728
  exports.node2TS = node2TS;
787
729
  /**
788
730
  * attribute2Value
789
731
  */
790
- var attribute2TS = function (ctx, n) {
791
- return "".concat((0, exports.attributeName2TS)(ctx, n), " : ").concat((0, exports.attributeValue2TS)(ctx, n), " ");
792
- };
732
+ const attribute2TS = (ctx, n) => `${(0, exports.attributeName2TS)(ctx, n)} : ${(0, exports.attributeValue2TS)(ctx, n)} `;
793
733
  exports.attribute2TS = attribute2TS;
794
734
  /**
795
735
  * attributeValue2TS
796
736
  */
797
- var attributeValue2TS = function (ctx, n) {
798
- return (n.value instanceof ast.Interpolation) ?
799
- (0, exports.interpolation2TS)(ctx, n.value) :
800
- (0, exports.literal2TS)(ctx, n.value);
801
- };
737
+ const attributeValue2TS = (ctx, n) => (n.value instanceof ast.Interpolation) ?
738
+ (0, exports.interpolation2TS)(ctx, n.value) :
739
+ (0, exports.literal2TS)(ctx, n.value);
802
740
  exports.attributeValue2TS = attributeValue2TS;
803
741
  /**
804
742
  * attributeName2TS
805
743
  */
806
- var attributeName2TS = function (_, n) {
807
- return "'".concat((0, exports.unqualifiedIdentifier2TS)(n.name), "'");
808
- };
744
+ const attributeName2TS = (_, n) => `'${(0, exports.unqualifiedIdentifier2TS)(n.name)}'`;
809
745
  exports.attributeName2TS = attributeName2TS;
810
746
  /**
811
747
  * attrs2String
812
748
  */
813
- var attrs2String = function (attrs) {
814
- return '{' +
815
- Object.keys(attrs).map(function (name) {
816
- return Array.isArray(attrs[name]) ?
817
- "".concat(name, " : { ").concat(attrs[name].join(','), " }") :
818
- "".concat(name, ": ").concat(attrs[name]);
819
- }) +
820
- '}';
749
+ const attrs2String = (ctx, attrs) => {
750
+ // Check for the special wml:attrs attribute.
751
+ let mallAttrs = (0, array_1.find)(attrs, attr => ((attr.namespace.value === 'wml') &&
752
+ (attr.name.value === 'attrs')));
753
+ if (mallAttrs.isJust())
754
+ return (0, exports.attributeValue2TS)(ctx, mallAttrs.get());
755
+ let [nns, ns] = (0, array_1.partition)(attrs, a => (a.namespace.value === ''));
756
+ let nso = ns.reduce((p, n) => (0, record_1.merge)(p, {
757
+ [n.namespace.value]: (p[n.namespace.value] || []).concat((0, exports.attribute2TS)(ctx, n))
758
+ }), {});
759
+ return _attrs2String(nns.reduce((p, n) => (0, record_1.merge)(p, {
760
+ [(0, exports.attributeName2TS)(ctx, n)]: (0, exports.attributeValue2TS)(ctx, n)
761
+ }), nso));
821
762
  };
822
763
  exports.attrs2String = attrs2String;
823
- /**
824
- * groupAttrs
825
- */
826
- var groupAttrs = function (ctx, attrs) {
827
- var _a = (0, array_1.partition)(attrs, function (a) { return (a.namespace.value === ''); }), nns = _a[0], ns = _a[1];
828
- var nso = ns.reduce(function (p, n) {
829
- var _a;
830
- return (0, record_1.merge)(p, (_a = {},
831
- _a[n.namespace.value] = (p[n.namespace.value] || []).concat((0, exports.attribute2TS)(ctx, n)),
832
- _a));
833
- }, {});
834
- return nns.reduce(function (p, n) {
835
- var _a;
836
- return (0, record_1.merge)(p, (_a = {},
837
- _a[(0, exports.attributeName2TS)(ctx, n)] = (0, exports.attributeValue2TS)(ctx, n),
838
- _a));
839
- }, nso);
840
- };
841
- exports.groupAttrs = groupAttrs;
764
+ const _attrs2String = (attrs) => '{' +
765
+ Object.keys(attrs).map(name => Array.isArray(attrs[name]) ?
766
+ `${name} : { ${attrs[name].join(',')} }` :
767
+ `${name}: ${attrs[name]}`) +
768
+ '}';
842
769
  /**
843
770
  * interpolation2TS
844
771
  */
845
- var interpolation2TS = function (ctx, n) {
846
- return n.filters.reduce(function (p, c) {
847
- return "".concat((0, exports.expression2TS)(ctx, c), " (").concat(p, ")");
848
- }, (0, exports.expression2TS)(ctx, n.expression));
849
- };
772
+ const interpolation2TS = (ctx, n) => n.filters.reduce((p, c) => `${(0, exports.expression2TS)(ctx, c)} (${p})`, (0, exports.expression2TS)(ctx, n.expression));
850
773
  exports.interpolation2TS = interpolation2TS;
851
774
  /**
852
775
  * ifStatementTS converts an IfStatement to its typescript representation.
853
776
  */
854
- var ifStatement2TS = function (ctx, n) {
855
- var condition = (0, exports.expression2TS)(ctx, n.condition);
856
- var conseq = (0, exports.children2TS)(ctx, n.then);
857
- var alt = (n.elseClause instanceof ast.ElseIfClause) ?
858
- "[".concat((0, exports.ifStatement2TS)(ctx, n.elseClause), "]") :
777
+ const ifStatement2TS = (ctx, n) => {
778
+ let condition = (0, exports.expression2TS)(ctx, n.condition);
779
+ let conseq = (0, exports.children2TS)(ctx, n.then);
780
+ let alt = (n.elseClause instanceof ast.ElseIfClause) ?
781
+ `[${(0, exports.ifStatement2TS)(ctx, n.elseClause)}]` :
859
782
  (n.elseClause instanceof ast.ElseClause) ?
860
783
  (0, exports.children2TS)(ctx, n.elseClause.children) :
861
784
  '[]';
862
785
  return [
863
- "...((".concat(condition, ") ?"),
864
- "(()=>(".concat(conseq, "))() :"),
865
- "(()=>(".concat(alt, "))())")
786
+ `...((${condition}) ?`,
787
+ `(()=>(${conseq}))() :`,
788
+ `(()=>(${alt}))())`
866
789
  ].join(ctx.options.EOL);
867
790
  };
868
791
  exports.ifStatement2TS = ifStatement2TS;
869
792
  /**
870
793
  * forInStatement2TS converts a ForInStatement to its typescript representation.
871
794
  */
872
- var forInStatement2TS = function (ctx, n) {
873
- var expr = (0, exports.expression2TS)(ctx, n.expression);
874
- var value = (0, exports.parameter2TS)(n.variables[0]);
875
- var key = n.variables.length > 1 ? (0, exports.parameter2TS)(n.variables[1]) : '_$$i';
876
- var all = n.variables.length > 2 ? (0, exports.parameter2TS)(n.variables[2]) : '_$$all';
877
- var body = (0, exports.children2TS)(ctx, n.body);
878
- var alt = n.otherwise.length > 0 ? (0, exports.children2TS)(ctx, n.otherwise) : '[]';
795
+ const forInStatement2TS = (ctx, n) => {
796
+ let expr = (0, exports.expression2TS)(ctx, n.expression);
797
+ let value = (0, exports.parameter2TS)(n.variables[0]);
798
+ let key = n.variables.length > 1 ? (0, exports.parameter2TS)(n.variables[1]) : '_$$i';
799
+ let all = n.variables.length > 2 ? (0, exports.parameter2TS)(n.variables[2]) : '_$$all';
800
+ let body = (0, exports.children2TS)(ctx, n.body);
801
+ let alt = n.otherwise.length > 0 ? (0, exports.children2TS)(ctx, n.otherwise) : '[]';
879
802
  return [
880
- "...".concat(FOR_IN, " (").concat(expr, ", (").concat(value, ", ").concat(key, ", ").concat(all, ")=> "),
881
- "(".concat(body, "), "),
882
- "()=> (".concat(alt, "))")
803
+ `...${FOR_IN} (${expr}, (${value}, ${key}, ${all})=> `,
804
+ `(${body}), `,
805
+ `()=> (${alt}))`
883
806
  ].join(ctx.options.EOL);
884
807
  };
885
808
  exports.forInStatement2TS = forInStatement2TS;
886
809
  /**
887
810
  * forOfStatement2TS
888
811
  */
889
- var forOfStatement2TS = function (ctx, n) {
890
- var expr = (0, exports.expression2TS)(ctx, n.expression);
891
- var value = (0, exports.parameter2TS)(n.variables[0]);
892
- var key = n.variables.length > 1 ? (0, exports.parameter2TS)(n.variables[1]) : '_$$k';
893
- var all = n.variables.length > 2 ? (0, exports.parameter2TS)(n.variables[2]) : '_$$all';
894
- var body = (0, exports.children2TS)(ctx, n.body);
895
- var alt = n.otherwise.length > 0 ? (0, exports.children2TS)(ctx, n.otherwise) : '[]';
812
+ const forOfStatement2TS = (ctx, n) => {
813
+ let expr = (0, exports.expression2TS)(ctx, n.expression);
814
+ let value = (0, exports.parameter2TS)(n.variables[0]);
815
+ let key = n.variables.length > 1 ? (0, exports.parameter2TS)(n.variables[1]) : '_$$k';
816
+ let all = n.variables.length > 2 ? (0, exports.parameter2TS)(n.variables[2]) : '_$$all';
817
+ let body = (0, exports.children2TS)(ctx, n.body);
818
+ let alt = n.otherwise.length > 0 ? (0, exports.children2TS)(ctx, n.otherwise) : '[]';
896
819
  return [
897
- "...".concat(FOR_OF, " (").concat(expr, ", (").concat(value, ", ").concat(key, ", ").concat(all, ") => "),
898
- " (".concat(body, "), "),
899
- " ()=> (".concat(alt, "))")
820
+ `...${FOR_OF} (${expr}, (${value}, ${key}, ${all}) => `,
821
+ ` (${body}), `,
822
+ ` ()=> (${alt}))`
900
823
  ].join(eol(ctx));
901
824
  };
902
825
  exports.forOfStatement2TS = forOfStatement2TS;
903
826
  /**
904
827
  * forFromStatement2TS
905
828
  */
906
- var forFromStatement2TS = function (ctx, node) {
907
- var value = (0, exports.parameter2TS)(node.variable);
908
- var start = (0, exports.expression2TS)(ctx, node.start);
909
- var end = (0, exports.expression2TS)(ctx, node.end);
910
- var body = (0, exports.children2TS)(ctx, node.body);
829
+ const forFromStatement2TS = (ctx, node) => {
830
+ let value = (0, exports.parameter2TS)(node.variable);
831
+ let start = (0, exports.expression2TS)(ctx, node.start);
832
+ let end = (0, exports.expression2TS)(ctx, node.end);
833
+ let body = (0, exports.children2TS)(ctx, node.body);
911
834
  return [
912
- "...(function forFrom() {",
913
- " let result:".concat(exports.WML, ".Content[] = [];"),
914
- " for(let ".concat(value, ":number=").concat(start, "; ").concat(value, "<=").concat(end, "; ").concat(value, "++)"),
915
- " result.push(",
916
- " ...".concat(body),
917
- " );",
918
- " return result;",
919
- "})()"
835
+ `...(function forFrom() {`,
836
+ ` let result:${exports.WML}.Content[] = [];`,
837
+ ` for(let ${value}:number=${start}; ${value}<=${end}; ${value}++)`,
838
+ ` result.push(`,
839
+ ` ...${body}`,
840
+ ` );`,
841
+ ` return result;`,
842
+ `})()`
920
843
  ].join(eol(ctx));
921
844
  };
922
845
  exports.forFromStatement2TS = forFromStatement2TS;
923
846
  /**
924
847
  * characters2TS converts character text to a typescript string.
925
848
  */
926
- var characters2TS = function (n) {
927
- return "".concat(exports.DOCUMENT, ".createTextNode('").concat(breakLines(n.value), "')");
928
- };
849
+ const characters2TS = (n) => `${exports.DOCUMENT}.createTextNode('${breakLines(n.value)}')`;
929
850
  exports.characters2TS = characters2TS;
930
- var breakLines = function (str) { return str.split('\n').join('\\u000a'); };
851
+ const breakLines = (str) => str.split('\n').join('\\u000a');
931
852
  /**
932
853
  * expression2TS
933
854
  */
934
- var expression2TS = function (ctx, n) {
855
+ const expression2TS = (ctx, n) => {
935
856
  if (n instanceof ast.IfThenExpression)
936
857
  return (0, exports.ifThenExpression2TS)(ctx, n);
937
858
  else if (n instanceof ast.BinaryExpression)
@@ -981,119 +902,109 @@ exports.expression2TS = expression2TS;
981
902
  /**
982
903
  * ifThenExpression2TS
983
904
  */
984
- var ifThenExpression2TS = function (ctx, n) {
985
- var condition = (0, exports.expression2TS)(ctx, n.condition);
986
- var conseq = (0, exports.expression2TS)(ctx, n.iftrue);
987
- var alt = (0, exports.expression2TS)(ctx, n.iffalse);
988
- return "(".concat(condition, ") ? ").concat(conseq, " : ").concat(alt);
905
+ const ifThenExpression2TS = (ctx, n) => {
906
+ let condition = (0, exports.expression2TS)(ctx, n.condition);
907
+ let conseq = (0, exports.expression2TS)(ctx, n.iftrue);
908
+ let alt = (0, exports.expression2TS)(ctx, n.iffalse);
909
+ return `(${condition}) ? ${conseq} : ${alt}`;
989
910
  };
990
911
  exports.ifThenExpression2TS = ifThenExpression2TS;
991
912
  /**
992
913
  * binaryExpression2TS
993
914
  */
994
- var binaryExpression2TS = function (ctx, n) {
995
- var left = (0, exports.expression2TS)(ctx, n.left);
996
- var right = (0, exports.expression2TS)(ctx, n.right);
997
- var op = operators.hasOwnProperty(n.operator) ?
915
+ const binaryExpression2TS = (ctx, n) => {
916
+ let left = (0, exports.expression2TS)(ctx, n.left);
917
+ let right = (0, exports.expression2TS)(ctx, n.right);
918
+ let op = operators.hasOwnProperty(n.operator) ?
998
919
  operators[n.operator] :
999
920
  n.operator;
1000
- return "(".concat(left, " ").concat(op, " ").concat(right, ")");
921
+ return `(${left} ${op} ${right})`;
1001
922
  };
1002
923
  exports.binaryExpression2TS = binaryExpression2TS;
1003
924
  /**
1004
925
  * unaryExpression2TS
1005
926
  */
1006
- var unaryExpression2TS = function (ctx, n) {
1007
- var expr = (0, exports.expression2TS)(ctx, n.expression);
927
+ const unaryExpression2TS = (ctx, n) => {
928
+ let expr = (0, exports.expression2TS)(ctx, n.expression);
1008
929
  return (n.operator === '??') ?
1009
- "(".concat(expr, ") != null") :
1010
- "".concat(n.operator, "(").concat(expr, ")");
930
+ `(${expr}) != null` :
931
+ `${n.operator}(${expr})`;
1011
932
  };
1012
933
  exports.unaryExpression2TS = unaryExpression2TS;
1013
934
  /**
1014
935
  * typeAssertion2TS
1015
936
  */
1016
- var typeAssertion2TS = function (ctx, n) {
1017
- return "<".concat((0, exports.type2TS)(n.target), ">(").concat((0, exports.expression2TS)(ctx, n.expression), ")");
1018
- };
937
+ const typeAssertion2TS = (ctx, n) => `<${(0, exports.type2TS)(n.target)}>(${(0, exports.expression2TS)(ctx, n.expression)})`;
1019
938
  exports.typeAssertion2TS = typeAssertion2TS;
1020
939
  /**
1021
940
  * viewConstruction2TS
1022
941
  */
1023
- var viewConstruction2TS = function (ctx, n) {
1024
- return "".concat(exports.THIS, ".registerView(").concat((0, exports.expression2TS)(ctx, n.expression), ").render()");
1025
- };
942
+ const viewConstruction2TS = (ctx, n) => `${exports.THIS}.registerView(${(0, exports.expression2TS)(ctx, n.expression)}).render()`;
1026
943
  exports.viewConstruction2TS = viewConstruction2TS;
1027
944
  /**
1028
945
  * funApplication2TS
1029
946
  */
1030
- var funApplication2TS = function (ctx, n) {
1031
- return "".concat((0, exports.expression2TS)(ctx, n.target)).concat((0, exports.typeArgs2TS)(n.typeArgs), " ") +
1032
- "(".concat((0, exports.args2TS)(ctx, n.args), ")(").concat(exports.THIS, ")");
1033
- };
947
+ const funApplication2TS = (ctx, n) => `${(0, exports.expression2TS)(ctx, n.target)}${(0, exports.typeArgs2TS)(n.typeArgs)} ` +
948
+ `(${(0, exports.args2TS)(ctx, n.args)})(${exports.THIS})`;
1034
949
  exports.funApplication2TS = funApplication2TS;
1035
950
  /**
1036
951
  * constructExpression2TS
1037
952
  */
1038
- var constructExpression2TS = function (ctx, n) {
1039
- var cons = (0, exports.constructor2TS)(n.cons);
1040
- var consOriginal = "".concat(cons[0].toUpperCase()).concat(cons.slice(1));
1041
- var args = (0, exports.args2TS)(ctx, n.args);
953
+ const constructExpression2TS = (ctx, n) => {
954
+ let cons = (0, exports.constructor2TS)(n.cons);
955
+ let consOriginal = `${cons[0].toUpperCase()}${cons.slice(1)}`;
956
+ let args = (0, exports.args2TS)(ctx, n.args);
1042
957
  if ((0, array_1.contains)(casters, consOriginal)) {
1043
- return "".concat(consOriginal, "(").concat(args, ")");
958
+ return `${consOriginal}(${args})`;
1044
959
  }
1045
960
  else {
1046
- return "new ".concat(cons, "(").concat(args, ")");
961
+ return `new ${cons}(${args})`;
1047
962
  }
1048
963
  };
1049
964
  exports.constructExpression2TS = constructExpression2TS;
1050
965
  /**
1051
966
  * callExpression2TS
1052
967
  */
1053
- var callExpression2TS = function (ctx, n) {
1054
- var target = (0, exports.expression2TS)(ctx, n.target);
1055
- var typeArgs = (0, exports.typeArgs2TS)(n.typeArgs);
1056
- var args = (0, exports.args2TS)(ctx, n.args);
1057
- return "".concat(target).concat(typeArgs, "(").concat(args, ")");
968
+ const callExpression2TS = (ctx, n) => {
969
+ let target = (0, exports.expression2TS)(ctx, n.target);
970
+ let typeArgs = (0, exports.typeArgs2TS)(n.typeArgs);
971
+ let args = (0, exports.args2TS)(ctx, n.args);
972
+ return `${target}${typeArgs}(${args})`;
1058
973
  };
1059
974
  exports.callExpression2TS = callExpression2TS;
1060
975
  /**
1061
976
  * typeArgs2TS
1062
977
  */
1063
- var typeArgs2TS = function (ns) {
1064
- return ns.length === 0 ? '' : "<".concat(ns.map(exports.type2TS).join(','), ">");
1065
- };
978
+ const typeArgs2TS = (ns) => ns.length === 0 ? '' : `<${ns.map(exports.type2TS).join(',')}>`;
1066
979
  exports.typeArgs2TS = typeArgs2TS;
1067
980
  /**
1068
981
  * args2TS converts a list of arguments to a typescript argument tupple.
1069
982
  */
1070
- var args2TS = function (ctx, ns) {
1071
- return (ns.length === 0) ? '' : ns.map(function (e) { return (0, exports.expression2TS)(ctx, e); }).join(',');
1072
- };
983
+ const args2TS = (ctx, ns) => (ns.length === 0) ? '' : ns.map(e => (0, exports.expression2TS)(ctx, e)).join(',');
1073
984
  exports.args2TS = args2TS;
1074
985
  /**
1075
986
  * memberExpression2TS
1076
987
  */
1077
- var memberExpression2TS = function (ctx, n) {
1078
- var target = (0, exports.expression2TS)(ctx, n.target);
1079
- return (n.member instanceof ast.StringLiteral) ?
1080
- "".concat(target, "[").concat((0, exports.string2TS)(n.member), "]") :
1081
- "".concat(target, ".").concat((0, exports.identifier2TS)(n.member));
988
+ const memberExpression2TS = (ctx, n) => {
989
+ let target = (0, exports.expression2TS)(ctx, n.head);
990
+ return (n.tail instanceof ast.StringLiteral) ?
991
+ `${target}[${(0, exports.string2TS)(n.tail)}]` :
992
+ `${target}.${(0, exports.expression2TS)(ctx, n.tail)}`;
1082
993
  };
1083
994
  exports.memberExpression2TS = memberExpression2TS;
1084
995
  /**
1085
996
  * functionExpression2TS
1086
997
  */
1087
- var functionExpression2TS = function (ctx, n) {
1088
- var params = n.parameters.map(exports.parameter2TS).join(',');
1089
- var body = (0, exports.expression2TS)(ctx, n.body);
1090
- return "(".concat(params, ") => ").concat(body);
998
+ const functionExpression2TS = (ctx, n) => {
999
+ let params = n.parameters.map(exports.parameter2TS).join(',');
1000
+ let body = (0, exports.expression2TS)(ctx, n.body);
1001
+ return `(${params}) => ${body}`;
1091
1002
  };
1092
1003
  exports.functionExpression2TS = functionExpression2TS;
1093
1004
  /**
1094
1005
  * literal2TS
1095
1006
  */
1096
- var literal2TS = function (ctx, n) {
1007
+ const literal2TS = (ctx, n) => {
1097
1008
  if (n instanceof ast.BooleanLiteral)
1098
1009
  return (0, exports.boolean2TS)(n);
1099
1010
  else if (n instanceof ast.StringLiteral)
@@ -1111,66 +1022,64 @@ exports.literal2TS = literal2TS;
1111
1022
  /**
1112
1023
  * boolean2TS
1113
1024
  */
1114
- var boolean2TS = function (n) { return "".concat(n.value, " "); };
1025
+ const boolean2TS = (n) => `${n.value} `;
1115
1026
  exports.boolean2TS = boolean2TS;
1116
1027
  /**
1117
1028
  * string2TS
1118
1029
  */
1119
- var string2TS = function (n) { return "'".concat(n.value, "'"); };
1030
+ const string2TS = (n) => `'${n.value}'`;
1120
1031
  exports.string2TS = string2TS;
1121
1032
  /**
1122
1033
  * number2TS
1123
1034
  */
1124
- var number2TS = function (n) { return "".concat(parseFloat(n.value)); };
1035
+ const number2TS = (n) => `${parseFloat(n.value)}`;
1125
1036
  exports.number2TS = number2TS;
1126
1037
  /**
1127
1038
  * record2TS
1128
1039
  */
1129
- var record2TS = function (ctx, n) {
1130
- return "{".concat(ctx.options.EOL, " \n ").concat(n.properties.map(function (p) { return (0, exports.property2TS)(ctx, p); }).join(',' + ctx.options.EOL), "\n }");
1131
- };
1040
+ const record2TS = (ctx, n) => `{${ctx.options.EOL}
1041
+ ${n.properties.map(p => (0, exports.property2TS)(ctx, p)).join(',' + ctx.options.EOL)}
1042
+ }`;
1132
1043
  exports.record2TS = record2TS;
1133
1044
  /**
1134
1045
  * list2TS
1135
1046
  */
1136
- var list2TS = function (ctx, n) {
1137
- var mems = n.members.map(function (e) { return (0, exports.expression2TS)(ctx, e); });
1138
- return "[".concat(ctx.options.EOL, "\n ").concat(mems.join(',' + ctx.options.EOL), "\n ]");
1047
+ const list2TS = (ctx, n) => {
1048
+ let mems = n.members.map(e => (0, exports.expression2TS)(ctx, e));
1049
+ return `[${ctx.options.EOL}
1050
+ ${mems.join(',' + ctx.options.EOL)}
1051
+ ]`;
1139
1052
  };
1140
1053
  exports.list2TS = list2TS;
1141
1054
  /**
1142
1055
  * property2TS
1143
1056
  */
1144
- var property2TS = function (ctx, n) {
1145
- return "'".concat((0, exports.key2TS)(n.key), "' : ").concat((0, exports.expression2TS)(ctx, n.value));
1146
- };
1057
+ const property2TS = (ctx, n) => `'${(0, exports.key2TS)(n.key)}' : ${(0, exports.expression2TS)(ctx, n.value)}`;
1147
1058
  exports.property2TS = property2TS;
1148
1059
  /**
1149
1060
  * key2TS
1150
1061
  */
1151
- var key2TS = function (n) {
1152
- return (n instanceof ast.StringLiteral) ? (0, exports.string2TS)(n) : (0, exports.identifier2TS)(n);
1153
- };
1062
+ const key2TS = (n) => (n instanceof ast.StringLiteral) ? (0, exports.string2TS)(n) : (0, exports.identifier2TS)(n);
1154
1063
  exports.key2TS = key2TS;
1155
1064
  /**
1156
1065
  * contextProperty2TS
1157
1066
  */
1158
- var contextProperty2TS = function (n) {
1159
- var member = (n.member instanceof ast.StringLiteral) ?
1067
+ const contextProperty2TS = (n) => {
1068
+ let member = (n.member instanceof ast.StringLiteral) ?
1160
1069
  n.member.value :
1161
1070
  (0, exports.identifier2TS)(n.member);
1162
- return "".concat(exports.CONTEXT, ".").concat(member);
1071
+ return `${exports.CONTEXT}.${member}`;
1163
1072
  };
1164
1073
  exports.contextProperty2TS = contextProperty2TS;
1165
1074
  /**
1166
1075
  * contextVariable2TS
1167
1076
  */
1168
- var contextVariable2TS = function (_) { return "".concat(exports.CONTEXT); };
1077
+ const contextVariable2TS = (_) => `${exports.CONTEXT}`;
1169
1078
  exports.contextVariable2TS = contextVariable2TS;
1170
1079
  /**
1171
1080
  * identifierOrConstructor2TS
1172
1081
  */
1173
- var identifierOrConstructor2TS = function (n) {
1082
+ const identifierOrConstructor2TS = (n) => {
1174
1083
  if ((n instanceof ast.UnqualifiedIdentifier) ||
1175
1084
  (n instanceof ast.QualifiedIdentifier))
1176
1085
  return (0, exports.identifier2TS)(n);
@@ -1184,7 +1093,7 @@ exports.identifierOrConstructor2TS = identifierOrConstructor2TS;
1184
1093
  /**
1185
1094
  * constructor2TS
1186
1095
  */
1187
- var constructor2TS = function (n) {
1096
+ const constructor2TS = (n) => {
1188
1097
  if (n instanceof ast.QualifiedConstructor)
1189
1098
  return (0, exports.qualifiedConstructor2TS)(n);
1190
1099
  else if (n instanceof ast.UnqualifiedConstructor)
@@ -1196,21 +1105,17 @@ exports.constructor2TS = constructor2TS;
1196
1105
  /**
1197
1106
  * unqualifiedConstructor2TS
1198
1107
  */
1199
- var unqualifiedConstructor2TS = function (n) {
1200
- return toPrim(n.value);
1201
- };
1108
+ const unqualifiedConstructor2TS = (n) => toPrim(n.value);
1202
1109
  exports.unqualifiedConstructor2TS = unqualifiedConstructor2TS;
1203
1110
  /**
1204
1111
  * qualifiedConstructor
1205
1112
  */
1206
- var qualifiedConstructor2TS = function (n) {
1207
- return "".concat(n.qualifier, ".").concat(n.member);
1208
- };
1113
+ const qualifiedConstructor2TS = (n) => `${n.qualifier}.${n.member}`;
1209
1114
  exports.qualifiedConstructor2TS = qualifiedConstructor2TS;
1210
1115
  /**
1211
1116
  * identifier2TS
1212
1117
  */
1213
- var identifier2TS = function (n) {
1118
+ const identifier2TS = (n) => {
1214
1119
  if (n instanceof ast.QualifiedIdentifier)
1215
1120
  return (0, exports.qualifiedIdentifier2TS)(n);
1216
1121
  else if (n instanceof ast.UnqualifiedIdentifier)
@@ -1222,16 +1127,12 @@ exports.identifier2TS = identifier2TS;
1222
1127
  /**
1223
1128
  * qualifiedIdentifier2TS
1224
1129
  */
1225
- var qualifiedIdentifier2TS = function (n) {
1226
- return "".concat(n.qualifier, ".").concat(n.member);
1227
- };
1130
+ const qualifiedIdentifier2TS = (n) => `${n.qualifier}.${n.member}`;
1228
1131
  exports.qualifiedIdentifier2TS = qualifiedIdentifier2TS;
1229
1132
  /**
1230
1133
  * unqualifiedIdentifier2TS
1231
1134
  */
1232
- var unqualifiedIdentifier2TS = function (n) {
1233
- return "".concat(toPrim(n.value));
1234
- };
1135
+ const unqualifiedIdentifier2TS = (n) => `${toPrim(n.value)}`;
1235
1136
  exports.unqualifiedIdentifier2TS = unqualifiedIdentifier2TS;
1236
- var toPrim = function (id) { return prims.indexOf(id) > -1 ? id.toLowerCase() : id; };
1137
+ const toPrim = (id) => prims.indexOf(id) > -1 ? id.toLowerCase() : id;
1237
1138
  //# sourceMappingURL=codegen.js.map