babel-plugin-vasille 0.99.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.
@@ -0,0 +1,391 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.transformJsx = transformJsx;
27
+ exports.transformJsxArray = transformJsxArray;
28
+ const t = __importStar(require("@babel/types"));
29
+ const internal_js_1 = require("./internal.js");
30
+ const lib_js_1 = require("./lib.js");
31
+ const mesh_js_1 = require("./mesh.js");
32
+ const jsx_detect_js_1 = require("./jsx-detect.js");
33
+ function transformJsx(path, internal) {
34
+ if (t.isJSXElement(path.node)) {
35
+ return [transformJsxElement(path, internal)];
36
+ }
37
+ return transformJsxArray(path.get("children"), internal);
38
+ }
39
+ function transformJsxArray(paths, internal) {
40
+ const result = [];
41
+ for (const path of paths) {
42
+ if (t.isJSXElement(path.node) || t.isJSXFragment(path.node)) {
43
+ result.push(...transformJsx(path, internal));
44
+ }
45
+ else if (t.isJSXText(path.node)) {
46
+ if (!/^\s+$/.test(path.node.value)) {
47
+ const fixed = path.node.value
48
+ .replace(/\n\s+$/m, "")
49
+ .replace(/^\s*\n\s+/m, "")
50
+ .replace(/\s*\n\s*/gm, "\n");
51
+ result.push(t.expressionStatement(t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)])));
52
+ }
53
+ }
54
+ else if (t.isJSXExpressionContainer(path.node)) {
55
+ const value = transformJsxExpressionContainer(path, internal, false, false);
56
+ result.push(t.expressionStatement(t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [value])));
57
+ }
58
+ else {
59
+ throw path.buildCodeFrameError("Vasille: Spread child is not supported");
60
+ }
61
+ }
62
+ return result;
63
+ }
64
+ function transformJsxExpressionContainer(path, internal, acceptSlots, isInternalSlot) {
65
+ if (!t.isExpression(path.node.expression)) {
66
+ return t.booleanLiteral(true);
67
+ }
68
+ if (acceptSlots &&
69
+ (t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression)) &&
70
+ (0, jsx_detect_js_1.bodyHasJsx)(path.node.expression.body)) {
71
+ (0, mesh_js_1.compose)(path.get("expression"), internal, isInternalSlot);
72
+ if (!isInternalSlot) {
73
+ if (path.node.expression.params.length < 1) {
74
+ path.node.expression.params.push(t.identifier(internal.prefix));
75
+ }
76
+ path.node.expression.params.push(internal_js_1.ctx);
77
+ }
78
+ else {
79
+ path.node.expression.params.unshift(internal_js_1.ctx);
80
+ }
81
+ return path.node.expression;
82
+ }
83
+ else if (isInternalSlot &&
84
+ (t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression))) {
85
+ path.node.expression.params.unshift(internal_js_1.ctx);
86
+ }
87
+ let call = (0, lib_js_1.exprCall)(path.get("expression"), path.node.expression, internal);
88
+ if (!call &&
89
+ t.isIdentifier(path.node.expression) &&
90
+ internal.stack.get(path.node.expression.name) === 3 /* VariableState.ReactiveObject */) {
91
+ call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [path.node.expression]);
92
+ }
93
+ return call !== null && call !== void 0 ? call : path.node.expression;
94
+ }
95
+ function id(str) {
96
+ if (/^[\w_]+$/.test(str)) {
97
+ return t.identifier(str);
98
+ }
99
+ else {
100
+ return t.stringLiteral(str);
101
+ }
102
+ }
103
+ function transformJsxElement(path, internal) {
104
+ var _a, _b;
105
+ const name = path.node.openingElement.name;
106
+ if (t.isJSXIdentifier(name) && name.name[0].toLowerCase() === name.name[0]) {
107
+ const opening = path.get("openingElement");
108
+ const attrs = [];
109
+ const events = [];
110
+ const bind = [];
111
+ const classElements = [];
112
+ const classObject = [];
113
+ const classStatic = [];
114
+ const styleObject = [];
115
+ const styleStatic = [];
116
+ for (const attrPath of opening.get("attributes")) {
117
+ const attr = attrPath.node;
118
+ if (t.isJSXAttribute(attr)) {
119
+ const name = attr.name;
120
+ if (t.isJSXIdentifier(name)) {
121
+ if (name.name.startsWith("on")) {
122
+ if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
123
+ const path = attrPath.get("value");
124
+ if (t.isExpression(path.node.expression)) {
125
+ (0, mesh_js_1.meshExpression)(path.get("expression"), internal);
126
+ }
127
+ events.push(t.objectProperty(id(name.name.substring(2)), path.node.expression));
128
+ }
129
+ else {
130
+ throw attrPath
131
+ .get("value")
132
+ .buildCodeFrameError("Vasille: Expected event handler.");
133
+ }
134
+ }
135
+ else if (name.name === "class") {
136
+ // class={[..]}
137
+ if (t.isJSXExpressionContainer(attr.value) && t.isArrayExpression(attr.value.expression)) {
138
+ const valuePath = attrPath.get("value");
139
+ const arrayExprPath = valuePath.get("expression");
140
+ for (const elementPath of arrayExprPath.get("elements")) {
141
+ const item = elementPath.node;
142
+ if (t.isExpression(item)) {
143
+ // class={[cond && "string"]}
144
+ if (t.isLogicalExpression(item) && item.operator === "&&" && t.isStringLiteral(item.right)) {
145
+ const call = (0, lib_js_1.exprCall)(elementPath.get("left"), item.left, internal);
146
+ classObject.push(t.objectProperty(id(item.right.value), call !== null && call !== void 0 ? call : item.left));
147
+ }
148
+ // class={[{..}]}
149
+ else if (t.isObjectExpression(item)) {
150
+ for (const propPath of elementPath.get("properties")) {
151
+ // class={[{a: b}]}
152
+ if (t.isObjectProperty(propPath.node)) {
153
+ const prop = propPath;
154
+ const value = (_a = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
155
+ if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
156
+ (0, mesh_js_1.meshExpression)(prop.get("key"), internal);
157
+ }
158
+ classObject.push(t.objectProperty(prop.node.key, value));
159
+ }
160
+ // class={[{...a}]}
161
+ else if (t.isSpreadElement(propPath.node)) {
162
+ classObject.push(propPath.node);
163
+ }
164
+ // class={[{a(){}}]}
165
+ else {
166
+ throw propPath.buildCodeFrameError("Vasille: Methods are not alllowed here");
167
+ }
168
+ }
169
+ }
170
+ // class={[".."]}
171
+ else if (t.isStringLiteral(elementPath.node)) {
172
+ classStatic.push(elementPath.node.value);
173
+ }
174
+ // class={[..]}
175
+ else {
176
+ const call = (0, lib_js_1.exprCall)(elementPath, item, internal);
177
+ classElements.push(call !== null && call !== void 0 ? call : item);
178
+ }
179
+ }
180
+ // class={[...array]}
181
+ else {
182
+ classElements.push(elementPath.node);
183
+ }
184
+ }
185
+ }
186
+ // class={"a b"}
187
+ else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
188
+ attrs.push(t.objectProperty(t.identifier("class"), attr.value.expression));
189
+ }
190
+ // class={`a ${b}`}
191
+ else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
192
+ const jsxAttrPath = attrPath;
193
+ const jsxContainerPath = jsxAttrPath.get("value");
194
+ const value = (0, lib_js_1.exprCall)(jsxContainerPath.get("expression"), attr.value.expression, internal);
195
+ attrs.push(t.objectProperty(t.identifier("class"), value !== null && value !== void 0 ? value : attr.value.expression));
196
+ if (value) {
197
+ console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
198
+ }
199
+ }
200
+ // class="a b"
201
+ else if (t.isStringLiteral(attr.value)) {
202
+ const splitted = attr.value.value.split(" ");
203
+ for (const item of splitted) {
204
+ classStatic.push(item);
205
+ }
206
+ }
207
+ // class=<div/>
208
+ else {
209
+ throw attrPath.buildCodeFrameError('Vasille: Value of "class" attribute must be an array expression');
210
+ }
211
+ }
212
+ else if (name.name === "style") {
213
+ // style={{..}}
214
+ if (t.isJSXExpressionContainer(attr.value) && t.isObjectExpression(attr.value.expression)) {
215
+ const valuePath = attrPath.get("value");
216
+ const objectPath = valuePath.get("expression");
217
+ for (const propPath of objectPath.get("properties")) {
218
+ // style={{a: b}}
219
+ if (t.isObjectProperty(propPath.node)) {
220
+ const prop = propPath;
221
+ const value = (_b = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
222
+ if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
223
+ (0, mesh_js_1.meshExpression)(prop.get("key"), internal);
224
+ }
225
+ // style={{a: "b"}} -> static in compile time
226
+ if (t.isIdentifier(prop.node.key) && t.isStringLiteral(prop.node.value)) {
227
+ styleStatic.push([prop.node.key, prop.node.value]);
228
+ }
229
+ // style={{a: 23}} -> static in compile time
230
+ else if (t.isIdentifier(prop.node.key) && t.isNumericLiteral(prop.node.value)) {
231
+ styleStatic.push([prop.node.key, t.stringLiteral(`${prop.node.value.value}px`)]);
232
+ }
233
+ // style={{a: [1, 2, 3]}} -> static in compile time
234
+ else if (t.isIdentifier(prop.node.key) &&
235
+ t.isArrayExpression(prop.node.value) &&
236
+ prop.node.value.elements.every(item => t.isNumericLiteral(item))) {
237
+ styleStatic.push([
238
+ prop.node.key,
239
+ t.stringLiteral(prop.node.value.elements
240
+ .map(item => {
241
+ return `${item.value}px`;
242
+ })
243
+ .join(" ")),
244
+ ]);
245
+ }
246
+ // need processing in run time
247
+ else {
248
+ styleObject.push(t.objectProperty(prop.node.key, value));
249
+ }
250
+ }
251
+ // style={{...a}}
252
+ else if (t.isSpreadElement(propPath.node)) {
253
+ styleObject.push(propPath.node);
254
+ }
255
+ // style={{a(){}}}
256
+ else {
257
+ throw propPath.buildCodeFrameError("Vasille: Methods are not alllowed here");
258
+ }
259
+ }
260
+ }
261
+ // style={".."}
262
+ else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
263
+ attrs.push(t.objectProperty(t.identifier("style"), attr.value.expression));
264
+ }
265
+ // style={`a: ${b}px`}
266
+ else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
267
+ const jsxAttrPath = attrPath;
268
+ const jsxContainerPath = jsxAttrPath.get("value");
269
+ const literalPath = jsxContainerPath.get("expression");
270
+ const value = (0, lib_js_1.exprCall)(literalPath, attr.value.expression, internal);
271
+ attrs.push(t.objectProperty(t.identifier("style"), value !== null && value !== void 0 ? value : attr.value.expression));
272
+ if (value) {
273
+ console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
274
+ }
275
+ }
276
+ // style=<div/>
277
+ else {
278
+ throw attrPath.buildCodeFrameError('Vasille: Value of "style" attribute must be an object expression');
279
+ }
280
+ }
281
+ else {
282
+ if (t.isJSXExpressionContainer(attr.value)) {
283
+ attrs.push(t.objectProperty(id(name.name), t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true)));
284
+ }
285
+ else if (t.isStringLiteral(attr.value)) {
286
+ attrs.push(t.objectProperty(id(name.name), attr.value));
287
+ }
288
+ else {
289
+ throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
290
+ }
291
+ }
292
+ }
293
+ if (t.isJSXNamespacedName(name)) {
294
+ if (name.namespace.name === "bind") {
295
+ if (t.isJSXExpressionContainer(attr.value)) {
296
+ const value = t.isExpression(attr.value.expression)
297
+ ? (0, lib_js_1.exprCall)(attrPath.get("value"), attr.value.expression, internal)
298
+ : undefined;
299
+ bind.push(t.objectProperty(id(name.name.name), value !== null && value !== void 0 ? value : (t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true))));
300
+ }
301
+ else if (t.isStringLiteral(attr.value)) {
302
+ bind.push(t.objectProperty(id(name.name.name), attr.value));
303
+ }
304
+ else {
305
+ throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
306
+ }
307
+ }
308
+ else {
309
+ throw attrPath.buildCodeFrameError("Vasille: only bind namespace is supported");
310
+ }
311
+ }
312
+ }
313
+ else {
314
+ throw attrPath.buildCodeFrameError("Vasille: Spread attribute is not allowed on HTML tags.");
315
+ }
316
+ }
317
+ if (classStatic.length > 0) {
318
+ attrs.push(t.objectProperty(t.identifier("class"), t.stringLiteral(classStatic.join(" "))));
319
+ }
320
+ if (styleStatic.length > 0) {
321
+ attrs.push(t.objectProperty(t.identifier("style"), t.stringLiteral(styleStatic.map(([id, value]) => `${id.name}:${value.value}`).join(";"))));
322
+ }
323
+ const statements = transformJsxArray(path.get("children"), internal);
324
+ return t.expressionStatement(t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("tag")), [
325
+ t.stringLiteral(name.name),
326
+ t.objectExpression([
327
+ ...(attrs.length > 0 ? [t.objectProperty(t.identifier("attr"), t.objectExpression(attrs))] : []),
328
+ ...(events.length > 0 ? [t.objectProperty(t.identifier("events"), t.objectExpression(events))] : []),
329
+ ...(bind.length > 0 ? [t.objectProperty(t.identifier("bind"), t.objectExpression(bind))] : []),
330
+ ...(classElements.length > 0 || classObject.length
331
+ ? [
332
+ t.objectProperty(t.identifier("class"), t.arrayExpression([
333
+ ...classElements,
334
+ ...(classObject.length > 0 ? [t.objectExpression(classObject)] : []),
335
+ ])),
336
+ ]
337
+ : []),
338
+ ...(styleObject.length > 0 ? [t.objectProperty(t.identifier("style"), t.objectExpression(styleObject))] : []),
339
+ ]),
340
+ ...(statements.length > 0 ? [t.arrowFunctionExpression([internal_js_1.ctx], t.blockStatement(statements))] : []),
341
+ ]));
342
+ }
343
+ if (t.isJSXIdentifier(name)) {
344
+ const element = path.node;
345
+ const opening = path.get("openingElement");
346
+ const props = [];
347
+ let run;
348
+ for (const attrPath of opening.get("attributes")) {
349
+ const attr = attrPath.node;
350
+ // <A prop=../>
351
+ if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
352
+ // <A prop=".."/>
353
+ if (t.isStringLiteral(attr.value)) {
354
+ props.push(t.objectProperty(id(attr.name.name), attr.value));
355
+ }
356
+ // <A prop={..}/>
357
+ else if (t.isJSXExpressionContainer(attr.value)) {
358
+ const isSystem = internal.mapping.has(name.name);
359
+ const value = transformJsxExpressionContainer(attrPath.get("value"), internal, !isSystem || attr.name.name === "slot", isSystem && attr.name.name === "slot");
360
+ props.push(t.objectProperty(id(attr.name.name), value));
361
+ }
362
+ else {
363
+ throw attrPath.buildCodeFrameError("Vasille: JSX Elements/Fragments are not supported here");
364
+ }
365
+ }
366
+ // <A {...arg}/>
367
+ else if (t.isJSXSpreadAttribute(attr)) {
368
+ props.push(t.spreadElement(attr.argument));
369
+ }
370
+ // <A space:name=../>
371
+ else {
372
+ throw attrPath.buildCodeFrameError("Vasille: Namespaced attributes names are not supported");
373
+ }
374
+ }
375
+ if (element.children.length === 1 &&
376
+ t.isJSXExpressionContainer(element.children[0]) &&
377
+ (t.isFunctionExpression(element.children[0].expression) ||
378
+ t.isArrowFunctionExpression(element.children[0].expression))) {
379
+ run = element.children[0].expression;
380
+ run.params.push(internal_js_1.ctx);
381
+ }
382
+ else {
383
+ const statements = transformJsxArray(path.get("children"), internal);
384
+ if (statements.length > 0) {
385
+ run = t.arrowFunctionExpression([internal_js_1.ctx], t.blockStatement(statements));
386
+ }
387
+ }
388
+ return t.expressionStatement(t.callExpression(t.identifier(name.name), [internal_js_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]));
389
+ }
390
+ throw path.buildCodeFrameError("Vasille: Unsupported tag detected, html lowercase tagnames and components are accepted");
391
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parseCalculateCall = parseCalculateCall;
27
+ exports.exprCall = exprCall;
28
+ exports.forwardOnlyExpr = forwardOnlyExpr;
29
+ exports.own = own;
30
+ exports.ref = ref;
31
+ exports.reactiveObject = reactiveObject;
32
+ exports.arrayModel = arrayModel;
33
+ exports.setModel = setModel;
34
+ exports.mapModel = mapModel;
35
+ const t = __importStar(require("@babel/types"));
36
+ const expression_js_1 = require("./expression.js");
37
+ const internal_js_1 = require("./internal.js");
38
+ const call_js_1 = require("./call.js");
39
+ function parseCalculateCall(path, internal) {
40
+ if (t.isCallExpression(path.node) && (0, call_js_1.calls)(path.node, ["calculate", "watch"], internal)) {
41
+ if (path.node.arguments.length !== 1) {
42
+ throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
43
+ }
44
+ if (t.isFunctionExpression(path.node.arguments[0]) || t.isArrowFunctionExpression(path.node.arguments[0])) {
45
+ if (path.node.arguments[0].params.length > 0) {
46
+ throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
47
+ }
48
+ const exprData = (0, expression_js_1.checkNode)(path.get("arguments")[0], internal);
49
+ path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
50
+ return [path.node.arguments[0], ...exprData.found.values()];
51
+ }
52
+ else {
53
+ throw path.buildCodeFrameError("Vasille: Argument of calculate must be a function");
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+ function exprCall(path, expr, internal) {
59
+ const calculateCall = parseCalculateCall(path, internal);
60
+ if (calculateCall) {
61
+ return t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("expr")), calculateCall);
62
+ }
63
+ const exprData = (0, expression_js_1.checkNode)(path, internal);
64
+ return exprData.self
65
+ ? exprData.self
66
+ : exprData.found.size > 0 && expr
67
+ ? t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("expr")), [
68
+ t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name)), expr),
69
+ ...exprData.found.values(),
70
+ ])
71
+ : null;
72
+ }
73
+ function forwardOnlyExpr(path, expr, internal) {
74
+ if (t.isCallExpression(path.node) && (0, call_js_1.calls)(path.node, ["calculate"], internal)) {
75
+ if (path.node.arguments.length !== 1) {
76
+ throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
77
+ }
78
+ if (t.isFunctionExpression(path.node.arguments[0]) || t.isArrowFunctionExpression(path.node.arguments[0])) {
79
+ if (path.node.arguments[0].params.length > 0) {
80
+ throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
81
+ }
82
+ const exprData = (0, expression_js_1.checkNode)(path.get("arguments")[0], internal);
83
+ path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
84
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
85
+ path.node.arguments[0],
86
+ ...exprData.found.values(),
87
+ ]);
88
+ }
89
+ else {
90
+ throw path.buildCodeFrameError("Vasille: Argument of calculate must be a function");
91
+ }
92
+ }
93
+ const calculateCall = parseCalculateCall(path, internal);
94
+ if (calculateCall) {
95
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), calculateCall);
96
+ }
97
+ const exprData = (0, expression_js_1.checkNode)(path, internal);
98
+ return exprData.self
99
+ ? t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [exprData.self])
100
+ : exprData.found.size > 0 && expr
101
+ ? t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
102
+ t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name)), expr),
103
+ ...exprData.found.values(),
104
+ ])
105
+ : null;
106
+ }
107
+ function own(expr) {
108
+ return t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("own")), [expr]);
109
+ }
110
+ function ref(expr) {
111
+ return t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("ref")), expr ? [expr] : []);
112
+ }
113
+ function reactiveObject(init, internal) {
114
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("ro")), [internal_js_1.ctx, init]);
115
+ }
116
+ function arrayModel(init, internal) {
117
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("am")), [internal_js_1.ctx, ...(init ? [init] : [])]);
118
+ }
119
+ function setModel(args, internal) {
120
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("sm")), [internal_js_1.ctx, ...args]);
121
+ }
122
+ function mapModel(args, internal) {
123
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("mm")), [internal_js_1.ctx, ...args]);
124
+ }