babel-plugin-vasille 0.99.4 → 3.1.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.
package/lib-node/jsx.js CHANGED
@@ -15,21 +15,31 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.transformJsx = transformJsx;
27
37
  exports.transformJsxArray = transformJsxArray;
28
38
  const t = __importStar(require("@babel/types"));
29
- const internal_1 = require("./internal");
30
- const lib_1 = require("./lib");
31
- const mesh_1 = require("./mesh");
32
- const jsx_detect_1 = require("./jsx-detect");
39
+ const internal_js_1 = require("./internal.js");
40
+ const lib_js_1 = require("./lib.js");
41
+ const mesh_js_1 = require("./mesh.js");
42
+ const jsx_detect_js_1 = require("./jsx-detect.js");
33
43
  function transformJsx(path, internal) {
34
44
  if (t.isJSXElement(path.node)) {
35
45
  return [transformJsxElement(path, internal)];
@@ -48,7 +58,7 @@ function transformJsxArray(paths, internal) {
48
58
  .replace(/\n\s+$/m, "")
49
59
  .replace(/^\s*\n\s+/m, "")
50
60
  .replace(/\s*\n\s*/gm, "\n");
51
- const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)]);
61
+ const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)]);
52
62
  call.loc = path.node.loc;
53
63
  if (call.loc) {
54
64
  for (const char of path.node.value) {
@@ -70,7 +80,7 @@ function transformJsxArray(paths, internal) {
70
80
  }
71
81
  else if (t.isJSXExpressionContainer(path.node)) {
72
82
  const value = transformJsxExpressionContainer(path, internal, false, false);
73
- const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("text")), [value]);
83
+ const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [value]);
74
84
  call.loc = value.loc;
75
85
  result.push(t.expressionStatement(call));
76
86
  }
@@ -81,37 +91,32 @@ function transformJsxArray(paths, internal) {
81
91
  return result;
82
92
  }
83
93
  function transformJsxExpressionContainer(path, internal, acceptSlots, isInternalSlot) {
84
- if (!t.isExpression(path.node.expression)) {
85
- return t.booleanLiteral(true);
86
- }
87
- const loc = path.node.expression.loc;
94
+ const expression = path.node.expression;
95
+ const loc = expression.loc;
88
96
  if (acceptSlots &&
89
- (t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression)) &&
90
- (0, jsx_detect_1.bodyHasJsx)(path.node.expression.body)) {
91
- (0, mesh_1.compose)(path.get("expression"), internal, isInternalSlot);
97
+ (t.isFunctionExpression(expression) || t.isArrowFunctionExpression(expression)) &&
98
+ (0, jsx_detect_js_1.bodyHasJsx)(expression.body)) {
99
+ (0, mesh_js_1.compose)(path.get("expression"), internal, isInternalSlot);
92
100
  if (!isInternalSlot) {
93
- if (path.node.expression.params.length < 1) {
94
- path.node.expression.params.push(t.identifier(internal.prefix));
101
+ if (expression.params.length < 1) {
102
+ expression.params.push(t.identifier(`_${internal.prefix}`));
95
103
  }
96
- path.node.expression.params.push(internal_1.ctx);
104
+ expression.params.push(internal_js_1.ctx);
97
105
  }
98
106
  else {
99
- path.node.expression.params.unshift(internal_1.ctx);
107
+ expression.params.unshift(internal_js_1.ctx);
100
108
  }
101
- path.node.expression.loc = loc;
102
- return path.node.expression;
109
+ expression.loc = loc;
110
+ return expression;
103
111
  }
104
- else if (isInternalSlot &&
105
- (t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression))) {
106
- path.node.expression.params.unshift(internal_1.ctx);
112
+ else if (isInternalSlot && (t.isFunctionExpression(expression) || t.isArrowFunctionExpression(expression))) {
113
+ expression.params.unshift(internal_js_1.ctx);
107
114
  }
108
- let call = (0, lib_1.exprCall)(path.get("expression"), path.node.expression, internal);
109
- if (!call &&
110
- t.isIdentifier(path.node.expression) &&
111
- internal.stack.get(path.node.expression.name) === 3 /* VariableState.ReactiveObject */) {
112
- call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [path.node.expression]);
115
+ let call = (0, lib_js_1.exprCall)(path.get("expression"), expression, internal);
116
+ if (!call && t.isIdentifier(expression) && internal.stack.get(expression.name) === 3 /* VariableState.ReactiveObject */) {
117
+ call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [expression]);
113
118
  }
