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/mesh.js
CHANGED
|
@@ -59,6 +59,7 @@ const lib_js_1 = require("./lib.js");
|
|
|
59
59
|
const order_check_1 = require("./order-check");
|
|
60
60
|
const router_1 = require("./router");
|
|
61
61
|
const utils_1 = require("./utils");
|
|
62
|
+
const transformer_1 = require("./transformer");
|
|
62
63
|
function meshOrIgnoreAllExpressions(nodePaths, internal) {
|
|
63
64
|
for (const path of nodePaths) {
|
|
64
65
|
/* istanbul ignore else */
|
|
@@ -80,8 +81,8 @@ function meshComposeCall(name, path, internal) {
|
|
|
80
81
|
}
|
|
81
82
|
compose(arg, internal, false, false);
|
|
82
83
|
arg.node.params.unshift(internal_js_1.ctx);
|
|
83
|
-
if (internal.
|
|
84
|
-
path.node.arguments.push(t.stringLiteral(name ? name : "#"));
|
|
84
|
+
if (internal.devLayer && path.isCallExpression()) {
|
|
85
|
+
path.node.arguments.push((0, transformer_1.nodeToStaticPosition)(path.node), t.stringLiteral(name ? name : "#"));
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
function meshAllUnknown(paths, internal) {
|
|
@@ -166,7 +167,18 @@ function meshExpression(nodePath, internal) {
|
|
|
166
167
|
if (argPath) {
|
|
167
168
|
meshAllUnknown([argPath], internal);
|
|
168
169
|
}
|
|
169
|
-
path.node.
|
|
170
|
+
const loc = path.node.loc;
|
|
171
|
+
/* istanbul ignore else */
|
|
172
|
+
if ((0, call_js_1.calls)(path, ["arrayModel"], internal)) {
|
|
173
|
+
path.replaceWith(internal.arrayModel(argPath?.node, path.node, undefined));
|
|
174
|
+
}
|
|
175
|
+
else if ((0, call_js_1.calls)(path, ["mapModel"], internal)) {
|
|
176
|
+
path.replaceWith(internal.mapModel(argPath?.node, path.node, undefined));
|
|
177
|
+
}
|
|
178
|
+
else if ((0, call_js_1.calls)(path, ["setModel"], internal)) {
|
|
179
|
+
path.replaceWith(internal.setModel(argPath?.node, path.node, undefined));
|
|
180
|
+
}
|
|
181
|
+
path.node.loc = loc;
|
|
170
182
|
}
|
|
171
183
|
// router call
|
|
172
184
|
else if (internal.isComposing && (0, call_js_1.calls)(path, ["router"], internal)) {
|
|
@@ -179,7 +191,7 @@ function meshExpression(nodePath, internal) {
|
|
|
179
191
|
}
|
|
180
192
|
// watch call
|
|
181
193
|
else if ((0, call_js_1.calls)(path, ["watch"], internal)) {
|
|
182
|
-
(0, lib_js_1.processCalculateCall)(path, internal);
|
|
194
|
+
(0, lib_js_1.processCalculateCall)(path, internal, path.node, undefined);
|
|
183
195
|
}
|
|
184
196
|
else if (path.isCallExpression() &&
|
|
185
197
|
t.isIdentifier(path.node.callee) &&
|
|
@@ -189,7 +201,14 @@ function meshExpression(nodePath, internal) {
|
|
|
189
201
|
}
|
|
190
202
|
path.node.arguments.unshift(internal_js_1.ctx);
|
|
191
203
|
}
|
|
192
|
-
//
|
|
204
|
+
// dependency injection
|
|
205
|
+
else if (internal.isComposing &&
|
|
206
|
+
!internal.stateOnly &&
|
|
207
|
+
(0, call_js_1.calls)(path, call_js_1.dependencyInjections, internal) &&
|
|
208
|
+
path.node.arguments[0] === internal_js_1.ctx) {
|
|
209
|
+
meshAllUnknown(path.get("arguments"), internal);
|
|
210
|
+
}
|
|
211
|
+
// call any other functions invalid if code calls a hint
|
|
193
212
|
else {
|
|
194
213
|
if ((0, call_js_1.calls)(path, call_js_1.hintFunctions, internal)) {
|
|
195
214
|
(0, lib_js_1.err)(lib_js_1.Errors.IncompatibleContext, path, `Usage of hints is restricted here`, internal);
|
|
@@ -222,10 +241,15 @@ function meshExpression(nodePath, internal) {
|
|
|
222
241
|
meshExpression(right, internal);
|
|
223
242
|
/* istanbul ignore else */
|
|
224
243
|
if (!t.isPrivateName(property)) {
|
|
225
|
-
(
|
|
244
|
+
path.replaceWith(internal.set(left.node.object, !left.node.computed && t.isIdentifier(property) ? t.stringLiteral(property.name) : property, right.node, path.node));
|
|
226
245
|
}
|
|
227
246
|
}
|
|
228
247
|
}
|
|
248
|
+
else if (internal.devLayer &&
|
|
249
|
+
((left.isIdentifier() && (0, expression_js_1.idIsIValue)(left)) || (left.isMemberExpression() && (0, expression_js_1.memberIsIValue)(left.node)))) {
|
|
250
|
+
meshExpression(right, internal);
|
|
251
|
+
path.replaceWith(internal.updateIValue(path.node, left.node, right.node));
|
|
252
|
+
}
|
|
229
253
|
else {
|
|
230
254
|
meshLValue(left, internal);
|
|
231
255
|
meshExpression(right, internal);
|
|
@@ -426,11 +450,11 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
426
450
|
ignoreParams(valuePath.get("left"), internal, ["id"]);
|
|
427
451
|
meshExpression(right, internal);
|
|
428
452
|
if (property.computed && t.isIdentifier(property.key)) {
|
|
429
|
-
right.replaceWith(internal.match(t.stringLiteral(property.key.name), right.node));
|
|
453
|
+
right.replaceWith(internal.match(t.stringLiteral(property.key.name), right.node, property));
|
|
430
454
|
}
|
|
431
455
|
else if ((t.isIdentifier(property.key) && property.key.name.startsWith("$")) ||
|
|
432
456
|
(t.isStringLiteral(property.key) && property.key.value.startsWith("$"))) {
|
|
433
|
-
right.replaceWith(internal.ref(right.node));
|
|
457
|
+
right.replaceWith(internal.ref(right.node, property, undefined));
|
|
434
458
|
}
|
|
435
459
|
}
|
|
436
460
|
else if (t.isIdentifier(property.value)) {
|
|
@@ -438,10 +462,10 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
438
462
|
if (property.computed) {
|
|
439
463
|
path
|
|
440
464
|
.get("value")
|
|
441
|
-
.replaceWith(t.assignmentPattern(property.value, internal.match(t.stringLiteral(property.value.name))));
|
|
465
|
+
.replaceWith(t.assignmentPattern(property.value, internal.match(t.stringLiteral(property.value.name), null, property)));
|
|
442
466
|
}
|
|
443
467
|
else if (property.value.name.startsWith("$")) {
|
|
444
|
-
path.get("value").replaceWith(t.assignmentPattern(property.value, internal.ref()));
|
|
468
|
+
path.get("value").replaceWith(t.assignmentPattern(property.value, internal.ref(null, property, undefined)));
|
|
445
469
|
}
|
|
446
470
|
}
|
|
447
471
|
}
|
|
@@ -503,8 +527,12 @@ function meshClassBody(path, internal) {
|
|
|
503
527
|
const key = item.get("key");
|
|
504
528
|
const value = item.get("value");
|
|
505
529
|
if (value.isCallExpression() && (0, call_js_1.calls)(value, ["ref"], internal)) {
|
|
530
|
+
const refValue = value.node.arguments[0];
|
|
531
|
+
const pos = value.node.loc;
|
|
506
532
|
(0, lib_js_1.checkReactiveName)(key, internal);
|
|
507
533
|
meshAllUnknown(value.get("arguments"), internal);
|
|
534
|
+
value.replaceWith((0, lib_js_1.ref)(t.isExpression(refValue) ? refValue : null, internal, item.node, key.isIdentifier() ? key.node.name : undefined));
|
|
535
|
+
value.node.loc = pos;
|
|
508
536
|
}
|
|
509
537
|
else {
|
|
510
538
|
if (key.isIdentifier() && value.node !== null) {
|
|
@@ -521,7 +549,7 @@ function meshClassBody(path, internal) {
|
|
|
521
549
|
}
|
|
522
550
|
}
|
|
523
551
|
}
|
|
524
|
-
function procedureProcessObjectExpression(path, internal, state
|
|
552
|
+
function procedureProcessObjectExpression(path, internal, state) {
|
|
525
553
|
for (const prop of path.get("properties")) {
|
|
526
554
|
const keyPath = prop.get("key");
|
|
527
555
|
const valuePath = prop.get("value");
|
|
@@ -531,7 +559,7 @@ function procedureProcessObjectExpression(path, internal, state, prefix) {
|
|
|
531
559
|
if ((!prop.node.computed || keyPath.isStringLiteral()) && valuePath.isExpression()) {
|
|
532
560
|
const call = (internal.isComposing && !internal.isFunctionParsing) ||
|
|
533
561
|
(0, call_js_1.calls)(valuePath, ["ref", "bind", "calculate"], internal)
|
|
534
|
-
? (0, expression_js_1.checkNode)(valuePath, internal)
|
|
562
|
+
? (0, expression_js_1.checkNode)(valuePath, internal, prop.node)
|
|
535
563
|
: null;
|
|
536
564
|
const name = (0, utils_1.stringify)(keyPath.node);
|
|
537
565
|
if ((call?.found.size ?? 0) > 0) {
|
|
@@ -545,12 +573,12 @@ function procedureProcessObjectExpression(path, internal, state, prefix) {
|
|
|
545
573
|
}
|
|
546
574
|
else {
|
|
547
575
|
if (valuePath.isObjectExpression()) {
|
|
548
|
-
procedureProcessObjectExpression(valuePath, internal, state
|
|
576
|
+
procedureProcessObjectExpression(valuePath, internal, state);
|
|
549
577
|
}
|
|
550
578
|
if (name.startsWith("$")) {
|
|
551
579
|
if (internal.isComposing && !internal.isFunctionParsing) {
|
|
552
580
|
meshExpression(valuePath, internal);
|
|
553
|
-
valuePath.replaceWith(internal.ref(valuePath.node));
|
|
581
|
+
valuePath.replaceWith(internal.ref(valuePath.node, prop.node, undefined));
|
|
554
582
|
state[name] = 1;
|
|
555
583
|
}
|
|
556
584
|
else if (!((valuePath.isIdentifier() && (0, expression_js_1.idIsIValue)(valuePath)) ||
|
|
@@ -569,7 +597,7 @@ function procedureProcessObjectExpression(path, internal, state, prefix) {
|
|
|
569
597
|
meshLValue(valuePath, internal);
|
|
570
598
|
/* istanbul ignore else */
|
|
571
599
|
if (keyPath.isExpression() && valuePath.isExpression()) {
|
|
572
|
-
valuePath.replaceWith(internal.match(keyPath.node, valuePath.node));
|
|
600
|
+
valuePath.replaceWith(internal.match(keyPath.node, valuePath.node, prop.node));
|
|
573
601
|
}
|
|
574
602
|
}
|
|
575
603
|
}
|
|
@@ -579,11 +607,12 @@ function procedureProcessObjectExpression(path, internal, state, prefix) {
|
|
|
579
607
|
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, prop.get("key"), "Method name can not start with $", internal);
|
|
580
608
|
}
|
|
581
609
|
meshStatement(prop.get("body"), internal);
|
|
610
|
+
internal.wrapFunctionBody(prop.node);
|
|
582
611
|
}
|
|
583
612
|
else if (prop.isSpreadElement()) {
|
|
584
613
|
const argumentPath = prop.get("argument");
|
|
585
614
|
if (argumentPath.isObjectExpression()) {
|
|
586
|
-
procedureProcessObjectExpression(argumentPath, internal, state
|
|
615
|
+
procedureProcessObjectExpression(argumentPath, internal, state);
|
|
587
616
|
}
|
|
588
617
|
else {
|
|
589
618
|
meshExpression(argumentPath, internal);
|
|
@@ -593,7 +622,7 @@ function procedureProcessObjectExpression(path, internal, state, prefix) {
|
|
|
593
622
|
return state;
|
|
594
623
|
}
|
|
595
624
|
function processObjectExpression(path, internal) {
|
|
596
|
-
return procedureProcessObjectExpression(path, internal, {}
|
|
625
|
+
return procedureProcessObjectExpression(path, internal, {});
|
|
597
626
|
}
|
|
598
627
|
function meshStatement(path, internal) {
|
|
599
628
|
const statement = path.node;
|
|
@@ -692,6 +721,7 @@ function meshStatement(path, internal) {
|
|
|
692
721
|
const idPath = declaration.get("id");
|
|
693
722
|
const isNotUpperCase = name[0].toUpperCase() !== name[0];
|
|
694
723
|
const isNotLowerCase = name[0].toLowerCase() !== name[0];
|
|
724
|
+
const isExported = t.isExportNamedDeclaration(path.parent);
|
|
695
725
|
function report(error) {
|
|
696
726
|
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, idPath, error, internal);
|
|
697
727
|
}
|
|
@@ -699,7 +729,7 @@ function meshStatement(path, internal) {
|
|
|
699
729
|
if (isNotUpperCase) {
|
|
700
730
|
report("The component name must start with a uppercase letter");
|
|
701
731
|
}
|
|
702
|
-
if (internal.strictFolders && !internal.filename.includes("/components/")) {
|
|
732
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/components/")) {
|
|
703
733
|
report("Components must be placed in a folder named `components`");
|
|
704
734
|
}
|
|
705
735
|
}
|
|
@@ -710,7 +740,7 @@ function meshStatement(path, internal) {
|
|
|
710
740
|
if (!name.endsWith("View")) {
|
|
711
741
|
report("The view name must end with `View`");
|
|
712
742
|
}
|
|
713
|
-
if (internal.strictFolders && !internal.filename.includes("/views/")) {
|
|
743
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/views/")) {
|
|
714
744
|
report("Views must be placed in a folder named `views`");
|
|
715
745
|
}
|
|
716
746
|
}
|
|
@@ -721,7 +751,7 @@ function meshStatement(path, internal) {
|
|
|
721
751
|
if (!name.endsWith("Store")) {
|
|
722
752
|
report("The store name must end with `Store`");
|
|
723
753
|
}
|
|
724
|
-
if (internal.strictFolders && !internal.filename.includes("/stores/")) {
|
|
754
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/stores/")) {
|
|
725
755
|
report("Stores must be placed in a folder named `stores`");
|
|
726
756
|
}
|
|
727
757
|
}
|
|
@@ -732,7 +762,7 @@ function meshStatement(path, internal) {
|
|
|
732
762
|
if (!name.endsWith("Model")) {
|
|
733
763
|
report("The model constructor function name must end with `Model`");
|
|
734
764
|
}
|
|
735
|
-
if (internal.strictFolders && !internal.filename.includes("/models/")) {
|
|
765
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/models/")) {
|
|
736
766
|
report("Models must be placed in a folder named `models`");
|
|
737
767
|
}
|
|
738
768
|
}
|
|
@@ -743,7 +773,7 @@ function meshStatement(path, internal) {
|
|
|
743
773
|
if (!name.endsWith("Modal")) {
|
|
744
774
|
report("The modal component name must end with `Modal`");
|
|
745
775
|
}
|
|
746
|
-
if (internal.strictFolders && !internal.filename.includes("/modals/")) {
|
|
776
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/modals/")) {
|
|
747
777
|
report("Modals must be placed in a folder named `modals`");
|
|
748
778
|
}
|
|
749
779
|
}
|
|
@@ -751,7 +781,7 @@ function meshStatement(path, internal) {
|
|
|
751
781
|
if (!name.startsWith("prompt")) {
|
|
752
782
|
report("The prompt function name must start with `prompt`");
|
|
753
783
|
}
|
|
754
|
-
if (internal.strictFolders && !internal.filename.includes("/prompts/")) {
|
|
784
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/prompts/")) {
|
|
755
785
|
report("Prompts must be placed in a folder named `prompts`");
|
|
756
786
|
}
|
|
757
787
|
}
|
|
@@ -759,14 +789,14 @@ function meshStatement(path, internal) {
|
|
|
759
789
|
if (!name.endsWith("Screen")) {
|
|
760
790
|
report("The screen name must start with `Screen`");
|
|
761
791
|
}
|
|
762
|
-
if (internal.strictFolders && !internal.filename.includes("/screens/")) {
|
|
792
|
+
if (isExported && internal.strictFolders && !internal.filename.includes("/screens/")) {
|
|
763
793
|
report("Screens must be placed in a folder named `screens`");
|
|
764
794
|
}
|
|
765
795
|
}
|
|
766
796
|
if ((0, call_js_1.calls)(initPath, ["page"], internal)) {
|
|
767
797
|
report("Use export default instead");
|
|
768
798
|
}
|
|
769
|
-
if (
|
|
799
|
+
if (isExported) {
|
|
770
800
|
/* istanbul ignore else */
|
|
771
801
|
if (![".ts", ".tsx", ".js", ".jsx"].some(ext => {
|
|
772
802
|
return internal.filename.endsWith(`${name}${ext}`);
|
|
@@ -777,16 +807,24 @@ function meshStatement(path, internal) {
|
|
|
777
807
|
meshComposeCall(id.name, initPath, internal);
|
|
778
808
|
}
|
|
779
809
|
// calculate call
|
|
780
|
-
else if ((0, call_js_1.calls)(initPath, ["calculate"], internal) &&
|
|
781
|
-
(0, lib_js_1.
|
|
810
|
+
else if ((0, call_js_1.calls)(initPath, ["calculate"], internal) &&
|
|
811
|
+
(0, lib_js_1.processCalculateCall)(initPath, internal, declaration.node, t.isIdentifier(id) ? id.name : undefined)) {
|
|
812
|
+
if (!idPath.isArrayPattern() && !idPath.isObjectPattern()) {
|
|
813
|
+
(0, lib_js_1.checkReactiveName)(idPath, internal);
|
|
814
|
+
}
|
|
782
815
|
}
|
|
783
816
|
// ref call
|
|
784
|
-
else if ((0, call_js_1.calls)(initPath, call_js_1.
|
|
817
|
+
else if ((0, call_js_1.calls)(initPath, call_js_1.refFunctions, internal)) {
|
|
818
|
+
const refValue = initPath.node.arguments[0];
|
|
819
|
+
const pos = initPath.node.loc;
|
|
785
820
|
meshAllUnknown(initPath.get("arguments"), internal);
|
|
786
821
|
(0, lib_js_1.checkReactiveName)(idPath, internal);
|
|
822
|
+
initPath.replaceWith((0, lib_js_1.ref)(refValue, internal, declaration.node));
|
|
823
|
+
initPath.node.loc = pos;
|
|
787
824
|
}
|
|
788
825
|
// bind call
|
|
789
|
-
else if ((0, call_js_1.calls)(initPath, ["bind"], internal) &&
|
|
826
|
+
else if ((0, call_js_1.calls)(initPath, ["bind"], internal) &&
|
|
827
|
+
(0, lib_js_1.exprCall)(initPath, initPath.node, internal, { strong: true }, declaration.node)) {
|
|
790
828
|
(0, lib_js_1.checkReactiveName)(idPath, internal);
|
|
791
829
|
}
|
|
792
830
|
// variable declaration
|
|
@@ -867,6 +905,12 @@ function meshFunction(path, internal) {
|
|
|
867
905
|
else if (bodyPath.isBlockStatement()) {
|
|
868
906
|
meshStatement(bodyPath, internal);
|
|
869
907
|
}
|
|
908
|
+
if (path.isFunctionExpression() || path.isArrowFunctionExpression()) {
|
|
909
|
+
path.replaceWith(internal.wrapFunction(path.node));
|
|
910
|
+
}
|
|
911
|
+
else {
|
|
912
|
+
internal.wrapFunctionBody(path.node);
|
|
913
|
+
}
|
|
870
914
|
internal.stack.pop();
|
|
871
915
|
}
|
|
872
916
|
function composeExpression(path, internal) {
|
|
@@ -876,7 +920,7 @@ function composeExpression(path, internal) {
|
|
|
876
920
|
case "OptionalCallExpression": {
|
|
877
921
|
/* istanbul ignore else */
|
|
878
922
|
if ((0, call_js_1.calls)(path, ["watch"], internal)) {
|
|
879
|
-
(0, lib_js_1.parseCalculateCall)(path, internal);
|
|
923
|
+
(0, lib_js_1.parseCalculateCall)(path, internal, path.node, undefined);
|
|
880
924
|
const args = path.node.arguments;
|
|
881
925
|
/* istanbul ignore else */
|
|
882
926
|
if (args) {
|
|
@@ -897,10 +941,16 @@ function composeExpression(path, internal) {
|
|
|
897
941
|
}
|
|
898
942
|
else if ((0, call_js_1.calls)(path, ["beforeDestroy"], internal)) {
|
|
899
943
|
if (internal.stateOnly) {
|
|
900
|
-
(0, lib_js_1.err)(lib_js_1.Errors.IncompatibleContext, path, "Stores in Vasille.JS are not destroyable", internal);
|
|
944
|
+
(0, lib_js_1.err)(lib_js_1.Errors.IncompatibleContext, path, "Stores/Models in Vasille.JS are not destroyable", internal);
|
|
901
945
|
}
|
|
902
946
|
path.get("callee").replaceWith(t.memberExpression(internal_js_1.ctx, t.identifier("runOnDestroy")));
|
|
903
947
|
}
|
|
948
|
+
else if ((0, call_js_1.calls)(path, ["share"], internal)) {
|
|
949
|
+
if (internal.stateOnly) {
|
|
950
|
+
(0, lib_js_1.err)(lib_js_1.Errors.IncompatibleContext, path, "Stores/Models in Vasille.JS cannot share dependecies", internal);
|
|
951
|
+
}
|
|
952
|
+
path.node.arguments.unshift(internal_js_1.ctx);
|
|
953
|
+
}
|
|
904
954
|
break;
|
|
905
955
|
}
|
|
906
956
|
case "JSXElement":
|
|
@@ -960,7 +1010,10 @@ function composeStatement(path, internal) {
|
|
|
960
1010
|
}
|
|
961
1011
|
function idDoubleName() {
|
|
962
1012
|
const pattern = id;
|
|
963
|
-
return
|
|
1013
|
+
return {
|
|
1014
|
+
names: [idName(pattern.elements?.[0]), idName(pattern.elements?.[1])],
|
|
1015
|
+
nodes: [pattern.elements?.[0], pattern.elements?.[1]],
|
|
1016
|
+
};
|
|
964
1017
|
}
|
|
965
1018
|
ignoreParams(declaration.get("id"), internal, ["id", "array"]);
|
|
966
1019
|
/* istanbul ignore else */
|
|
@@ -969,10 +1022,15 @@ function composeStatement(path, internal) {
|
|
|
969
1022
|
reactiveArrayPattern(declaration.get("id"), internal);
|
|
970
1023
|
meshAllUnknown(callPath.get("arguments"), internal);
|
|
971
1024
|
/* istanbul ignore else */
|
|
972
|
-
if (internal.
|
|
973
|
-
|
|
1025
|
+
if (internal.devLayer) {
|
|
1026
|
+
const error = t.identifier("error");
|
|
1027
|
+
const value = t.identifier("value");
|
|
1028
|
+
const { names, nodes } = idDoubleName();
|
|
1029
|
+
callPath.node.arguments.push(t.arrowFunctionExpression([error, value], t.blockStatement([
|
|
1030
|
+
t.expressionStatement(internal.shareStateById(error, names[0])),
|
|
1031
|
+
t.expressionStatement(internal.shareStateById(value, names[1])),
|
|
1032
|
+
])), t.arrayExpression([(0, transformer_1.nodeToStaticPosition)(nodes[0] ?? id), (0, transformer_1.nodeToStaticPosition)(nodes[1] ?? id)]), internal_js_1.inspector);
|
|
974
1033
|
}
|
|
975
|
-
(0, lib_js_1.named)(callPath.node, idDoubleName(), internal, 2);
|
|
976
1034
|
meshInit = false;
|
|
977
1035
|
}
|
|
978
1036
|
else if (t.isIdentifier(id)) {
|
|
@@ -990,10 +1048,10 @@ function composeStatement(path, internal) {
|
|
|
990
1048
|
// const x = bind(a + b);
|
|
991
1049
|
else if ((0, call_js_1.calls)(initPath, ["bind", "calculate"], internal)) {
|
|
992
1050
|
const argument = init.arguments[0];
|
|
993
|
-
const isReactive = (0, lib_js_1.exprCall)(initPath, initPath.node, internal, { name: idName(), strong: true });
|
|
1051
|
+
const isReactive = (0, lib_js_1.exprCall)(initPath, initPath.node, internal, { name: idName(), strong: true }, declaration.node);
|
|
994
1052
|
meshInit = !isReactive;
|
|
995
1053
|
if (!isReactive) {
|
|
996
|
-
declaration.get("init").replaceWith((0, lib_js_1.ref)(argument, internal, idName()));
|
|
1054
|
+
declaration.get("init").replaceWith((0, lib_js_1.ref)(argument, internal, declaration.node, idName()));
|
|
997
1055
|
}
|
|
998
1056
|
(0, lib_js_1.checkReactiveName)(idPath, internal);
|
|
999
1057
|
}
|
|
@@ -1001,25 +1059,25 @@ function composeStatement(path, internal) {
|
|
|
1001
1059
|
else if ((0, call_js_1.calls)(initPath, ["ref"], internal)) {
|
|
1002
1060
|
meshAllUnknown(initPath.get("arguments"), internal);
|
|
1003
1061
|
const argument = init.arguments[0];
|
|
1004
|
-
declaration.get("init").replaceWith((0, lib_js_1.ref)(
|
|
1062
|
+
declaration.get("init").replaceWith((0, lib_js_1.ref)(argument, internal, declaration.node, idName()));
|
|
1005
1063
|
(0, lib_js_1.checkReactiveName)(idPath, internal);
|
|
1006
1064
|
meshInit = false;
|
|
1007
1065
|
}
|
|
1008
1066
|
// const arr = arrayModel()
|
|
1009
1067
|
else if ((0, call_js_1.calls)(initPath, ["arrayModel"], internal)) {
|
|
1010
|
-
(0, lib_js_1.processModelCall)(initPath, "Array", kind === "const", internal, idName());
|
|
1068
|
+
(0, lib_js_1.processModelCall)(initPath, declaration.node, "Array", kind === "const", internal, idName());
|
|
1011
1069
|
meshInit = false;
|
|
1012
1070
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1013
1071
|
}
|
|
1014
1072
|
// const map = mapModel();
|
|
1015
1073
|
else if ((0, call_js_1.calls)(initPath, ["mapModel"], internal)) {
|
|
1016
|
-
(0, lib_js_1.processModelCall)(initPath, "Map", kind === "const", internal, idName());
|
|
1074
|
+
(0, lib_js_1.processModelCall)(initPath, declaration.node, "Map", kind === "const", internal, idName());
|
|
1017
1075
|
meshInit = false;
|
|
1018
1076
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1019
1077
|
}
|
|
1020
1078
|
// const set = setModel();
|
|
1021
1079
|
else if ((0, call_js_1.calls)(initPath, ["setModel"], internal)) {
|
|
1022
|
-
(0, lib_js_1.processModelCall)(initPath, "Set", kind === "const", internal, idName());
|
|
1080
|
+
(0, lib_js_1.processModelCall)(initPath, declaration.node, "Set", kind === "const", internal, idName());
|
|
1023
1081
|
meshInit = false;
|
|
1024
1082
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1025
1083
|
}
|
|
@@ -1036,21 +1094,21 @@ function composeStatement(path, internal) {
|
|
|
1036
1094
|
}
|
|
1037
1095
|
meshExpression(initPath, internal);
|
|
1038
1096
|
meshInit = false;
|
|
1039
|
-
initPath.replaceWith((0, lib_js_1.arrayModel)([initPath.node], internal, idName()));
|
|
1097
|
+
initPath.replaceWith((0, lib_js_1.arrayModel)([initPath.node], declaration.node, internal, idName()));
|
|
1040
1098
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1041
1099
|
}
|
|
1042
1100
|
// const s = new Set(), const m = new Map()
|
|
1043
1101
|
else if (initPath.isNewExpression() &&
|
|
1044
1102
|
t.isIdentifier(initPath.node.callee) &&
|
|
1045
1103
|
["Set", "Map"].includes(initPath.node.callee.name)) {
|
|
1046
|
-
(0, lib_js_1.processModelCall)(initPath, initPath.node.callee.name, kind === "const", internal, idName());
|
|
1104
|
+
(0, lib_js_1.processModelCall)(initPath, declaration.node, initPath.node.callee.name, kind === "const", internal, idName());
|
|
1047
1105
|
meshInit = false;
|
|
1048
1106
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1049
1107
|
}
|
|
1050
1108
|
else if (kind === "let") {
|
|
1051
1109
|
meshExpression(declaration.get("init"), internal);
|
|
1052
1110
|
if (idPath.isIdentifier() && idPath.node.name.startsWith("$")) {
|
|
1053
|
-
declaration.get("init").replaceWith((0, lib_js_1.ref)(declaration.node.init, internal, idName()));
|
|
1111
|
+
declaration.get("init").replaceWith((0, lib_js_1.ref)(declaration.node.init, internal, declaration.node, idName()));
|
|
1054
1112
|
}
|
|
1055
1113
|
else {
|
|
1056
1114
|
switchToConst = false;
|
|
@@ -1061,7 +1119,7 @@ function composeStatement(path, internal) {
|
|
|
1061
1119
|
const isReactive = (0, lib_js_1.exprCall)(declaration.get("init"), declaration.node.init, internal, {
|
|
1062
1120
|
name: idName(),
|
|
1063
1121
|
strong: true,
|
|
1064
|
-
});
|
|
1122
|
+
}, declaration.node);
|
|
1065
1123
|
if (isReactive) {
|
|
1066
1124
|
(0, lib_js_1.checkReactiveName)(idPath, internal);
|
|
1067
1125
|
}
|
package/lib/order-check.js
CHANGED
|
@@ -6,6 +6,7 @@ const lib_1 = require("./lib");
|
|
|
6
6
|
const componentOrder = [
|
|
7
7
|
{ nodeType: ["VariableDeclaration"] },
|
|
8
8
|
{ calls: ["watch"] },
|
|
9
|
+
{ calls: ["share"] },
|
|
9
10
|
{ nodeType: ["FunctionDeclaration"] },
|
|
10
11
|
{ calls: ["beforeMount"] },
|
|
11
12
|
{ nodeType: ["JSXElement", "JSXFragment"] },
|
|
@@ -34,12 +35,13 @@ function checkOrder(paths, internal) {
|
|
|
34
35
|
"Malformed component detected, required component structure is:",
|
|
35
36
|
"1. Variable declarations.",
|
|
36
37
|
"2. Watchers/effects (calls of `watch` function).",
|
|
37
|
-
"3.
|
|
38
|
-
"4.
|
|
39
|
-
"5.
|
|
40
|
-
"6.
|
|
41
|
-
"7.
|
|
42
|
-
"8.
|
|
38
|
+
"3. Dependency sharing (calls of `share` function).",
|
|
39
|
+
"4. Function declarations.",
|
|
40
|
+
"5. Before mount hint (call of `beforeMount` function)",
|
|
41
|
+
"6. JSX elements and fragments",
|
|
42
|
+
"7. After mount hint (call of `afterMount` function)",
|
|
43
|
+
"8. Before destroy hint (call of `beforeDestroy` function)",
|
|
44
|
+
"9. Return statement",
|
|
43
45
|
"All steps are optional, but the order is strict.",
|
|
44
46
|
"Unlisted statements are not accepted.",
|
|
45
47
|
].join("\n"), internal);
|