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/README.md +5 -4
- package/lib/bridge.js +173 -0
- package/lib/call.js +30 -19
- package/lib/css-transformer.js +4 -4
- package/lib/expression.js +50 -23
- package/lib/jsx.js +20 -6
- package/lib/lib.js +26 -20
- package/lib/mesh.js +182 -50
- package/lib/router.js +41 -0
- package/lib/transformer.js +6 -0
- package/lib/utils.js +50 -0
- package/lib-node/bridge.js +173 -0
- package/lib-node/call.js +30 -19
- package/lib-node/css-transformer.js +4 -4
- package/lib-node/expression.js +50 -23
- package/lib-node/jsx.js +25 -11
- package/lib-node/lib.js +26 -20
- package/lib-node/mesh.js +182 -50
- package/lib-node/router.js +41 -0
- package/lib-node/transformer.js +6 -0
- package/lib-node/utils.js +50 -0
- package/package.json +10 -11
package/lib-node/mesh.js
CHANGED
|
@@ -50,13 +50,37 @@ exports.composeStatements = composeStatements;
|
|
|
50
50
|
exports.composeStatement = composeStatement;
|
|
51
51
|
exports.compose = compose;
|
|
52
52
|
const t = __importStar(require("@babel/types"));
|
|
53
|
+
const bridge_1 = require("./bridge");
|
|
53
54
|
const call_js_1 = require("./call.js");
|
|
54
55
|
const expression_js_1 = require("./expression.js");
|
|
55
56
|
const internal_js_1 = require("./internal.js");
|
|
56
57
|
const jsx_js_1 = require("./jsx.js");
|
|
57
58
|
const lib_js_1 = require("./lib.js");
|
|
59
|
+
const router_1 = require("./router");
|
|
60
|
+
const utils_1 = require("./utils");
|
|
61
|
+
const composePropsIndex = {
|
|
62
|
+
slot: 0,
|
|
63
|
+
compose: 0,
|
|
64
|
+
view: 0,
|
|
65
|
+
mvvmView: 0,
|
|
66
|
+
mvcView: -1,
|
|
67
|
+
hybridView: 1,
|
|
68
|
+
store: 0,
|
|
69
|
+
screen: -1,
|
|
70
|
+
};
|
|
71
|
+
const composeArgsNumber = {
|
|
72
|
+
slot: 1,
|
|
73
|
+
compose: 1,
|
|
74
|
+
view: 1,
|
|
75
|
+
mvvmView: 1,
|
|
76
|
+
mvcView: 1,
|
|
77
|
+
hybridView: 2,
|
|
78
|
+
store: 1,
|
|
79
|
+
screen: 1,
|
|
80
|
+
};
|
|
58
81
|
function meshOrIgnoreAllExpressions(nodePaths, internal) {
|
|
59
82
|
for (const path of nodePaths) {
|
|
83
|
+
/* istanbul ignore else */
|
|
60
84
|
if (t.isExpression(path.node)) {
|
|
61
85
|
meshExpression(path, internal);
|
|
62
86
|
}
|
|
@@ -67,13 +91,16 @@ function meshAllExpressions(nodePaths, internal) {
|
|
|
67
91
|
meshExpression(path, internal);
|
|
68
92
|
}
|
|
69
93
|
}
|
|
70
|
-
function meshComposeCall(call, name, nodePath, internal) {
|
|
94
|
+
function meshComposeCall(call, name, nodePath, method, internal) {
|
|
71
95
|
const arg = call.arguments[0];
|
|
72
96
|
if (call.arguments.length !== 1 || !(t.isFunctionExpression(arg) || t.isArrowFunctionExpression(arg))) {
|
|
73
97
|
throw nodePath.buildCodeFrameError("Vasille: Invalid arguments");
|
|
74
98
|
}
|
|
75
99
|
const fnPath = nodePath.get("arguments")[0];
|
|
76
|
-
compose(fnPath, internal, false);
|
|
100
|
+
const nonePropsFields = compose(fnPath, internal, false, method);
|
|
101
|
+
if (composeArgsNumber[method] > 1) {
|
|
102
|
+
call.arguments.push(t.arrayExpression(nonePropsFields.map(item => t.stringLiteral(item))));
|
|
103
|
+
}
|
|
77
104
|
if (!internal.stateOnly) {
|
|
78
105
|
arg.params.unshift(internal_js_1.ctx);
|
|
79
106
|
}
|
|
@@ -83,6 +110,7 @@ function meshComposeCall(call, name, nodePath, internal) {
|
|
|
83
110
|
}
|
|
84
111
|
function meshAllUnknown(paths, internal) {
|
|
85
112
|
for (const path of paths) {
|
|
113
|
+
/* istanbul ignore else */
|
|
86
114
|
if (t.isSpreadElement(path.node)) {
|
|
87
115
|
meshExpression(path.get("argument"), internal);
|
|
88
116
|
}
|
|
@@ -93,11 +121,13 @@ function meshAllUnknown(paths, internal) {
|
|
|
93
121
|
}
|
|
94
122
|
function meshLValue(path, internal) {
|
|
95
123
|
const node = path.node;
|
|
124
|
+
/* istanbul ignore else */
|
|
96
125
|
if (t.isExpression(node)) {
|
|
97
126
|
meshExpression(path, internal);
|
|
98
127
|
}
|
|
99
128
|
}
|
|
100
129
|
function meshOrIgnoreExpression(path, internal) {
|
|
130
|
+
/* istanbul ignore else */
|
|
101
131
|
if (t.isExpression(path.node)) {
|
|
102
132
|
meshExpression(path, internal);
|
|
103
133
|
}
|
|
@@ -107,8 +137,9 @@ function meshExpression(nodePath, internal, isRoot) {
|
|
|
107
137
|
if (!expr) {
|
|
108
138
|
return;
|
|
109
139
|
}
|
|
110
|
-
|
|
111
|
-
|
|
140
|
+
let composeMethod = (0, call_js_1.calls)(nodePath, ["compose", "store", "view", "mvvmView", "mvcView", "hybridView"], internal);
|
|
141
|
+
if (composeMethod) {
|
|
142
|
+
meshComposeCall(expr, null, nodePath, composeMethod, internal);
|
|
112
143
|
return;
|
|
113
144
|
}
|
|
114
145
|
switch (expr.type) {
|
|
@@ -137,23 +168,26 @@ function meshExpression(nodePath, internal, isRoot) {
|
|
|
137
168
|
case "CallExpression":
|
|
138
169
|
case "OptionalCallExpression": {
|
|
139
170
|
const path = nodePath;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
throw path.buildCodeFrameError(`Vasille: Usage of hint "${callsFn}" is restricted here`);
|
|
144
|
-
}
|
|
145
|
-
if (callsStyleHint) {
|
|
146
|
-
throw path.buildCodeFrameError(`Vasille: Usage of style hint "${callsStyleHint}" is restricted here`);
|
|
147
|
-
}
|
|
148
|
-
meshOrIgnoreExpression(path.get("callee"), internal);
|
|
149
|
-
meshAllUnknown(path.get("arguments"), internal);
|
|
150
|
-
if ((0, call_js_1.calls)(path.node, ["calculate"], internal)) {
|
|
151
|
-
if (path.node.arguments.length === 1 &&
|
|
152
|
-
(t.isFunctionExpression(path.node.arguments[0]) || t.isArrowFunctionExpression(path.node.arguments[0]))) {
|
|
153
|
-
path.replaceWith(t.callExpression(path.node.arguments[0], []));
|
|
171
|
+
if (internal.isComposing && (0, call_js_1.calls)(path, ["router"], internal)) {
|
|
172
|
+
if (!internal.stateOnly) {
|
|
173
|
+
(0, router_1.routerReplace)(path);
|
|
154
174
|
}
|
|
155
175
|
else {
|
|
156
|
-
throw path.buildCodeFrameError("Vasille:
|
|
176
|
+
throw path.buildCodeFrameError("Vasille: The router is not available in stores");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const callsFn = (0, call_js_1.calls)(path, call_js_1.composeOnly, internal);
|
|
181
|
+
const callsStyleHint = (0, call_js_1.calls)(path, call_js_1.styleOnly, internal);
|
|
182
|
+
if (callsFn) {
|
|
183
|
+
throw path.buildCodeFrameError(`Vasille: Usage of hint "${callsFn}" is restricted here`);
|
|
184
|
+
}
|
|
185
|
+
if (callsStyleHint) {
|
|
186
|
+
throw path.buildCodeFrameError(`Vasille: Usage of style hint "${callsStyleHint}" is restricted here`);
|
|
187
|
+
}
|
|
188
|
+
if (!(0, bridge_1.processBridgeCall)(path, internal)) {
|
|
189
|
+
meshOrIgnoreExpression(path.get("callee"), internal);
|
|
190
|
+
meshAllUnknown(path.get("arguments"), internal);
|
|
157
191
|
}
|
|
158
192
|
}
|
|
159
193
|
break;
|
|
@@ -269,12 +303,12 @@ function meshExpression(nodePath, internal, isRoot) {
|
|
|
269
303
|
let replaced = false;
|
|
270
304
|
if (isRoot &&
|
|
271
305
|
internal.stateOnly &&
|
|
272
|
-
!path.node.computed &&
|
|
273
|
-
t.isIdentifier(path.node.key) &&
|
|
306
|
+
(!path.node.computed || t.isStringLiteral(path.node.key)) &&
|
|
307
|
+
(t.isIdentifier(path.node.key) || t.isStringLiteral(path.node.key)) &&
|
|
274
308
|
t.isExpression(valuePath.node)) {
|
|
275
309
|
const call = (0, lib_js_1.exprCall)(valuePath, valuePath.node, internal);
|
|
276
310
|
if (call) {
|
|
277
|
-
if (path.node.key.
|
|
311
|
+
if ((0, utils_1.stringify)(path.node.key).startsWith("$")) {
|
|
278
312
|
valuePath.replaceWith(call);
|
|
279
313
|
}
|
|
280
314
|
else {
|
|
@@ -283,9 +317,13 @@ function meshExpression(nodePath, internal, isRoot) {
|
|
|
283
317
|
replaced = true;
|
|
284
318
|
}
|
|
285
319
|
else if (t.isIdentifier(valuePath.node) &&
|
|
286
|
-
internal.stack.get(valuePath.node.name) === 3 /* VariableState.ReactiveObject */
|
|
287
|
-
!path.node.key.
|
|
288
|
-
|
|
320
|
+
internal.stack.get(valuePath.node.name) === 3 /* VariableState.ReactiveObject */) {
|
|
321
|
+
if (!(0, utils_1.stringify)(path.node.key).startsWith("$$")) {
|
|
322
|
+
throw path.buildCodeFrameError("Vasille: Reactive object property name must start with $$");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if ((0, utils_1.stringify)(path.node.key).startsWith("$")) {
|
|
326
|
+
throw path.buildCodeFrameError("Vasille: This property is not a reactive value or object");
|
|
289
327
|
}
|
|
290
328
|
}
|
|
291
329
|
if (!replaced) {
|
|
@@ -293,6 +331,9 @@ function meshExpression(nodePath, internal, isRoot) {
|
|
|
293
331
|
}
|
|
294
332
|
}
|
|
295
333
|
else if (t.isObjectMethod(prop)) {
|
|
334
|
+
if ((0, utils_1.stringify)(prop.key).startsWith("$")) {
|
|
335
|
+
throw propPath.buildCodeFrameError("Vasille: Method name stating with $ is not allowed");
|
|
336
|
+
}
|
|
296
337
|
meshFunction(propPath, internal);
|
|
297
338
|
}
|
|
298
339
|
else if (isRoot && internal.stateOnly && t.isSpreadElement(prop)) {
|
|
@@ -330,9 +371,11 @@ function meshStatements(paths, internal) {
|
|
|
330
371
|
}
|
|
331
372
|
}
|
|
332
373
|
function ignoreParams(val, internal) {
|
|
374
|
+
/* istanbul ignore else */
|
|
333
375
|
if (t.isAssignmentPattern(val)) {
|
|
334
376
|
val = val.left;
|
|
335
377
|
}
|
|
378
|
+
/* istanbul ignore else */
|
|
336
379
|
if (t.isIdentifier(val)) {
|
|
337
380
|
internal.stack.set(val.name, 1 /* VariableState.Ignored */);
|
|
338
381
|
}
|
|
@@ -349,7 +392,9 @@ function ignoreParams(val, internal) {
|
|
|
349
392
|
}
|
|
350
393
|
function ignoreObjectPattern(pattern, internal) {
|
|
351
394
|
for (const property of pattern.properties) {
|
|
395
|
+
/* istanbul ignore else */
|
|
352
396
|
if (t.isObjectProperty(property)) {
|
|
397
|
+
/* istanbul ignore else */
|
|
353
398
|
if (t.isObjectPattern(property.value)) {
|
|
354
399
|
ignoreObjectPattern(property.value, internal);
|
|
355
400
|
}
|
|
@@ -360,6 +405,7 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
360
405
|
internal.stack.set(property.value.name, 1 /* VariableState.Ignored */);
|
|
361
406
|
}
|
|
362
407
|
}
|
|
408
|
+
/* istanbul ignore else */
|
|
363
409
|
if (t.isRestElement(property)) {
|
|
364
410
|
internal.stack.set(property.argument.name, 1 /* VariableState.Ignored */);
|
|
365
411
|
}
|
|
@@ -368,6 +414,7 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
368
414
|
function reactiveArrayPattern(path, internal) {
|
|
369
415
|
if (t.isArrayPattern(path.node)) {
|
|
370
416
|
path.node.elements.forEach((element, index) => {
|
|
417
|
+
/* istanbul ignore else */
|
|
371
418
|
if (t.isIdentifier(element)) {
|
|
372
419
|
internal.stack.set(element.name, index < 2 ? 2 /* VariableState.Reactive */ : 1 /* VariableState.Ignored */);
|
|
373
420
|
}
|
|
@@ -380,12 +427,14 @@ function reactiveArrayPattern(path, internal) {
|
|
|
380
427
|
function meshForEachHeader(path, internal) {
|
|
381
428
|
const left = path.node.left;
|
|
382
429
|
meshExpression(path.get("right"), internal);
|
|
430
|
+
/* istanbul ignore else */
|
|
383
431
|
if (t.isVariableDeclaration(left) && t.isVariableDeclarator(left.declarations[0])) {
|
|
384
432
|
ignoreParams(left.declarations[0].id, internal);
|
|
385
433
|
}
|
|
386
434
|
}
|
|
387
435
|
function meshForHeader(path, internal) {
|
|
388
436
|
const node = path.node;
|
|
437
|
+
/* istanbul ignore else */
|
|
389
438
|
if (node.init) {
|
|
390
439
|
if (t.isExpression(node.init)) {
|
|
391
440
|
meshExpression(path.get("init"), internal);
|
|
@@ -403,9 +452,15 @@ function meshForHeader(path, internal) {
|
|
|
403
452
|
}
|
|
404
453
|
function meshClassBody(path, internal) {
|
|
405
454
|
for (const item of path.get("body")) {
|
|
455
|
+
/* istanbul ignore else */
|
|
406
456
|
if (t.isClassMethod(item.node) || t.isClassPrivateMethod(item.node)) {
|
|
407
457
|
meshFunction(item, internal);
|
|
408
458
|
}
|
|
459
|
+
else if (t.isClassAccessorProperty(item.node) ||
|
|
460
|
+
t.isClassPrivateProperty(item.node) ||
|
|
461
|
+
t.isClassProperty(item.node)) {
|
|
462
|
+
meshExpression(item.get("value"), internal);
|
|
463
|
+
}
|
|
409
464
|
}
|
|
410
465
|
}
|
|
411
466
|
function meshStatement(path, internal) {
|
|
@@ -487,6 +542,7 @@ function meshStatement(path, internal) {
|
|
|
487
542
|
break;
|
|
488
543
|
case "TryStatement":
|
|
489
544
|
meshStatement(path.get("block"), internal);
|
|
545
|
+
/* istanbul ignore else */
|
|
490
546
|
if (path.node.handler) {
|
|
491
547
|
meshStatement(path.get("handler").get("body"), internal);
|
|
492
548
|
}
|
|
@@ -496,8 +552,10 @@ function meshStatement(path, internal) {
|
|
|
496
552
|
const _path = path;
|
|
497
553
|
for (const declaration of _path.get("declarations")) {
|
|
498
554
|
const expr = declaration.node.init;
|
|
499
|
-
|
|
500
|
-
|
|
555
|
+
const initPath = declaration.get("init");
|
|
556
|
+
const composeMethod = (0, call_js_1.calls)(initPath, ["compose", "store", "view", "mvvmView", "mvcView", "hybridView", "screen"], internal);
|
|
557
|
+
if (expr && t.isIdentifier(declaration.node.id) && composeMethod) {
|
|
558
|
+
meshComposeCall(expr, declaration.node.id, declaration.get("init"), composeMethod, internal);
|
|
501
559
|
}
|
|
502
560
|
else {
|
|
503
561
|
meshExpression(declaration.get("init"), internal);
|
|
@@ -523,6 +581,7 @@ function meshStatement(path, internal) {
|
|
|
523
581
|
break;
|
|
524
582
|
case "ExportDefaultDeclaration": {
|
|
525
583
|
const declarationPath = path.get("declaration");
|
|
584
|
+
/* istanbul ignore else */
|
|
526
585
|
if (t.isExpression(declarationPath.node)) {
|
|
527
586
|
meshExpression(declarationPath, internal);
|
|
528
587
|
}
|
|
@@ -565,18 +624,26 @@ function composeExpression(path, internal, isRoot) {
|
|
|
565
624
|
}
|
|
566
625
|
case "CallExpression":
|
|
567
626
|
case "OptionalCallExpression": {
|
|
568
|
-
|
|
569
|
-
if ((0, call_js_1.calls)(call, ["watch"], internal)) {
|
|
627
|
+
if ((0, call_js_1.calls)(path, ["watch"], internal)) {
|
|
570
628
|
const args = (0, lib_js_1.parseCalculateCall)(path, internal);
|
|
629
|
+
/* istanbul ignore else */
|
|
571
630
|
if (args) {
|
|
572
631
|
if (args[1].elements.length > 0) {
|
|
573
|
-
path.replaceWith(t.callExpression(
|
|
632
|
+
path.replaceWith(t.callExpression(internal.stateOnly
|
|
633
|
+
? t.memberExpression(internal.id, t.identifier("ex"))
|
|
634
|
+
: t.memberExpression(internal_js_1.ctx, t.identifier("watch")), args));
|
|
574
635
|
}
|
|
575
636
|
else {
|
|
576
637
|
path.replaceWith(t.callExpression(args[0], []));
|
|
577
638
|
}
|
|
578
639
|
}
|
|
579
640
|
}
|
|
641
|
+
else if ((0, call_js_1.calls)(path, ["runOnDestroy"], internal)) {
|
|
642
|
+
if (internal.stateOnly) {
|
|
643
|
+
throw path.buildCodeFrameError("Vasille: Stores in Vasille.JS are not destroyable");
|
|
644
|
+
}
|
|
645
|
+
path.get("callee").replaceWith(t.memberExpression(internal_js_1.ctx, t.identifier("runOnDestroy")));
|
|
646
|
+
}
|
|
580
647
|
else {
|
|
581
648
|
meshExpression(path, internal);
|
|
582
649
|
}
|
|
@@ -689,14 +756,14 @@ function composeStatement(path, internal, isRoot) {
|
|
|
689
756
|
const _path = path;
|
|
690
757
|
const kind = _path.node.kind;
|
|
691
758
|
const declares = kind === "const" ? 1 /* VariableState.Ignored */ : 2 /* VariableState.Reactive */;
|
|
692
|
-
|
|
693
|
-
_path.node.kind = "const";
|
|
694
|
-
}
|
|
759
|
+
let switchToConst = true;
|
|
695
760
|
for (const declaration of _path.get("declarations")) {
|
|
696
761
|
const id = declaration.node.id;
|
|
762
|
+
const bridgeMethod = (0, bridge_1.processBridgeCall)(declaration.get("init"), internal);
|
|
697
763
|
let meshInit = true;
|
|
698
764
|
function idName(target = id) {
|
|
699
765
|
let name = "#";
|
|
766
|
+
/* istanbul ignore else */
|
|
700
767
|
if (t.isIdentifier(target)) {
|
|
701
768
|
name = target.name;
|
|
702
769
|
}
|
|
@@ -707,7 +774,18 @@ function composeStatement(path, internal, isRoot) {
|
|
|
707
774
|
return [idName(pattern.elements[0]), idName(pattern.elements[1])];
|
|
708
775
|
}
|
|
709
776
|
ignoreParams(declaration.node.id, internal);
|
|
710
|
-
|
|
777
|
+
/* istanbul ignore else */
|
|
778
|
+
if (bridgeMethod === "value" && declares === 2 /* VariableState.Reactive */ && t.isIdentifier(declaration.node.id)) {
|
|
779
|
+
switchToConst = true;
|
|
780
|
+
meshInit = false;
|
|
781
|
+
internal.stack.set(declaration.node.id.name, 2 /* VariableState.Reactive */);
|
|
782
|
+
declaration.get("init").replaceWith((0, lib_js_1.ref)(declaration.node.init, internal, declaration.node.id.name));
|
|
783
|
+
}
|
|
784
|
+
else if (bridgeMethod) {
|
|
785
|
+
switchToConst = false;
|
|
786
|
+
meshInit = false;
|
|
787
|
+
}
|
|
788
|
+
else if ((0, call_js_1.calls)(declaration.get("init"), ["awaited"], internal)) {
|
|
711
789
|
reactiveArrayPattern(declaration.get("id"), internal);
|
|
712
790
|
meshAllUnknown(declaration.get("init").get("arguments"), internal);
|
|
713
791
|
(0, lib_js_1.named)(declaration.node.init, idDoubleName(), internal);
|
|
@@ -716,12 +794,15 @@ function composeStatement(path, internal, isRoot) {
|
|
|
716
794
|
else if (t.isIdentifier(id)) {
|
|
717
795
|
internal.stack.set(id.name, declares);
|
|
718
796
|
const init = declaration.node.init;
|
|
719
|
-
|
|
797
|
+
const initPath = declaration.get("init");
|
|
798
|
+
let callName = false;
|
|
799
|
+
if ((0, call_js_1.calls)(initPath, ["value"], internal)) {
|
|
720
800
|
internal.stack.set(id.name, 1 /* VariableState.Ignored */);
|
|
721
801
|
declaration.get("init").replaceWith(init.arguments[0]);
|
|
722
802
|
_path.node.kind = kind;
|
|
803
|
+
switchToConst = false;
|
|
723
804
|
}
|
|
724
|
-
else if ((0, call_js_1.calls)(
|
|
805
|
+
else if ((0, call_js_1.calls)(initPath, ["bind"], internal)) {
|
|
725
806
|
const argument = init.arguments[0];
|
|
726
807
|
const argumentPath = declaration.get("init").get("arguments")[0];
|
|
727
808
|
let replaceWith = declares === 2 /* VariableState.Reactive */
|
|
@@ -743,12 +824,12 @@ function composeStatement(path, internal, isRoot) {
|
|
|
743
824
|
declaration.get("init").replaceWith(replaceWith);
|
|
744
825
|
meshInit = !replaceWith;
|
|
745
826
|
}
|
|
746
|
-
else if ((0, call_js_1.calls)(
|
|
827
|
+
else if ((0, call_js_1.calls)(initPath, ["ref"], internal)) {
|
|
747
828
|
const argument = init.arguments[0];
|
|
748
829
|
internal.stack.set(id.name, 2 /* VariableState.Reactive */);
|
|
749
830
|
declaration.get("init").replaceWith((0, lib_js_1.ref)(t.isExpression(argument) ? argument : null, internal, idName()));
|
|
750
831
|
}
|
|
751
|
-
else if ((0, call_js_1.calls)(
|
|
832
|
+
else if ((0, call_js_1.calls)(initPath, ["reactiveObject"], internal)) {
|
|
752
833
|
const value = init.arguments[0];
|
|
753
834
|
if (kind !== "const") {
|
|
754
835
|
throw declaration.buildCodeFrameError(`Vasille: Reactive objects must be must be declared as constants`);
|
|
@@ -761,7 +842,7 @@ function composeStatement(path, internal, isRoot) {
|
|
|
761
842
|
throw declaration.buildCodeFrameError(`Vasille: reactiveObject requires object expression as argument`);
|
|
762
843
|
}
|
|
763
844
|
}
|
|
764
|
-
else if ((0, call_js_1.calls)(
|
|
845
|
+
else if ((0, call_js_1.calls)(initPath, ["arrayModel"], internal)) {
|
|
765
846
|
const value = init.arguments[0];
|
|
766
847
|
if (kind !== "const") {
|
|
767
848
|
throw declaration.buildCodeFrameError(`Vasille: Array models must be must be declared as constants`);
|
|
@@ -773,15 +854,14 @@ function composeStatement(path, internal, isRoot) {
|
|
|
773
854
|
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(null, internal, idName()));
|
|
774
855
|
}
|
|
775
856
|
}
|
|
776
|
-
else if ((0, call_js_1.calls)(
|
|
857
|
+
else if ((callName = (0, call_js_1.calls)(initPath, ["mapModel", "setModel"], internal))) {
|
|
777
858
|
const args = init.arguments;
|
|
778
|
-
const name = (0, call_js_1.calls)(init, ["mapModel", "setModel"], internal);
|
|
779
859
|
if (kind !== "const") {
|
|
780
|
-
throw declaration.buildCodeFrameError(`Vasille: ${
|
|
860
|
+
throw declaration.buildCodeFrameError(`Vasille: ${callName === "mapModel" ? "Map" : "Set"} models must be declared as constants`);
|
|
781
861
|
}
|
|
782
862
|
declaration
|
|
783
863
|
.get("init")
|
|
784
|
-
.replaceWith(
|
|
864
|
+
.replaceWith(callName === "mapModel" ? (0, lib_js_1.mapModel)(args, internal, idName()) : (0, lib_js_1.setModel)(args, internal, idName()));
|
|
785
865
|
}
|
|
786
866
|
else if (t.isObjectExpression(init)) {
|
|
787
867
|
if (kind !== "const") {
|
|
@@ -829,10 +909,24 @@ function composeStatement(path, internal, isRoot) {
|
|
|
829
909
|
meshInit = !replaceWith;
|
|
830
910
|
}
|
|
831
911
|
}
|
|
912
|
+
else if (t.isObjectPattern(id)) {
|
|
913
|
+
for (const prop of id.properties) {
|
|
914
|
+
/* istanbul ignore else */
|
|
915
|
+
if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
|
|
916
|
+
internal.stack.set(prop.value.name, 2 /* VariableState.Reactive */);
|
|
917
|
+
}
|
|
918
|
+
else if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
|
|
919
|
+
internal.stack.set(prop.argument.name, 3 /* VariableState.ReactiveObject */);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
832
923
|
if (meshInit) {
|
|
833
924
|
meshExpression(declaration.get("init"), internal);
|
|
834
925
|
}
|
|
835
926
|
}
|
|
927
|
+
if (switchToConst && (kind === "let" || kind === "var")) {
|
|
928
|
+
_path.node.kind = "const";
|
|
929
|
+
}
|
|
836
930
|
break;
|
|
837
931
|
}
|
|
838
932
|
case "WhileStatement": {
|
|
@@ -855,26 +949,50 @@ function composeStatement(path, internal, isRoot) {
|
|
|
855
949
|
meshStatement(path, internal);
|
|
856
950
|
}
|
|
857
951
|
}
|
|
858
|
-
function compose(path, internal, isInternalSlot) {
|
|
952
|
+
function compose(path, internal, isInternalSlot, composeMethod) {
|
|
859
953
|
internal.stack.push();
|
|
860
954
|
const node = path.node;
|
|
861
955
|
const params = node.params;
|
|
862
956
|
const body = node.body;
|
|
957
|
+
const argsNumber = composeArgsNumber[composeMethod];
|
|
863
958
|
if (t.isFunctionExpression(node) && node.id) {
|
|
864
959
|
internal.stack.set(node.id.name, 1 /* VariableState.Ignored */);
|
|
865
960
|
}
|
|
866
|
-
if (params.length >
|
|
867
|
-
throw path.get("params")[
|
|
961
|
+
if (params.length > argsNumber && !isInternalSlot) {
|
|
962
|
+
throw path.get("params")[argsNumber].buildCodeFrameError("Vasille: Extra parameters are not allowed");
|
|
868
963
|
}
|
|
964
|
+
const cumulativeFields = new Set();
|
|
965
|
+
const nonPropsFields = [];
|
|
966
|
+
let index = 0;
|
|
869
967
|
for (const param of path.get("params")) {
|
|
870
968
|
const node = param.node;
|
|
969
|
+
const isProps = index === composePropsIndex[composeMethod];
|
|
871
970
|
if (t.isAssignmentPattern(node)) {
|
|
872
971
|
throw param.buildCodeFrameError("Vasille: No default value allowed here");
|
|
873
972
|
}
|
|
874
|
-
if (
|
|
875
|
-
|
|
973
|
+
if (argsNumber !== 1) {
|
|
974
|
+
if (t.isObjectPattern(node)) {
|
|
975
|
+
for (const prop of node.properties) {
|
|
976
|
+
if (t.isObjectProperty(prop)) {
|
|
977
|
+
const name = (0, utils_1.stringify)(prop.key);
|
|
978
|
+
if (cumulativeFields.has(name)) {
|
|
979
|
+
throw param.buildCodeFrameError(`Vasille: Field "${name}" is defined twice`);
|
|
980
|
+
}
|
|
981
|
+
cumulativeFields.add(name);
|
|
982
|
+
if (!isProps) {
|
|
983
|
+
nonPropsFields.push(name);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
else {
|
|
987
|
+
throw param.buildCodeFrameError("Vasille: Rest element is not supported here");
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
876
991
|
}
|
|
877
|
-
|
|
992
|
+
if (t.isIdentifier(node) && argsNumber === 1) {
|
|
993
|
+
internal.stack.set(node.name, isInternalSlot || !isProps ? 1 /* VariableState.Ignored */ : 3 /* VariableState.ReactiveObject */);
|
|
994
|
+
}
|
|
995
|
+
else if ((isInternalSlot || !isProps) && t.isObjectPattern(node)) {
|
|
878
996
|
ignoreObjectPattern(node, internal);
|
|
879
997
|
}
|
|
880
998
|
else if (t.isObjectPattern(node)) {
|
|
@@ -883,6 +1001,7 @@ function compose(path, internal, isInternalSlot) {
|
|
|
883
1001
|
if (t.isObjectProperty(node)) {
|
|
884
1002
|
const key = node.key;
|
|
885
1003
|
let keyName = "";
|
|
1004
|
+
/* istanbul ignore else */
|
|
886
1005
|
if (t.isIdentifier(node.value)) {
|
|
887
1006
|
keyName = node.value.name;
|
|
888
1007
|
}
|
|
@@ -906,14 +1025,27 @@ function compose(path, internal, isInternalSlot) {
|
|
|
906
1025
|
}
|
|
907
1026
|
}
|
|
908
1027
|
else {
|
|
909
|
-
throw param.buildCodeFrameError("Vasille: Expected identifier or object pattern");
|
|
1028
|
+
throw param.buildCodeFrameError(argsNumber === 1 ? "Vasille: Expected identifier or object pattern" : "Vasille: Expected object pattern here");
|
|
910
1029
|
}
|
|
1030
|
+
index++;
|
|
1031
|
+
}
|
|
1032
|
+
if (argsNumber !== 1) {
|
|
1033
|
+
node.params = [
|
|
1034
|
+
t.objectPattern([
|
|
1035
|
+
...params[0].properties,
|
|
1036
|
+
...params[1].properties,
|
|
1037
|
+
]),
|
|
1038
|
+
];
|
|
911
1039
|
}
|
|
1040
|
+
internal.isComposing = true;
|
|
1041
|
+
/* istanbul ignore else */
|
|
912
1042
|
if (t.isExpression(body)) {
|
|
913
1043
|
composeExpression(path.get("body"), internal, true);
|
|
914
1044
|
}
|
|
915
1045
|
else if (t.isBlockStatement(body)) {
|
|
916
1046
|
composeStatement(path.get("body"), internal, true);
|
|
917
1047
|
}
|
|
1048
|
+
internal.isComposing = false;
|
|
918
1049
|
internal.stack.pop();
|
|
1050
|
+
return nonPropsFields;
|
|
919
1051
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 () {
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.routerReplace = routerReplace;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
const internal_1 = require("./internal");
|
|
39
|
+
function routerReplace(path) {
|
|
40
|
+
path.replaceWith(t.memberExpression(t.memberExpression(internal_1.ctx, t.identifier("runner")), t.identifier("router")));
|
|
41
|
+
}
|
package/lib-node/transformer.js
CHANGED
|
@@ -57,6 +57,9 @@ const ignoreMembers = new Set([
|
|
|
57
57
|
"laptop",
|
|
58
58
|
"prefersDark",
|
|
59
59
|
"prefersLight",
|
|
60
|
+
"bridge",
|
|
61
|
+
"router",
|
|
62
|
+
"runOnDestroy",
|
|
60
63
|
]);
|
|
61
64
|
function extractText(node) {
|
|
62
65
|
// no case found for string literal
|
|
@@ -89,8 +92,10 @@ function trProgram(path, devMode) {
|
|
|
89
92
|
if (name) {
|
|
90
93
|
internal.prefix = name;
|
|
91
94
|
for (const specifier of statement.specifiers) {
|
|
95
|
+
/* istanbul ignore else */
|
|
92
96
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
|
93
97
|
internal.global = specifier.local.name;
|
|
98
|
+
/* istanbul ignore else */
|
|
94
99
|
if (statement.source.value === "vasille-web") {
|
|
95
100
|
stylesConnected = true;
|
|
96
101
|
}
|
|
@@ -134,6 +139,7 @@ function trProgram(path, devMode) {
|
|
|
134
139
|
const statement = statementPath.node;
|
|
135
140
|
statementPath.replaceWith(t.importDeclaration([
|
|
136
141
|
...statement.specifiers.filter(item => {
|
|
142
|
+
/* istanbul ignore else */
|
|
137
143
|
if (t.isImportSpecifier(item) && t.isIdentifier(item.local)) {
|
|
138
144
|
return statementPath.scope.bindings[item.local.name].referenced;
|
|
139
145
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 () {
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.stringify = stringify;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
function stringify(node) {
|
|
39
|
+
let name = "";
|
|
40
|
+
if (t.isStringLiteral(node)) {
|
|
41
|
+
name = node.value;
|
|
42
|
+
}
|
|
43
|
+
if (t.isPrivateName(node)) {
|
|
44
|
+
name = node.id.name;
|
|
45
|
+
}
|
|
46
|
+
if (t.isIdentifier(node)) {
|
|
47
|
+
name = node.name;
|
|
48
|
+
}
|
|
49
|
+
return name;
|
|
50
|
+
}
|