114
- const result = call !== null && call !== void 0 ? call : path.node.expression;
119
+ const result = call !== null && call !== void 0 ? call : expression;
115
120
  result.loc = loc;
116
121
  return result;
117
122
  }
@@ -131,7 +136,7 @@ function idToProp(id, value, from) {
131
136
  return t.objectProperty(expr, value);
132
137
  }
133
138
  function transformJsxElement(path, internal) {
134
- var _a, _b;
139
+ var _a, _b, _c, _d, _e;
135
140
  const name = path.node.openingElement.name;
136
141
  if (t.isJSXIdentifier(name) && name.name[0].toLowerCase() === name.name[0]) {
137
142
  const opening = path.get("openingElement");
@@ -152,7 +157,7 @@ function transformJsxElement(path, internal) {
152
157
  if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
153
158
  const path = attrPath.get("value");
154
159
  if (t.isExpression(path.node.expression)) {
155
- (0, mesh_1.meshExpression)(path.get("expression"), internal);
160
+ (0, mesh_js_1.meshExpression)(path.get("expression"), internal);
156
161
  }
157
162
  events.push(idToProp(name, path.node.expression, 2));
158
163
  }
@@ -172,7 +177,7 @@ function transformJsxElement(path, internal) {
172
177
  if (t.isExpression(item)) {
173
178
  // class={[cond && "string"]}
174
179
  if (t.isLogicalExpression(item) && item.operator === "&&" && t.isStringLiteral(item.right)) {
175
- const call = (0, lib_1.exprCall)(elementPath.get("left"), item.left, internal);
180
+ const call = (0, lib_js_1.exprCall)(elementPath.get("left"), item.left, internal);
176
181
  classObject.push(idToProp(item.right, call !== null && call !== void 0 ? call : item.left));
177
182
  }
178
183
  // class={[{..}]}
@@ -181,9 +186,9 @@ function transformJsxElement(path, internal) {
181
186
  // class={[{a: b}]}
182
187
  if (t.isObjectProperty(propPath.node)) {
183
188
  const prop = propPath;
184
- const value = (_a = (0, lib_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
189
+ const value = (_a = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
185
190
  if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
186
- (0, mesh_1.meshExpression)(prop.get("key"), internal);
191
+ (0, mesh_js_1.meshExpression)(prop.get("key"), internal);
187
192
  }
188
193
  classObject.push(t.objectProperty(prop.node.key, value));
189
194
  }
@@ -193,7 +198,7 @@ function transformJsxElement(path, internal) {
193
198
  }
194
199
  // class={[{a(){}}]}
195
200
  else {
196
- throw propPath.buildCodeFrameError("Vasille: Methods are not alllowed here");
201
+ throw propPath.buildCodeFrameError("Vasille: Methods are not allowed here");
197
202
  }
198
203
  }
199
204
  }
@@ -203,7 +208,7 @@ function transformJsxElement(path, internal) {
203
208
  }
204
209
  // class={[..]}
205
210
  else {
206
- const call = (0, lib_1.exprCall)(elementPath, item, internal);
211
+ const call = (0, lib_js_1.exprCall)(elementPath, item, internal);
207
212
  classElements.push(call !== null && call !== void 0 ? call : item);
208
213
  }
209
214
  }
@@ -221,20 +226,20 @@ function transformJsxElement(path, internal) {
221
226
  else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
222
227
  const jsxAttrPath = attrPath;
223
228
  const jsxContainerPath = jsxAttrPath.get("value");
224
- const value = (0, lib_1.exprCall)(jsxContainerPath.get("expression"), attr.value.expression, internal);
229
+ const value = (0, lib_js_1.exprCall)(jsxContainerPath.get("expression"), attr.value.expression, internal);
225
230
  attrs.push(t.objectProperty(t.identifier("class"), value !== null && value !== void 0 ? value : attr.value.expression));
226
231
  if (value) {
227
232
  console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
228
233
  }
229
234
  }
235
+ // class={name}
236
+ else if (t.isJSXExpressionContainer(attr.value) && t.isIdentifier(attr.value.expression)) {
237
+ attrs.push(t.objectProperty(t.identifier("class"), attr.value.expression));
238
+ }
230
239
  // class="a b"
231
240
  else if (t.isStringLiteral(attr.value)) {
232
241
  classStatic.push(attr.value);
233
242
  }
234
- // class=<div/>
235
- else {
236
- throw attrPath.buildCodeFrameError('Vasille: Value of "class" attribute must be an array expression');
237
- }
238
243
  }
239
244
  else if (name.name === "style") {
240
245
  // style={{..}}
@@ -245,9 +250,9 @@ function transformJsxElement(path, internal) {
245
250
  // style={{a: b}}
246
251
  if (t.isObjectProperty(propPath.node)) {
247
252
  const prop = propPath;
248
- const value = (_b = (0, lib_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
253
+ const value = (_b = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
249
254
  if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
250
- (0, mesh_1.meshExpression)(prop.get("key"), internal);
255
+ (0, mesh_js_1.meshExpression)(prop.get("key"), internal);
251
256
  }
252
257
  // style={{a: "b"}} -> static in compile time
253
258
  if (t.isIdentifier(prop.node.key) && t.isStringLiteral(prop.node.value)) {
@@ -281,10 +286,14 @@ function transformJsxElement(path, internal) {
281
286
  }
282
287
  // style={{a(){}}}
283
288
  else {
284
- throw propPath.buildCodeFrameError("Vasille: Methods are not alllowed here");
289
+ throw propPath.buildCodeFrameError("Vasille: Methods are not allowed here");
285
290
  }
286
291
  }
287
292
  }
293
+ // style=".."
294
+ else if (t.isStringLiteral(attr.value)) {
295
+ attrs.push(t.objectProperty(t.identifier("style"), attr.value));
296
+ }
288
297
  // style={".."}
289
298
  else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
290
299
  attrs.push(t.objectProperty(t.identifier("style"), attr.value.expression));
@@ -294,43 +303,33 @@ function transformJsxElement(path, internal) {
294
303
  const jsxAttrPath = attrPath;
295
304
  const jsxContainerPath = jsxAttrPath.get("value");
296
305
  const literalPath = jsxContainerPath.get("expression");
297
- const value = (0, lib_1.exprCall)(literalPath, attr.value.expression, internal);
306
+ const value = (0, lib_js_1.exprCall)(literalPath, attr.value.expression, internal);
298
307
  attrs.push(t.objectProperty(t.identifier("style"), value !== null && value !== void 0 ? value : attr.value.expression));
299
308
  if (value) {
300
309
  console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
301
310
  }
302
311
  }
303
- // style=<div/>
304
- else {
305
- throw attrPath.buildCodeFrameError('Vasille: Value of "style" attribute must be an object expression');
306
- }
307
312
  }
308
313
  else {
309
- if (t.isJSXExpressionContainer(attr.value)) {
310
- attrs.push(idToProp(name, t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true)));
314
+ if (!attr.value || t.isJSXExpressionContainer(attr.value)) {
315
+ attrs.push(idToProp(name, t.isExpression((_c = attr.value) === null || _c === void 0 ? void 0 : _c.expression) ? attr.value.expression : t.booleanLiteral(true)));
311
316
  }
312
317
  else if (t.isStringLiteral(attr.value)) {
313
318
  attrs.push(idToProp(name, attr.value));
314
319
  }
315
- else {
316
- throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
317
- }
318
320
  }
319
321
  }
320
322
  if (t.isJSXNamespacedName(name)) {
321
323
  if (name.namespace.name === "bind") {
322
- if (t.isJSXExpressionContainer(attr.value)) {
323
- const value = t.isExpression(attr.value.expression)
324
- ? (0, lib_1.exprCall)(attrPath.get("value"), attr.value.expression, internal)
324
+ if (t.isJSXExpressionContainer(attr.value) || !attr.value) {
325
+ const value = t.isExpression((_d = attr.value) === null || _d === void 0 ? void 0 : _d.expression)
326
+ ? (0, lib_js_1.exprCall)(attrPath.get("value").get("expression"), attr.value.expression, internal)
325
327
  : undefined;
326
- bind.push(idToProp(name.name, value !== null && value !== void 0 ? value : (t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true))));
328
+ bind.push(idToProp(name.name, value !== null && value !== void 0 ? value : (t.isExpression((_e = attr.value) === null || _e === void 0 ? void 0 : _e.expression) ? attr.value.expression : t.booleanLiteral(true))));
327
329
  }
328
330
  else if (t.isStringLiteral(attr.value)) {
329
331
  bind.push(idToProp(name.name, attr.value));
330
332
  }
331
- else {
332
- throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
333
- }
334
333
  }
335
334
  else {
336
335
  throw attrPath.buildCodeFrameError("Vasille: only bind namespace is supported");
@@ -351,7 +350,7 @@ function transformJsxElement(path, internal) {
351
350
  attrs.push(t.objectProperty(t.identifier("style"), t.stringLiteral(styleStatic.map(([id, value]) => `${id.name}:${value.value}`).join(";"))));
352
351
  }
353
352
  const statements = transformJsxArray(path.get("children"), internal);
354
- const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("tag")), [
353
+ const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("tag")), [
355
354
  t.stringLiteral(name.name),
356
355
  t.objectExpression([
357
356
  ...(attrs.length > 0 ? [t.objectProperty(t.identifier("attr"), t.objectExpression(attrs))] : []),
@@ -367,7 +366,7 @@ function transformJsxElement(path, internal) {
367
366
  : []),
368
367
  ...(styleObject.length > 0 ? [t.objectProperty(t.identifier("style"), t.objectExpression(styleObject))] : []),
369
368
  ]),
370
- ...(statements.length > 0 ? [t.arrowFunctionExpression([internal_1.ctx], t.blockStatement(statements))] : []),
369
+ ...(statements.length > 0 ? [t.arrowFunctionExpression([internal_js_1.ctx], t.blockStatement(statements))] : []),
371
370
  ]);
372
371
  call.loc = path.node.loc;
373
372
  return t.expressionStatement(call);
@@ -395,8 +394,8 @@ function transformJsxElement(path, internal) {
395
394
  const value = transformJsxExpressionContainer(attrPath.get("value"), internal, !isSystem || attr.name.name === "slot", isSystem && attr.name.name === "slot");
396
395
  props.push(idToProp(attr.name, value));
397
396
  }
398
- else {
399
- throw attrPath.buildCodeFrameError("Vasille: JSX Elements/Fragments are not supported here");
397
+ else if (!attr.value) {
398
+ props.push(idToProp(attr.name, t.booleanLiteral(true)));
400
399
  }
401
400
  }
402
401
  // <A {...arg}/>
@@ -408,22 +407,33 @@ function transformJsxElement(path, internal) {
408
407
  throw attrPath.buildCodeFrameError("Vasille: Namespaced attributes names are not supported");
409
408
  }
410
409
  }
411
- if (element.children.length === 1 &&
412
- t.isJSXExpressionContainer(element.children[0]) &&
413
- (t.isFunctionExpression(element.children[0].expression) ||
414
- t.isArrowFunctionExpression(element.children[0].expression))) {
415
- run = element.children[0].expression;
416
- run.params.push(internal_1.ctx);
410
+ const filteredChildren = element.children.filter(item => {
411
+ if (!t.isJSXText(item)) {
412
+ return true;
413
+ }
414
+ return !!item.value.trim();
415
+ });
416
+ const isInternal = internal.mapping.has(name.name);
417
+ if (filteredChildren.length === 1 &&
418
+ t.isJSXExpressionContainer(filteredChildren[0]) &&
419
+ (t.isFunctionExpression(filteredChildren[0].expression) ||
420
+ t.isArrowFunctionExpression(filteredChildren[0].expression))) {
421
+ transformJsxExpressionContainer(path.get("children")[element.children.indexOf(filteredChildren[0])], internal, true, isInternal);
422
+ run = filteredChildren[0].expression;
417
423
  }
418
424
  else {
419
425
  const statements = transformJsxArray(path.get("children"), internal);
420
426
  if (statements.length > 0) {
421
- run = t.arrowFunctionExpression([internal_1.ctx], t.blockStatement(statements));
427
+ const params = [internal_js_1.ctx];
428
+ if (!isInternal) {
429
+ params.unshift(t.identifier(`_${internal.prefix}`));
430
+ }
431
+ run = t.arrowFunctionExpression(params, t.blockStatement(statements));
422
432
  }
423
433
  }
424
- const call = t.callExpression(t.identifier(name.name), [internal_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]);
434
+ const call = t.callExpression(t.identifier(name.name), [internal_js_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]);
425
435
  call.loc = path.node.loc;
426
436
  return t.expressionStatement(call);
427
437
  }
428
- throw path.buildCodeFrameError("Vasille: Unsupported tag detected, html lowercase tagnames and components are accepted");
438
+ throw path.buildCodeFrameError("Vasille: Unsupported tag detected, html lowercase tag names and components are accepted");
429
439
  }
package/lib-node/lib.js CHANGED
@@ -15,14 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.named = named;
26
37
  exports.parseCalculateCall = parseCalculateCall;
27
38
  exports.exprCall = exprCall;
28
39
  exports.forwardOnlyExpr = forwardOnlyExpr;
@@ -33,21 +44,31 @@ exports.arrayModel = arrayModel;
33
44
  exports.setModel = setModel;
34
45
  exports.mapModel = mapModel;
35
46
  const t = __importStar(require("@babel/types"));
36
- const expression_1 = require("./expression");
37
- const internal_1 = require("./internal");
38
- const call_1 = require("./call");
47
+ const expression_js_1 = require("./expression.js");
48
+ const internal_js_1 = require("./internal.js");
49
+ const call_js_1 = require("./call.js");
50
+ function named(call, name, internal, argPos) {
51
+ if (internal.devMode && !internal.stateOnly && name) {
52
+ while (argPos && call.arguments.length < argPos) {
53
+ call.arguments.push(t.buildUndefinedNode());
54
+ }
55
+ call.arguments.push(...(typeof name === "string" ? [t.stringLiteral(name)] : name.map(item => t.stringLiteral(item))));
56
+ }
57
+ return call;
58
+ }
39
59
  function parseCalculateCall(path, internal) {
40
- if (t.isCallExpression(path.node) && (0, call_1.calls)(path.node, ["calculate", "watch"], internal)) {
60
+ if (t.isCallExpression(path.node) && (0, call_js_1.calls)(path.node, ["calculate", "watch"], internal)) {
61
+ const call = path.node.arguments[0];
41
62
  if (path.node.arguments.length !== 1) {
42
63
  throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
43
64
  }
44
- if (t.isFunctionExpression(path.node.arguments[0]) || t.isArrowFunctionExpression(path.node.arguments[0])) {
45
- if (path.node.arguments[0].params.length > 0) {
65
+ if (t.isFunctionExpression(call) || t.isArrowFunctionExpression(call)) {
66
+ if (call.params.length > 0) {
46
67
  throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
47
68
  }
48
- const exprData = (0, expression_1.checkNode)(path.get("arguments")[0], internal);
49
- path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0, expression_1.encodeName)(name));
50
- return [path.node.arguments[0], ...exprData.found.values()];
69
+ const exprData = (0, expression_js_1.checkNode)(path.get("arguments")[0], internal);
70
+ call.params = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
71
+ return [call, t.arrayExpression([...exprData.found.values()])];
51
72
  }
52
73
  else {
53
74
  throw path.buildCodeFrameError("Vasille: Argument of calculate must be a function");
@@ -55,70 +76,78 @@ function parseCalculateCall(path, internal) {
55
76
  }
56
77
  return null;
57
78
  }
58
- function exprCall(path, expr, internal) {
79
+ function exprCall(path, expr, internal, name) {
59
80
  const calculateCall = parseCalculateCall(path, internal);
60
81
  if (calculateCall) {
61
- return t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("expr")), calculateCall);
82
+ return named(t.callExpression(internal.stateOnly
83
+ ? t.memberExpression(internal.id, t.identifier("ex"))
84
+ : t.memberExpression(internal_js_1.ctx, t.identifier("expr")), calculateCall), name, internal);
62
85
  }
63
- const exprData = (0, expression_1.checkNode)(path, internal);
64
- return exprData.self
65
- ? exprData.self
66
- : exprData.found.size > 0 && expr
67
- ? t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("expr")), [
68
- t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_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_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_1.checkNode)(path.get("arguments")[0], internal);
83
- path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0, expression_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");
86
+ if (t.isCallExpression(expr) &&
87
+ (0, call_js_1.calls)(expr, ["forward"], internal) &&
88
+ expr.arguments.length === 1 &&
89
+ t.isExpression(expr.arguments[0])) {
90
+ const data = exprCall(path.get("arguments")[0], expr.arguments[0], internal);
91
+ if (data && !t.isCallExpression(data)) {
92
+ return t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [data]);
91
93
  }
92
94
  }
95
+ const exprData = (0, expression_js_1.checkNode)(path, internal);
96
+ if (exprData.self) {
97
+ return exprData.self;
98
+ }
99
+ const names = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
100
+ const dependencies = t.arrayExpression([...exprData.found.values()]);
101
+ if (names.length > 0 && expr) {
102
+ return named(t.callExpression(internal.stateOnly
103
+ ? t.memberExpression(internal.id, t.identifier("ex"))
104
+ : t.memberExpression(internal_js_1.ctx, t.identifier("expr")), [t.arrowFunctionExpression(names, expr), dependencies]), name, internal);
105
+ }
106
+ return null;
107
+ }
108
+ function forwardOnlyExpr(path, expr, internal) {
93
109
  const calculateCall = parseCalculateCall(path, internal);
94
110
  if (calculateCall) {
95
111
  return t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), calculateCall);
96
112
  }
97
- const exprData = (0, expression_1.checkNode)(path, internal);
113
+ const exprData = (0, expression_js_1.checkNode)(path, internal);
98
114
  return exprData.self
99
115
  ? t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [exprData.self])
100
116
  : exprData.found.size > 0 && expr
101
117
  ? t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
102
- t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_1.encodeName)(name)), expr),
103
- ...exprData.found.values(),
118
+ t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name)), expr),
119
+ t.arrayExpression([...exprData.found.values()]),
104
120
  ])
