babel-plugin-vasille 3.1.5 → 3.2.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.
package/lib-node/jsx.js CHANGED
@@ -60,6 +60,7 @@ function transformJsxArray(paths, internal) {
60
60
  .replace(/\s*\n\s*/gm, "\n");
61
61
  const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)]);
62
62
  call.loc = path.node.loc;
63
+ /* istanbul ignore else */
63
64
  if (call.loc) {
64
65
  for (const char of path.node.value) {
65
66
  if (!/\s/.test(char)) {
@@ -96,7 +97,7 @@ function transformJsxExpressionContainer(path, internal, acceptSlots, isInternal
96
97
  if (acceptSlots &&
97
98
  (t.isFunctionExpression(expression) || t.isArrowFunctionExpression(expression)) &&
98
99
  (0, jsx_detect_js_1.bodyHasJsx)(expression.body)) {
99
- (0, mesh_js_1.compose)(path.get("expression"), internal, isInternalSlot);
100
+ (0, mesh_js_1.compose)(path.get("expression"), internal, isInternalSlot, "slot");
100
101
  if (!isInternalSlot) {
101
102
  if (expression.params.length < 1) {
102
103
  expression.params.push(t.identifier(`_${internal.prefix}`));
@@ -112,11 +113,12 @@ function transformJsxExpressionContainer(path, internal, acceptSlots, isInternal
112
113
  else if (isInternalSlot && (t.isFunctionExpression(expression) || t.isArrowFunctionExpression(expression))) {
113
114
  expression.params.unshift(internal_js_1.ctx);
114
115
  }
115
- let call = (0, lib_js_1.exprCall)(path.get("expression"), expression, internal);
116
+ const exprPath = path.get("expression");
117
+ let call = (0, lib_js_1.exprCall)(exprPath, expression, internal);
116
118
  if (!call && t.isIdentifier(expression) && internal.stack.get(expression.name) === 3 /* VariableState.ReactiveObject */) {
117
119
  call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [expression]);
118
120
  }
119
- const result = call !== null && call !== void 0 ? call : expression;
121
+ const result = call !== null && call !== void 0 ? call : exprPath.node;
120
122
  result.loc = loc;
121
123
  return result;
122
124
  }
@@ -136,7 +138,7 @@ function idToProp(id, value, from) {
136
138
  return t.objectProperty(expr, value);
137
139
  }
138
140
  function transformJsxElement(path, internal) {
139
- var _a, _b, _c, _d, _e;
141
+ var _a, _b, _c, _d, _e, _f, _g;
140
142
  const name = path.node.openingElement.name;
141
143
  if (t.isJSXIdentifier(name) && name.name[0].toLowerCase() === name.name[0]) {
142
144
  const opening = path.get("openingElement");
@@ -152,10 +154,12 @@ function transformJsxElement(path, internal) {
152
154
  const attr = attrPath.node;
153
155
  if (t.isJSXAttribute(attr)) {
154
156
  const name = attr.name;
157
+ /* istanbul ignore else */
155
158
  if (t.isJSXIdentifier(name)) {
156
159
  if (name.name.startsWith("on")) {
157
160
  if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
158
161
  const path = attrPath.get("value");
162
+ /* istanbul ignore else */
159
163
  if (t.isExpression(path.node.expression)) {
160
164
  (0, mesh_js_1.meshExpression)(path.get("expression"), internal);
161
165
  }
@@ -169,6 +173,7 @@ function transformJsxElement(path, internal) {
169
173
  }
170
174
  else if (name.name === "class") {
171
175
  // class={[..]}
176
+ /* istanbul ignore else */
172
177
  if (t.isJSXExpressionContainer(attr.value) && t.isArrayExpression(attr.value.expression)) {
173
178
  const valuePath = attrPath.get("value");
174
179
  const arrayExprPath = valuePath.get("expression");
@@ -233,8 +238,9 @@ function transformJsxElement(path, internal) {
233
238
  }
234
239
  }
235
240
  // 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));
241
+ else if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
242
+ const expr = (_b = (0, lib_js_1.exprCall)(attrPath.get("value"), attr.value.expression, internal)) !== null && _b !== void 0 ? _b : attr.value.expression;
243
+ attrs.push(t.objectProperty(t.identifier("class"), expr));
238
244
  }
239
245
  // class="a b"
240
246
  else if (t.isStringLiteral(attr.value)) {
@@ -243,6 +249,7 @@ function transformJsxElement(path, internal) {
243
249
  }
244
250
  else if (name.name === "style") {
245
251
  // style={{..}}
252
+ /* istanbul ignore else */
246
253
  if (t.isJSXExpressionContainer(attr.value) && t.isObjectExpression(attr.value.expression)) {
247
254
  const valuePath = attrPath.get("value");
248
255
  const objectPath = valuePath.get("expression");
@@ -250,7 +257,7 @@ function transformJsxElement(path, internal) {
250
257
  // style={{a: b}}
251
258
  if (t.isObjectProperty(propPath.node)) {
252
259
  const prop = propPath;
253
- const value = (_b = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
260
+ const value = (_c = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _c !== void 0 ? _c : prop.node.value;
254
261
  if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
255
262
  (0, mesh_js_1.meshExpression)(prop.get("key"), internal);
256
263
  }
@@ -309,10 +316,15 @@ function transformJsxElement(path, internal) {
309
316
  console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
310
317
  }
311
318
  }
319
+ else if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
320
+ const expr = (_d = (0, lib_js_1.exprCall)(attrPath.get("value"), attr.value.expression, internal)) !== null && _d !== void 0 ? _d : attr.value.expression;
321
+ attrs.push(t.objectProperty(t.identifier("style"), expr));
322
+ }
312
323
  }
313
324
  else {
325
+ /* istanbul ignore else */
314
326
  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)));
327
+ attrs.push(idToProp(name, t.isExpression((_e = attr.value) === null || _e === void 0 ? void 0 : _e.expression) ? attr.value.expression : t.booleanLiteral(true)));
316
328
  }
317
329
  else if (t.isStringLiteral(attr.value)) {
318
330
  attrs.push(idToProp(name, attr.value));
@@ -321,11 +333,12 @@ function transformJsxElement(path, internal) {
321
333
  }
322
334
  if (t.isJSXNamespacedName(name)) {
323
335
  if (name.namespace.name === "bind") {
336
+ /* istanbul ignore else */
324
337
  if (t.isJSXExpressionContainer(attr.value) || !attr.value) {
325
- const value = t.isExpression((_d = attr.value) === null || _d === void 0 ? void 0 : _d.expression)
338
+ const value = t.isExpression((_f = attr.value) === null || _f === void 0 ? void 0 : _f.expression)
326
339
  ? (0, lib_js_1.exprCall)(attrPath.get("value").get("expression"), attr.value.expression, internal)
327
340
  : undefined;
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))));
341
+ bind.push(idToProp(name.name, value !== null && value !== void 0 ? value : (t.isExpression((_g = attr.value) === null || _g === void 0 ? void 0 : _g.expression) ? attr.value.expression : t.booleanLiteral(true))));
329
342
  }
330
343
  else if (t.isStringLiteral(attr.value)) {
331
344
  bind.push(idToProp(name.name, attr.value));
@@ -385,6 +398,7 @@ function transformJsxElement(path, internal) {
385
398
  // <A prop=../>
386
399
  if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
387
400
  // <A prop=".."/>
401
+ /* istanbul ignore else */
388
402
  if (t.isStringLiteral(attr.value)) {
389
403
  props.push(idToProp(attr.name, attr.value));
390
404
  }
@@ -431,7 +445,7 @@ function transformJsxElement(path, internal) {
431
445
  run = t.arrowFunctionExpression(params, t.blockStatement(statements));
432
446
  }
433
447
  }
434
- const call = t.callExpression(t.identifier(name.name), [internal_js_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]);
448
+ const call = t.callExpression(t.identifier(name.name), [t.objectExpression(props), internal_js_1.ctx, ...(run ? [run] : [])]);
435
449
  call.loc = path.node.loc;
436
450
  return t.expressionStatement(call);
437
451
  }
package/lib-node/lib.js CHANGED
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.named = named;
37
+ exports.processCalculateCall = processCalculateCall;
37
38
  exports.parseCalculateCall = parseCalculateCall;
38
39
  exports.exprCall = exprCall;
39
40
  exports.forwardOnlyExpr = forwardOnlyExpr;
@@ -56,23 +57,24 @@ function named(call, name, internal, argPos) {
56
57
  }
57
58
  return call;
58
59
  }
59
- function parseCalculateCall(path, internal) {
60
- if (t.isCallExpression(path.node) && (0, call_js_1.calls)(path.node, ["calculate", "watch"], internal)) {
61
- const call = path.node.arguments[0];
62
- if (path.node.arguments.length !== 1) {
63
- throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
64
- }
65
- if (t.isFunctionExpression(call) || t.isArrowFunctionExpression(call)) {
66
- if (call.params.length > 0) {
67
- throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
68
- }
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()])];
72
- }
73
- else {
74
- throw path.buildCodeFrameError("Vasille: Argument of calculate must be a function");
60
+ function processCalculateCall(path, internal) {
61
+ const call = path.node.arguments[0];
62
+ if (path.node.arguments.length !== 1) {
63
+ throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
64
+ }
65
+ if (t.isFunctionExpression(call) || t.isArrowFunctionExpression(call)) {
66
+ if (call.params.length > 0) {
67
+ throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
75
68
  }
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()])];
72
+ }
73
+ throw path.buildCodeFrameError("Vasille: Argument of calculate must be a function");
74
+ }
75
+ function parseCalculateCall(path, internal) {
76
+ if (t.isCallExpression(path.node) && (0, call_js_1.calls)(path, ["calculate", "watch"], internal)) {
77
+ return processCalculateCall(path, internal);
76
78
  }
77
79
  return null;
78
80
  }
@@ -84,10 +86,11 @@ function exprCall(path, expr, internal, name) {
84
86
  : t.memberExpression(internal_js_1.ctx, t.identifier("expr")), calculateCall), name, internal);
85
87
  }
86
88
  if (t.isCallExpression(expr) &&
87
- (0, call_js_1.calls)(expr, ["forward"], internal) &&
89
+ (0, call_js_1.calls)(path, ["forward"], internal) &&
88
90
  expr.arguments.length === 1 &&
89
91
  t.isExpression(expr.arguments[0])) {
90
92
  const data = exprCall(path.get("arguments")[0], expr.arguments[0], internal);
93
+ /* istanbul ignore else */
91
94
  if (data && !t.isCallExpression(data)) {
92
95
  return t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [data]);
93
96
  }
@@ -96,12 +99,15 @@ function exprCall(path, expr, internal, name) {
96
99
  if (exprData.self) {
97
100
  return exprData.self;
98
101
  }
99
- const names = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
102
+ const names = [...exprData.found.keys()].map(expression_js_1.encodeName);
100
103
  const dependencies = t.arrayExpression([...exprData.found.values()]);
101
- if (names.length > 0 && expr) {
104
+ if (expr !== path.node && names.length === 1 && t.isIdentifier(path.node) && path.node.name === names[0].name) {
105
+ return [...exprData.found.values()][0];
106
+ }
107
+ if (names.length > 0 && path.node) {
102
108
  return named(t.callExpression(internal.stateOnly
103
109
  ? t.memberExpression(internal.id, t.identifier("ex"))
104
- : t.memberExpression(internal_js_1.ctx, t.identifier("expr")), [t.arrowFunctionExpression(names, expr), dependencies]), name, internal);
110
+ : t.memberExpression(internal_js_1.ctx, t.identifier("expr")), [t.arrowFunctionExpression(names, path.node), dependencies]), name, internal);
105
111
  }
106
112
  return null;
107
113
  }