babel-plugin-vasille 4.3.3 → 5.0.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/README.md +43 -31
- package/lib/call.js +8 -5
- package/lib/expression.js +60 -49
- package/lib/index.js +1 -1
- package/lib/internal.js +10 -4
- package/lib/jsx.js +35 -67
- package/lib/lib.js +46 -45
- package/lib/mesh.js +103 -45
- package/lib/order-check.js +8 -6
- package/lib/transformer.js +163 -25
- package/package.json +3 -4
package/lib/jsx.js
CHANGED
|
@@ -37,11 +37,11 @@ exports.transformJsx = transformJsx;
|
|
|
37
37
|
exports.transformJsxArray = transformJsxArray;
|
|
38
38
|
exports.processConditions = processConditions;
|
|
39
39
|
const t = __importStar(require("@babel/types"));
|
|
40
|
-
const call_1 = require("./call");
|
|
41
40
|
const internal_js_1 = require("./internal.js");
|
|
42
41
|
const jsx_detect_js_1 = require("./jsx-detect.js");
|
|
43
42
|
const lib_js_1 = require("./lib.js");
|
|
44
43
|
const mesh_js_1 = require("./mesh.js");
|
|
44
|
+
const transformer_1 = require("./transformer");
|
|
45
45
|
function transformJsx(path, conditions, internal) {
|
|
46
46
|
if (path.isJSXElement()) {
|
|
47
47
|
return transformJsxElement(path, conditions, internal);
|
|
@@ -64,7 +64,9 @@ function transformJsxArray(paths, internal) {
|
|
|
64
64
|
.replace(/\n\s+$/m, "")
|
|
65
65
|
.replace(/^\s*\n\s+/m, "")
|
|
66
66
|
.replace(/\s*\n\s*/gm, "\n");
|
|
67
|
-
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [
|
|
67
|
+
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [
|
|
68
|
+
internal.devLayer ? internal.positionedText(t.stringLiteral(fixed), path.node) : t.stringLiteral(fixed),
|
|
69
|
+
]);
|
|
68
70
|
call.loc = path.node.loc;
|
|
69
71
|
/* istanbul ignore else */
|
|
70
72
|
if (call.loc) {
|
|
@@ -94,7 +96,9 @@ function transformJsxArray(paths, internal) {
|
|
|
94
96
|
const value = transformJsxExpressionContainer(path, internal, false, false, true, true);
|
|
95
97
|
/* istanbul ignore else */
|
|
96
98
|
if (!t.isJSXEmptyExpression(value)) {
|
|
97
|
-
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [
|
|
99
|
+
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [
|
|
100
|
+
internal.devLayer ? internal.positionedText(value, value) : value,
|
|
101
|
+
]);
|
|
98
102
|
call.loc = value.loc;
|
|
99
103
|
result.push(t.expressionStatement(call));
|
|
100
104
|
}
|
|
@@ -126,7 +130,7 @@ function checkIfExpressionIsConditionalJsx(expr) {
|
|
|
126
130
|
(t.isJSX(expr.alternate) || checkIfExpressionIsConditionalJsx(expr.alternate))));
|
|
127
131
|
}
|
|
128
132
|
function processReactiveCondition(path, internal) {
|
|
129
|
-
(0, lib_js_1.exprCall)(path, path.node, internal, {});
|
|
133
|
+
(0, lib_js_1.exprCall)(path, path.node, internal, {}, path.node);
|
|
130
134
|
return path.node;
|
|
131
135
|
}
|
|
132
136
|
function addConditionToCollection(condition, exprPath, internal, conditions) {
|
|
@@ -203,49 +207,10 @@ function transformJsxExpressionContainer(path, internal, acceptSlots, isInternal
|
|
|
203
207
|
/* istanbul ignore else */
|
|
204
208
|
if (expression.isExpression()) {
|
|
205
209
|
if (acceptsReactive) {
|
|
206
|
-
// cals backward
|
|
207
|
-
if ((0, call_1.calls)(expression, ["backward"], internal)) {
|
|
208
|
-
const argPath = expression.get("arguments")[0];
|
|
209
|
-
if (argPath && argPath.isExpression()) {
|
|
210
|
-
const argValue = argPath.node;
|
|
211
|
-
if ((0, lib_js_1.exprCall)(argPath, argPath.node, internal, { strong: true })) {
|
|
212
|
-
if (!argPath.isMemberExpression() && !argPath.isIdentifier()) {
|
|
213
|
-
argPath.node = argValue;
|
|
214
|
-
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, argPath, "A reactive variable or object field expected, reactive expression are forward only", internal);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
argPath.node = argValue;
|
|
219
|
-
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, argPath, "The backward argument is not reactive", internal);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
(0, lib_js_1.err)(lib_js_1.Errors.IncorrectArguments, expression, "The argument is missing", internal);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
// calls forward
|
|
227
|
-
else if ((0, call_1.calls)(expression, ["forward"], internal)) {
|
|
228
|
-
const argPath = expression.get("arguments")[0];
|
|
229
|
-
if (argPath && argPath.isExpression()) {
|
|
230
|
-
const argValue = argPath.node;
|
|
231
|
-
if (!(0, lib_js_1.exprCall)(argPath, argPath.node, internal, { strong: true })) {
|
|
232
|
-
argPath.node = argValue;
|
|
233
|
-
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, argPath, "A reactive expression expected, argument value is constant", internal);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
expression.node.arguments.unshift(internal_js_1.ctx);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
(0, lib_js_1.err)(lib_js_1.Errors.IncorrectArguments, expression, "The argument is missing", internal);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
210
|
// two-side binding
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
expression.replaceWith(internal.ref(expression.node));
|
|
248
|
-
}
|
|
211
|
+
const isReactive = (0, lib_js_1.exprCall)(expression, expression.node, internal, { strong: !acceptsRaw }, expression.node);
|
|
212
|
+
if (!isReactive && !acceptsRaw) {
|
|
213
|
+
expression.replaceWith(internal.ref(expression.node, expression.node, undefined));
|
|
249
214
|
}
|
|
250
215
|
}
|
|
251
216
|
else {
|
|
@@ -333,7 +298,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
333
298
|
if (elementPath.isLogicalExpression() &&
|
|
334
299
|
elementPath.node.operator === "&&" &&
|
|
335
300
|
t.isStringLiteral(elementPath.node.right)) {
|
|
336
|
-
(0, lib_js_1.exprCall)(elementPath.get("left"), elementPath.node.left, internal, {});
|
|
301
|
+
(0, lib_js_1.exprCall)(elementPath.get("left"), elementPath.node.left, internal, {}, elementPath.node);
|
|
337
302
|
classObject.push(idToProp(elementPath.node.right, elementPath.node.left));
|
|
338
303
|
}
|
|
339
304
|
// class={[{..}]}
|
|
@@ -345,7 +310,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
345
310
|
const valuePath = propPath.get("value");
|
|
346
311
|
/* istanbul ignore else */
|
|
347
312
|
if (valuePath.isExpression()) {
|
|
348
|
-
(0, lib_js_1.exprCall)(valuePath, valuePath.node, internal, {});
|
|
313
|
+
(0, lib_js_1.exprCall)(valuePath, valuePath.node, internal, {}, elementPath.node);
|
|
349
314
|
}
|
|
350
315
|
if (keyPath.isExpression() && !keyPath.isIdentifier()) {
|
|
351
316
|
(0, mesh_js_1.meshExpression)(keyPath, internal);
|
|
@@ -368,7 +333,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
368
333
|
}
|
|
369
334
|
// class={[..]}
|
|
370
335
|
else {
|
|
371
|
-
(0, lib_js_1.exprCall)(elementPath, elementPath.node, internal, { strong: true });
|
|
336
|
+
(0, lib_js_1.exprCall)(elementPath, elementPath.node, internal, { strong: true }, elementPath.node);
|
|
372
337
|
classElements.push(elementPath.node);
|
|
373
338
|
}
|
|
374
339
|
}
|
|
@@ -384,14 +349,14 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
384
349
|
}
|
|
385
350
|
// class={`a ${b}`}
|
|
386
351
|
else if (expressionPath && expressionPath.isExpression()) {
|
|
387
|
-
if ((0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true })) {
|
|
352
|
+
if ((0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true }, expressionPath.node)) {
|
|
388
353
|
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
389
354
|
}
|
|
390
355
|
attrs.push(t.objectProperty(t.identifier("class"), expressionPath.node));
|
|
391
356
|
}
|
|
392
357
|
// class={name}
|
|
393
358
|
else if (expressionPath && expressionPath.isExpression()) {
|
|
394
|
-
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, {});
|
|
359
|
+
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, {}, expressionPath.node);
|
|
395
360
|
attrs.push(t.objectProperty(t.identifier("class"), expressionPath.node));
|
|
396
361
|
}
|
|
397
362
|
// class="a b"
|
|
@@ -410,7 +375,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
410
375
|
const valuePath = prop.get("value");
|
|
411
376
|
/* istanbul ignore else */
|
|
412
377
|
if (valuePath.isExpression()) {
|
|
413
|
-
(0, lib_js_1.exprCall)(valuePath, valuePath.node, internal, { strong: true });
|
|
378
|
+
(0, lib_js_1.exprCall)(valuePath, valuePath.node, internal, { strong: true }, prop.node);
|
|
414
379
|
}
|
|
415
380
|
const value = valuePath.node;
|
|
416
381
|
const keyPath = propPath.get("key");
|
|
@@ -463,7 +428,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
463
428
|
}
|
|
464
429
|
// style={`a: ${b}px`}
|
|
465
430
|
else if (expressionPath && expressionPath.isExpression()) {
|
|
466
|
-
if ((0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true })) {
|
|
431
|
+
if ((0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true }, expressionPath.node)) {
|
|
467
432
|
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
468
433
|
}
|
|
469
434
|
attrs.push(t.objectProperty(t.identifier("style"), expressionPath.node));
|
|
@@ -476,7 +441,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
476
441
|
else {
|
|
477
442
|
/* istanbul ignore else */
|
|
478
443
|
if (expressionPath && expressionPath.isExpression()) {
|
|
479
|
-
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, {});
|
|
444
|
+
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, {}, expressionPath.node);
|
|
480
445
|
attrs.push(idToProp(name, expressionPath.node));
|
|
481
446
|
}
|
|
482
447
|
else if (t.isStringLiteral(attr.value)) {
|
|
@@ -494,7 +459,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
494
459
|
if (expressionPath) {
|
|
495
460
|
/* istanbul ignore else */
|
|
496
461
|
if (expressionPath.isExpression()) {
|
|
497
|
-
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true });
|
|
462
|
+
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true }, expressionPath.node);
|
|
498
463
|
bind.push(idToProp(name.name, expressionPath.node));
|
|
499
464
|
pushed = true;
|
|
500
465
|
}
|
|
@@ -529,19 +494,20 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
529
494
|
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("tag")), [
|
|
530
495
|
t.stringLiteral(name.name),
|
|
531
496
|
t.objectExpression([
|
|
532
|
-
...(attrs.length > 0 ? [t.objectProperty(t.identifier("
|
|
533
|
-
...(events.length > 0 ? [t.objectProperty(t.identifier("
|
|
534
|
-
...(bind.length > 0 ? [t.objectProperty(t.identifier("
|
|
497
|
+
...(attrs.length > 0 ? [t.objectProperty(t.identifier("a"), t.objectExpression(attrs))] : []),
|
|
498
|
+
...(events.length > 0 ? [t.objectProperty(t.identifier("e"), t.objectExpression(events))] : []),
|
|
499
|
+
...(bind.length > 0 ? [t.objectProperty(t.identifier("b"), t.objectExpression(bind))] : []),
|
|
535
500
|
...(classElements.length > 0 || classObject.length
|
|
536
501
|
? [
|
|
537
|
-
t.objectProperty(t.identifier("
|
|
502
|
+
t.objectProperty(t.identifier("c"), t.arrayExpression([
|
|
538
503
|
...classElements,
|
|
539
504
|
...(classObject.length > 0 ? [t.objectExpression(classObject)] : []),
|
|
540
505
|
])),
|
|
541
506
|
]
|
|
542
507
|
: []),
|
|
543
|
-
...(styleObject.length > 0 ? [t.objectProperty(t.identifier("
|
|
544
|
-
...(callback ? [t.objectProperty(t.identifier("
|
|
508
|
+
...(styleObject.length > 0 ? [t.objectProperty(t.identifier("s"), t.objectExpression(styleObject))] : []),
|
|
509
|
+
...(callback ? [t.objectProperty(t.identifier("k"), callback)] : []),
|
|
510
|
+
...(internal.devLayer ? [t.objectProperty(t.identifier("usage"), (0, transformer_1.nodeToStaticPosition)(path.node))] : []),
|
|
545
511
|
]),
|
|
546
512
|
...(statements.length > 0 ? [t.arrowFunctionExpression([internal_js_1.ctx], t.blockStatement(statements))] : []),
|
|
547
513
|
]);
|
|
@@ -554,9 +520,6 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
554
520
|
const props = [];
|
|
555
521
|
let run;
|
|
556
522
|
const mapped = internal.mapping.get(name.name);
|
|
557
|
-
if (mapped === "Debug" && internal.stack.get(name.name) === undefined && !internal.devMode) {
|
|
558
|
-
return processConditions(conditions, internal);
|
|
559
|
-
}
|
|
560
523
|
for (const attrPath of opening.get("attributes")) {
|
|
561
524
|
const attr = attrPath.node;
|
|
562
525
|
// <A prop=../>
|
|
@@ -566,7 +529,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
566
529
|
// <A prop=".."/>
|
|
567
530
|
/* istanbul ignore else */
|
|
568
531
|
if (t.isStringLiteral(attr.value)) {
|
|
569
|
-
props.push(idToProp(attr.name, needReactive ? internal.ref(attr.value) : attr.value));
|
|
532
|
+
props.push(idToProp(attr.name, needReactive ? internal.ref(attr.value, attr, undefined) : attr.value));
|
|
570
533
|
}
|
|
571
534
|
// <A prop={..}/>
|
|
572
535
|
else if (valuePath && valuePath.isJSXExpressionContainer()) {
|
|
@@ -576,7 +539,7 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
576
539
|
props.push(idToProp(attr.name, value));
|
|
577
540
|
}
|
|
578
541
|
else if (!attr.value) {
|
|
579
|
-
props.push(idToProp(attr.name, needReactive ? internal.ref(t.booleanLiteral(true)) : t.booleanLiteral(true)));
|
|
542
|
+
props.push(idToProp(attr.name, needReactive ? internal.ref(t.booleanLiteral(true), attr, undefined) : t.booleanLiteral(true)));
|
|
580
543
|
}
|
|
581
544
|
}
|
|
582
545
|
// <A {...arg}/>
|
|
@@ -650,7 +613,12 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
650
613
|
}
|
|
651
614
|
return ret;
|
|
652
615
|
}
|
|
653
|
-
const call = t.callExpression(t.identifier(name.name), [
|
|
616
|
+
const call = t.callExpression(t.identifier(name.name), [
|
|
617
|
+
t.objectExpression(props),
|
|
618
|
+
internal_js_1.ctx,
|
|
619
|
+
...(run ? [run] : internal.devLayer ? [t.buildUndefinedNode()] : []),
|
|
620
|
+
...(internal.devLayer ? [(0, transformer_1.nodeToStaticPosition)(path.node)] : []),
|
|
621
|
+
]);
|
|
654
622
|
call.loc = path.node.loc;
|
|
655
623
|
return [...ret, t.expressionStatement(call)];
|
|
656
624
|
}
|
package/lib/lib.js
CHANGED
|
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Errors = void 0;
|
|
37
37
|
exports.err = err;
|
|
38
|
-
exports.named = named;
|
|
39
38
|
exports.processCalculateCall = processCalculateCall;
|
|
40
39
|
exports.parseCalculateCall = parseCalculateCall;
|
|
41
40
|
exports.bindCall = bindCall;
|
|
@@ -52,6 +51,7 @@ const expression_js_1 = require("./expression.js");
|
|
|
52
51
|
const internal_js_1 = require("./internal.js");
|
|
53
52
|
const call_js_1 = require("./call.js");
|
|
54
53
|
const mesh_1 = require("./mesh");
|
|
54
|
+
const transformer_1 = require("./transformer");
|
|
55
55
|
var Errors;
|
|
56
56
|
(function (Errors) {
|
|
57
57
|
Errors[Errors["IncorrectArguments"] = 1] = "IncorrectArguments";
|
|
@@ -72,19 +72,7 @@ function err(e, node, content, internal, ret) {
|
|
|
72
72
|
console.log(error);
|
|
73
73
|
return ret;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
return name[0] === "$" ? name.substring(1) : name;
|
|
77
|
-
}
|
|
78
|
-
function named(call, name, internal, argPos) {
|
|
79
|
-
if (internal.devMode && name) {
|
|
80
|
-
while (argPos && call.arguments.length < argPos) {
|
|
81
|
-
call.arguments.push(t.buildUndefinedNode());
|
|
82
|
-
}
|
|
83
|
-
call.arguments.push(...(typeof name === "string" ? [name] : name.map(item => item)).map(name => t.stringLiteral(unprefixedName(name))));
|
|
84
|
-
}
|
|
85
|
-
return call;
|
|
86
|
-
}
|
|
87
|
-
function processCalculateCall(path, internal) {
|
|
75
|
+
function processCalculateCall(path, internal, area, name) {
|
|
88
76
|
const call = path.node.arguments[0];
|
|
89
77
|
if (path.node.arguments.length !== 1) {
|
|
90
78
|
return err(Errors.IncorrectArguments, path, "Incorrect number of arguments", internal, false);
|
|
@@ -93,32 +81,39 @@ function processCalculateCall(path, internal) {
|
|
|
93
81
|
if (call.params.length > 0) {
|
|
94
82
|
return err(Errors.IncorrectArguments, path.get("arguments")[0], "Argument of calculate cannot have parameters", internal, false);
|
|
95
83
|
}
|
|
96
|
-
const exprData = (0, expression_js_1.checkNode)(path.get("arguments")[0], internal);
|
|
97
|
-
call.params = [...exprData.found.
|
|
84
|
+
const exprData = (0, expression_js_1.checkNode)(path.get("arguments")[0], internal, area, name);
|
|
85
|
+
call.params = [...exprData.found.values()].map(item => item.paramName);
|
|
98
86
|
path.node.arguments.unshift(internal.isComposing ? internal_js_1.ctx : t.nullLiteral());
|
|
99
|
-
path.node.arguments.push(t.arrayExpression([...exprData.found.values()]));
|
|
87
|
+
path.node.arguments.push(t.arrayExpression([...exprData.found.values()].map(item => item.node)));
|
|
88
|
+
if (internal.devLayer) {
|
|
89
|
+
path.node.arguments.push(t.arrayExpression([...exprData.found.keys()].map(name => t.identifier(name))), (0, transformer_1.nodeToStaticPosition)(area), (0, transformer_1.inspectorOf)(internal));
|
|
90
|
+
/* istanbul ignore else */
|
|
91
|
+
if (name) {
|
|
92
|
+
path.replaceWith(internal.shareStateById(path.node, name));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
100
95
|
return true;
|
|
101
96
|
}
|
|
102
97
|
return err(Errors.IncorrectArguments, path, "Argument of calculate must be a function", internal, false);
|
|
103
98
|
}
|
|
104
|
-
function parseCalculateCall(path, internal) {
|
|
99
|
+
function parseCalculateCall(path, internal, area, name) {
|
|
105
100
|
if (path.isCallExpression() && (0, call_js_1.calls)(path, ["calculate", "watch"], internal)) {
|
|
106
|
-
return processCalculateCall(path, internal);
|
|
101
|
+
return processCalculateCall(path, internal, area, name);
|
|
107
102
|
}
|
|
108
103
|
return false;
|
|
109
104
|
}
|
|
110
105
|
function bindCall(path, expr, data, internal, name) {
|
|
111
|
-
const names = [...data.
|
|
112
|
-
const dependencies =
|
|
106
|
+
const names = [...data.values()].map(item => item.paramName);
|
|
107
|
+
const dependencies = [...data.values()].map(item => item.node);
|
|
108
|
+
const codes = [...data.keys()];
|
|
113
109
|
if (names.length > 0 && expr) {
|
|
114
|
-
path.replaceWith(
|
|
110
|
+
path.replaceWith(internal.expr(t.arrowFunctionExpression(names, expr), dependencies, codes, expr, name));
|
|
115
111
|
return true;
|
|
116
112
|
}
|
|
117
113
|
return false;
|
|
118
114
|
}
|
|
119
|
-
function exprCall(path, expr, internal, opts) {
|
|
120
|
-
if (parseCalculateCall(path, internal)) {
|
|
121
|
-
named(path.node, opts.name, internal, 3);
|
|
115
|
+
function exprCall(path, expr, internal, opts, area) {
|
|
116
|
+
if (parseCalculateCall(path, internal, area, opts.name)) {
|
|
122
117
|
return true;
|
|
123
118
|
}
|
|
124
119
|
if (t.isCallExpression(expr) &&
|
|
@@ -126,56 +121,62 @@ function exprCall(path, expr, internal, opts) {
|
|
|
126
121
|
expr.arguments.length === 1 &&
|
|
127
122
|
t.isExpression(expr.arguments[0])) {
|
|
128
123
|
const argPath = path.get("arguments")[0];
|
|
129
|
-
const exprData = (0, expression_js_1.checkNode)(argPath, internal);
|
|
124
|
+
const exprData = (0, expression_js_1.checkNode)(argPath, internal, area, opts.name);
|
|
130
125
|
if (exprData.self) {
|
|
131
|
-
path.replaceWith(
|
|
126
|
+
path.replaceWith(exprData.self);
|
|
132
127
|
}
|
|
133
128
|
else if (exprData.found.size > 0) {
|
|
134
|
-
argPath.replaceWith(t.arrowFunctionExpression([...exprData.found.
|
|
129
|
+
argPath.replaceWith(t.arrowFunctionExpression([...exprData.found.values()].map(item => item.paramName), argPath.node));
|
|
135
130
|
expr.arguments.unshift(internal.isComposing ? internal_js_1.ctx : t.nullLiteral());
|
|
136
|
-
expr.arguments.push(t.arrayExpression([...exprData.found.values()]));
|
|
137
|
-
|
|
131
|
+
expr.arguments.push(t.arrayExpression([...exprData.found.values()].map(item => item.node)));
|
|
132
|
+
if (internal.devLayer) {
|
|
133
|
+
expr.arguments.push(t.arrayExpression([...exprData.found.keys()].map(item => t.stringLiteral(item))), (0, transformer_1.nodeToStaticPosition)(area), (0, transformer_1.inspectorOf)(internal));
|
|
134
|
+
/* istanbul ignore else */
|
|
135
|
+
if (opts.name) {
|
|
136
|
+
path.replaceWith(internal.shareStateById(path.node, opts.name));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
138
139
|
}
|
|
139
140
|
else {
|
|
140
|
-
path.replaceWith(
|
|
141
|
+
path.replaceWith(internal.ref(argPath.node, area, opts.name));
|
|
141
142
|
}
|
|
142
143
|
return true;
|
|
143
144
|
}
|
|
144
|
-
const exprData = (0, expression_js_1.checkNode)(path, internal);
|
|
145
|
+
const exprData = (0, expression_js_1.checkNode)(path, internal, area, opts.name);
|
|
145
146
|
if (exprData.self) {
|
|
146
147
|
if (!opts.strong || (0, expression_js_1.exprIsSure)(path, internal)) {
|
|
147
148
|
path.replaceWith(exprData.self);
|
|
148
149
|
}
|
|
149
150
|
else {
|
|
150
|
-
path.replaceWith(internal.ensure(exprData.self));
|
|
151
|
+
path.replaceWith(internal.ensure(exprData.self, area));
|
|
151
152
|
}
|
|
152
153
|
return true;
|
|
153
154
|
}
|
|
154
155
|
return bindCall(path, expr, exprData.found, internal, opts.name);
|
|
155
156
|
}
|
|
156
|
-
function ref(expr, internal, name) {
|
|
157
|
-
return
|
|
157
|
+
function ref(expr, internal, area, name) {
|
|
158
|
+
return internal.ref(t.isExpression(expr) ? expr : null, area, name);
|
|
158
159
|
}
|
|
159
|
-
function arrayModel(args, internal, name) {
|
|
160
|
-
return
|
|
160
|
+
function arrayModel(args, usage, internal, name) {
|
|
161
|
+
return internal.arrayModel(args[0], usage, name);
|
|
161
162
|
}
|
|
162
|
-
function setModel(args, internal, name) {
|
|
163
|
-
return
|
|
163
|
+
function setModel(args, usage, internal, name) {
|
|
164
|
+
return internal.setModel(args[0], usage, name);
|
|
164
165
|
}
|
|
165
|
-
function mapModel(args, internal, name) {
|
|
166
|
-
return
|
|
166
|
+
function mapModel(args, usage, internal, name) {
|
|
167
|
+
return internal.mapModel(args[0], usage, name);
|
|
167
168
|
}
|
|
168
|
-
function processModelCall(path, type, isConst, internal, name) {
|
|
169
|
+
function processModelCall(path, usage, type, isConst, internal, name) {
|
|
169
170
|
const args = path.node.arguments;
|
|
170
171
|
if (!isConst) {
|
|
171
172
|
err(Errors.RulesOfVasille, path, `${type} models must be declared as constants`, internal);
|
|
172
173
|
}
|
|
173
174
|
(0, mesh_1.meshAllUnknown)(path.get("arguments"), internal);
|
|
174
175
|
path.replaceWith(type === "Map"
|
|
175
|
-
? mapModel(args, internal, name)
|
|
176
|
+
? mapModel(args, usage, internal, name)
|
|
176
177
|
: type === "Set"
|
|
177
|
-
? setModel(args, internal, name)
|
|
178
|
-
: arrayModel(args, internal, name));
|
|
178
|
+
? setModel(args, usage, internal, name)
|
|
179
|
+
: arrayModel(args, usage, internal, name));
|
|
179
180
|
}
|
|
180
181
|
function checkReactiveName(idPath, internal) {
|
|
181
182
|
if (!(idPath.isIdentifier() && idPath.node.name.startsWith("$"))) {
|