105
121
  : null;
106
122
  }
107
- function own(expr) {
108
- return t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("own")), [expr]);
123
+ function own(expr, internal, name) {
124
+ if (internal.stateOnly &&
125
+ t.isCallExpression(expr) &&
126
+ t.isMemberExpression(expr.callee) &&
127
+ t.isIdentifier(expr.callee.property) &&
128
+ expr.callee.property.name === "fo" &&
129
+ t.isIdentifier(expr.callee.object) &&
130
+ expr.callee.object === internal.id) {
131
+ return expr;
132
+ }
133
+ return named(t.callExpression(internal.stateOnly
134
+ ? t.memberExpression(internal.id, t.identifier("fo"))
135
+ : t.memberExpression(internal_js_1.ctx, t.identifier("own")), [expr]), name, internal);
109
136
  }
110
- function ref(expr) {
111
- return t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("ref")), expr ? [expr] : []);
137
+ function ref(expr, internal, name) {
138
+ return named(t.callExpression(internal.stateOnly
139
+ ? t.memberExpression(internal.id, t.identifier("r"))
140
+ : t.memberExpression(internal_js_1.ctx, t.identifier("ref")), expr ? [expr] : []), name, internal, 1);
112
141
  }
113
- function reactiveObject(init, internal) {
114
- return t.callExpression(t.memberExpression(internal.id, t.identifier("ro")), [internal_1.ctx, init]);
142
+ function reactiveObject(init, internal, name) {
143
+ return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "sro" : "ro")), internal.stateOnly ? [init] : [internal_js_1.ctx, init]), name, internal);
115
144
  }
116
- function arrayModel(init, internal) {
117
- return t.callExpression(t.memberExpression(internal.id, t.identifier("am")), [internal_1.ctx, ...(init ? [init] : [])]);
145
+ function arrayModel(init, internal, name) {
146
+ return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "sam" : "am")), internal.stateOnly ? (init ? [init] : []) : [internal_js_1.ctx, ...(init ? [init] : [])]), name, internal, 2);
118
147
  }
119
- function setModel(args, internal) {
120
- return t.callExpression(t.memberExpression(internal.id, t.identifier("sm")), [internal_1.ctx, ...args]);
148
+ function setModel(args, internal, name) {
149
+ return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "ssm" : "sm")), internal.stateOnly ? args : [internal_js_1.ctx, ...args]), name, internal);
121
150
  }
122
- function mapModel(args, internal) {
123
- return t.callExpression(t.memberExpression(internal.id, t.identifier("mm")), [internal_1.ctx, ...args]);
151
+ function mapModel(args, internal, name) {
152
+ return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "smm" : "mm")), internal.stateOnly ? args : [internal_js_1.ctx, ...args]), name, internal);
124
153
  }