babel-plugin-vasille 5.0.2 → 5.0.4
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/call.js +5 -3
- package/lib/expression.js +11 -6
- package/lib/jsx.js +23 -21
- package/lib/lib.js +2 -1
- package/lib/mesh.js +101 -67
- package/lib/transformer.js +22 -18
- package/package.json +1 -1
package/lib/call.js
CHANGED
|
@@ -97,12 +97,14 @@ function calls(path, names, internal) {
|
|
|
97
97
|
}
|
|
98
98
|
let propName = null;
|
|
99
99
|
if (t.isMemberExpression(callee)) {
|
|
100
|
-
/* istanbul ignore else */
|
|
101
100
|
if (t.isIdentifier(callee.property)) {
|
|
102
101
|
propName = callee.property.name;
|
|
103
102
|
}
|
|
104
|
-
else
|
|
105
|
-
|
|
103
|
+
else {
|
|
104
|
+
/* istanbul ignore else */
|
|
105
|
+
if (t.isStringLiteral(callee.property)) {
|
|
106
|
+
propName = callee.property.value;
|
|
107
|
+
}
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
if (propName &&
|
package/lib/expression.js
CHANGED
|
@@ -141,13 +141,13 @@ function meshMember(path) {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
function meshLValue(path, internal) {
|
|
144
|
-
/* istanbul ignore else */
|
|
145
144
|
if (path.isIdentifier()) {
|
|
146
145
|
meshIdentifier(path);
|
|
147
146
|
}
|
|
148
147
|
else if (path.isMemberExpression() || path.isOptionalMemberExpression()) {
|
|
149
148
|
const object = path.get("object");
|
|
150
149
|
meshMember(path);
|
|
150
|
+
/* istanbul ignore else */
|
|
151
151
|
if (object.isLVal()) {
|
|
152
152
|
meshLValue(object, internal);
|
|
153
153
|
}
|
|
@@ -160,8 +160,11 @@ function meshLValue(path, internal) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
else
|
|
164
|
-
|
|
163
|
+
else {
|
|
164
|
+
/* istanbul ignore else */
|
|
165
|
+
if (path.isRestElement()) {
|
|
166
|
+
meshLValue(path.get("argument"), internal);
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
function checkNode(path, internal, area, name) {
|
|
@@ -214,12 +217,14 @@ function checkAllExpressions(nodePaths, search) {
|
|
|
214
217
|
}
|
|
215
218
|
function checkAllUnknown(paths, internal) {
|
|
216
219
|
for (const path of paths) {
|
|
217
|
-
/* istanbul ignore else */
|
|
218
220
|
if (path.isSpreadElement()) {
|
|
219
221
|
checkExpression(path.get("argument"), internal);
|
|
220
222
|
}
|
|
221
|
-
else
|
|
222
|
-
|
|
223
|
+
else {
|
|
224
|
+
/* istanbul ignore else */
|
|
225
|
+
if (path.isExpression()) {
|
|
226
|
+
checkExpression(path, internal);
|
|
227
|
+
}
|
|
223
228
|
}
|
|
224
229
|
}
|
|
225
230
|
}
|
package/lib/jsx.js
CHANGED
|
@@ -289,7 +289,6 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
289
289
|
}
|
|
290
290
|
else if (name.name === "class") {
|
|
291
291
|
// class={[..]}
|
|
292
|
-
/* istanbul ignore else */
|
|
293
292
|
if (valuePath.isJSXExpressionContainer() && t.isArrayExpression(valuePath.node.expression)) {
|
|
294
293
|
const arrayExprPath = valuePath.get("expression");
|
|
295
294
|
for (const elementPath of arrayExprPath.get("elements")) {
|
|
@@ -354,19 +353,16 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
354
353
|
}
|
|
355
354
|
attrs.push(t.objectProperty(t.identifier("class"), expressionPath.node));
|
|
356
355
|
}
|
|
357
|
-
// class={name}
|
|
358
|
-
else if (expressionPath && expressionPath.isExpression()) {
|
|
359
|
-
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, {}, expressionPath.node);
|
|
360
|
-
attrs.push(t.objectProperty(t.identifier("class"), expressionPath.node));
|
|
361
|
-
}
|
|
362
356
|
// class="a b"
|
|
363
|
-
else
|
|
364
|
-
|
|
357
|
+
else {
|
|
358
|
+
/* istanbul ignore else */
|
|
359
|
+
if (valuePath.isStringLiteral()) {
|
|
360
|
+
classStatic.push(valuePath.node);
|
|
361
|
+
}
|
|
365
362
|
}
|
|
366
363
|
}
|
|
367
364
|
else if (name.name === "style") {
|
|
368
365
|
// style={{..}}
|
|
369
|
-
/* istanbul ignore else */
|
|
370
366
|
if (expressionPath && expressionPath.isObjectExpression()) {
|
|
371
367
|
for (const propPath of expressionPath.get("properties")) {
|
|
372
368
|
// style={{a: b}}
|
|
@@ -427,11 +423,14 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
427
423
|
attrs.push(t.objectProperty(t.identifier("style"), expressionPath.node));
|
|
428
424
|
}
|
|
429
425
|
// style={`a: ${b}px`}
|
|
430
|
-
else
|
|
431
|
-
|
|
432
|
-
|
|
426
|
+
else {
|
|
427
|
+
/* istanbul ignore else */
|
|
428
|
+
if (expressionPath && expressionPath.isExpression()) {
|
|
429
|
+
if ((0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, { strong: true }, expressionPath.node)) {
|
|
430
|
+
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
431
|
+
}
|
|
432
|
+
attrs.push(t.objectProperty(t.identifier("style"), expressionPath.node));
|
|
433
433
|
}
|
|
434
|
-
attrs.push(t.objectProperty(t.identifier("style"), expressionPath.node));
|
|
435
434
|
}
|
|
436
435
|
}
|
|
437
436
|
else if (name.name === "callback" && expressionPath && expressionPath.isExpression()) {
|
|
@@ -439,7 +438,6 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
439
438
|
callback = expressionPath.node;
|
|
440
439
|
}
|
|
441
440
|
else {
|
|
442
|
-
/* istanbul ignore else */
|
|
443
441
|
if (expressionPath && expressionPath.isExpression()) {
|
|
444
442
|
(0, lib_js_1.exprCall)(expressionPath, expressionPath.node, internal, {}, expressionPath.node);
|
|
445
443
|
attrs.push(idToProp(name, expressionPath.node));
|
|
@@ -455,7 +453,6 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
455
453
|
if (t.isJSXNamespacedName(name)) {
|
|
456
454
|
if (name.namespace.name === "bind") {
|
|
457
455
|
let pushed = false;
|
|
458
|
-
/* istanbul ignore else */
|
|
459
456
|
if (expressionPath) {
|
|
460
457
|
/* istanbul ignore else */
|
|
461
458
|
if (expressionPath.isExpression()) {
|
|
@@ -464,9 +461,12 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
464
461
|
pushed = true;
|
|
465
462
|
}
|
|
466
463
|
}
|
|
467
|
-
else
|
|
468
|
-
|
|
469
|
-
|
|
464
|
+
else {
|
|
465
|
+
/* istanbul ignore else */
|
|
466
|
+
if (t.isStringLiteral(attr.value)) {
|
|
467
|
+
bind.push(idToProp(name.name, attr.value));
|
|
468
|
+
pushed = true;
|
|
469
|
+
}
|
|
470
470
|
}
|
|
471
471
|
if (!pushed) {
|
|
472
472
|
bind.push(idToProp(name.name, t.booleanLiteral(true)));
|
|
@@ -527,7 +527,6 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
527
527
|
const valuePath = attrPath.isJSXAttribute() && attrPath.get("value");
|
|
528
528
|
const needReactive = attr.name.name.startsWith("$");
|
|
529
529
|
// <A prop=".."/>
|
|
530
|
-
/* istanbul ignore else */
|
|
531
530
|
if (t.isStringLiteral(attr.value)) {
|
|
532
531
|
props.push(idToProp(attr.name, needReactive ? internal.ref(attr.value, attr, undefined) : attr.value));
|
|
533
532
|
}
|
|
@@ -538,8 +537,11 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
538
537
|
const value = transformJsxExpressionContainer(valuePath, internal, !isSystem || attr.name.name === "slot", isSystem && attr.name.name === "slot", requiresReactive, !requiresReactive);
|
|
539
538
|
props.push(idToProp(attr.name, value));
|
|
540
539
|
}
|
|
541
|
-
else
|
|
542
|
-
|
|
540
|
+
else {
|
|
541
|
+
/* istanbul ignore else */
|
|
542
|
+
if (!attr.value) {
|
|
543
|
+
props.push(idToProp(attr.name, needReactive ? internal.ref(t.booleanLiteral(true), attr, undefined) : t.booleanLiteral(true)));
|
|
544
|
+
}
|
|
543
545
|
}
|
|
544
546
|
}
|
|
545
547
|
// <A {...arg}/>
|
package/lib/lib.js
CHANGED
|
@@ -179,7 +179,8 @@ function processModelCall(path, usage, type, isConst, internal, name) {
|
|
|
179
179
|
: arrayModel(args, usage, internal, name));
|
|
180
180
|
}
|
|
181
181
|
function checkReactiveName(idPath, internal) {
|
|
182
|
-
if (!(idPath.isIdentifier() && idPath.node.name.startsWith("$"))
|
|
182
|
+
if (!(idPath.isIdentifier() && idPath.node.name.startsWith("$")) &&
|
|
183
|
+
!(idPath.isStringLiteral() && idPath.node.value.startsWith("$"))) {
|
|
183
184
|
err(Errors.RulesOfVasille, idPath, "Reactive variable name must start with $", internal);
|
|
184
185
|
}
|
|
185
186
|
}
|
package/lib/mesh.js
CHANGED
|
@@ -87,12 +87,14 @@ function meshComposeCall(name, path, internal) {
|
|
|
87
87
|
}
|
|
88
88
|
function meshAllUnknown(paths, internal) {
|
|
89
89
|
for (const path of paths) {
|
|
90
|
-
/* istanbul ignore else */
|
|
91
90
|
if (path.isSpreadElement()) {
|
|
92
91
|
meshExpression(path.get("argument"), internal);
|
|
93
92
|
}
|
|
94
|
-
else
|
|
95
|
-
|
|
93
|
+
else {
|
|
94
|
+
/* istanbul ignore else */
|
|
95
|
+
if (path.isExpression()) {
|
|
96
|
+
meshExpression(path, internal);
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
}
|
|
@@ -168,15 +170,17 @@ function meshExpression(nodePath, internal) {
|
|
|
168
170
|
meshAllUnknown([argPath], internal);
|
|
169
171
|
}
|
|
170
172
|
const loc = path.node.loc;
|
|
171
|
-
/* istanbul ignore else */
|
|
172
173
|
if ((0, call_js_1.calls)(path, ["arrayModel"], internal)) {
|
|
173
174
|
path.replaceWith(internal.arrayModel(argPath?.node, path.node, undefined));
|
|
174
175
|
}
|
|
175
176
|
else if ((0, call_js_1.calls)(path, ["mapModel"], internal)) {
|
|
176
177
|
path.replaceWith(internal.mapModel(argPath?.node, path.node, undefined));
|
|
177
178
|
}
|
|
178
|
-
else
|
|
179
|
-
|
|
179
|
+
else {
|
|
180
|
+
/* istanbul ignore else */
|
|
181
|
+
if ((0, call_js_1.calls)(path, ["setModel"], internal)) {
|
|
182
|
+
path.replaceWith(internal.setModel(argPath?.node, path.node, undefined));
|
|
183
|
+
}
|
|
180
184
|
}
|
|
181
185
|
path.node.loc = loc;
|
|
182
186
|
}
|
|
@@ -265,14 +269,19 @@ function meshExpression(nodePath, internal) {
|
|
|
265
269
|
if (t.isExpression(property) && !t.isIdentifier(property)) {
|
|
266
270
|
meshOrIgnoreExpression(path.get("property"), internal);
|
|
267
271
|
}
|
|
268
|
-
if ((0, expression_js_1.memberIsIValue)(node)
|
|
269
|
-
if ((0, expression_js_1.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
if ((0, expression_js_1.memberIsIValue)(node)) {
|
|
273
|
+
if (!(0, expression_js_1.nodeIsMeshed)(path)) {
|
|
274
|
+
if ((0, expression_js_1.exprIsSure)(path, internal)) {
|
|
275
|
+
path.replaceWith(t.memberExpression(path.node, internal_js_1.V));
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
path.replaceWith(t.optionalMemberExpression(path.node, internal_js_1.V, false, true));
|
|
279
|
+
}
|
|
274
280
|
}
|
|
275
281
|
}
|
|
282
|
+
else if (node.computed && t.isIdentifier(property)) {
|
|
283
|
+
path.replaceWith(internal.match(t.stringLiteral(""), node, node));
|
|
284
|
+
}
|
|
276
285
|
break;
|
|
277
286
|
}
|
|
278
287
|
case "BinaryExpression": {
|
|
@@ -382,7 +391,6 @@ function meshStatements(paths, internal) {
|
|
|
382
391
|
}
|
|
383
392
|
}
|
|
384
393
|
function ignoreParams(path, internal, allowReactiveId) {
|
|
385
|
-
/* istanbul ignore else */
|
|
386
394
|
// param with default value
|
|
387
395
|
if (path.isAssignmentPattern()) {
|
|
388
396
|
const left = path.get("left");
|
|
@@ -407,6 +415,7 @@ function ignoreParams(path, internal, allowReactiveId) {
|
|
|
407
415
|
// param is array destruction
|
|
408
416
|
else if (path.isArrayPattern()) {
|
|
409
417
|
for (const element of path.get("elements")) {
|
|
418
|
+
/* istanbul ignore else */
|
|
410
419
|
if (element) {
|
|
411
420
|
ignoreParams(element, internal, allowReactiveId && allowReactiveId.includes("array") && ["id", "array"]);
|
|
412
421
|
if ((!allowReactiveId || !allowReactiveId.includes("array")) && element.isIdentifier()) {
|
|
@@ -437,7 +446,6 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
437
446
|
(originName.startsWith("$") ? `rename it to "$${newName}"` : `rename it to "${newName.substring(1)}"`), internal);
|
|
438
447
|
}
|
|
439
448
|
const valuePath = path.get("value");
|
|
440
|
-
/* istanbul ignore else */
|
|
441
449
|
if (valuePath.isObjectPattern()) {
|
|
442
450
|
/* istanbul ignore else */
|
|
443
451
|
if (originName && originName.startsWith("$")) {
|
|
@@ -449,23 +457,24 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
449
457
|
const right = valuePath.get("right");
|
|
450
458
|
ignoreParams(valuePath.get("left"), internal, ["id"]);
|
|
451
459
|
meshExpression(right, internal);
|
|
452
|
-
if (property.
|
|
453
|
-
right.replaceWith(internal.match(t.stringLiteral(property.key.name), right.node, property));
|
|
454
|
-
}
|
|
455
|
-
else if ((t.isIdentifier(property.key) && property.key.name.startsWith("$")) ||
|
|
460
|
+
if ((t.isIdentifier(property.key) && property.key.name.startsWith("$")) ||
|
|
456
461
|
(t.isStringLiteral(property.key) && property.key.value.startsWith("$"))) {
|
|
457
462
|
right.replaceWith(internal.ref(right.node, property, undefined));
|
|
458
463
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
.get("value")
|
|
465
|
-
.replaceWith(t.assignmentPattern(property.value, internal.match(t.stringLiteral(property.value.name), null, property)));
|
|
464
|
+
else {
|
|
465
|
+
/* istanbul ignore else */
|
|
466
|
+
if (property.computed && !t.isStringLiteral(property.key)) {
|
|
467
|
+
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, valuePath, "Computed property can not be used in destruction", internal);
|
|
468
|
+
}
|
|
466
469
|
}
|
|
467
|
-
|
|
468
|
-
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
/* istanbul ignore else */
|
|
473
|
+
if (t.isIdentifier(property.value)) {
|
|
474
|
+
internal.stack.set(property.value.name, {});
|
|
475
|
+
if (property.value.name.startsWith("$")) {
|
|
476
|
+
path.get("value").replaceWith(t.assignmentPattern(property.value, internal.ref(null, property, undefined)));
|
|
477
|
+
}
|
|
469
478
|
}
|
|
470
479
|
}
|
|
471
480
|
}
|
|
@@ -477,13 +486,15 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
477
486
|
function reactiveArrayPattern(path, internal) {
|
|
478
487
|
if (path.isArrayPattern()) {
|
|
479
488
|
path.get("elements").forEach((element, index) => {
|
|
480
|
-
/* istanbul ignore else */
|
|
481
489
|
if (index < 2) {
|
|
482
490
|
(0, lib_js_1.checkReactiveName)(element, internal);
|
|
483
491
|
}
|
|
484
|
-
else
|
|
485
|
-
|
|
486
|
-
|
|
492
|
+
else {
|
|
493
|
+
/* istanbul ignore else */
|
|
494
|
+
if (element.isIdentifier()) {
|
|
495
|
+
(0, lib_js_1.checkNonReactiveName)(element, internal);
|
|
496
|
+
internal.stack.set(element.node.name, {});
|
|
497
|
+
}
|
|
487
498
|
}
|
|
488
499
|
});
|
|
489
500
|
}
|
|
@@ -519,7 +530,6 @@ function meshForHeader(path, internal) {
|
|
|
519
530
|
}
|
|
520
531
|
function meshClassBody(path, internal) {
|
|
521
532
|
for (const item of path.get("body")) {
|
|
522
|
-
/* istanbul ignore else */
|
|
523
533
|
if (item.isClassMethod() || item.isClassPrivateMethod()) {
|
|
524
534
|
meshFunction(item, internal);
|
|
525
535
|
}
|
|
@@ -541,11 +551,11 @@ function meshClassBody(path, internal) {
|
|
|
541
551
|
meshExpression(item.get("value"), internal);
|
|
542
552
|
}
|
|
543
553
|
}
|
|
544
|
-
else
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
554
|
+
else {
|
|
555
|
+
/* istanbul ignore else */
|
|
556
|
+
if (item.isClassPrivateProperty()) {
|
|
557
|
+
meshExpression(item.get("value"), internal);
|
|
558
|
+
}
|
|
549
559
|
}
|
|
550
560
|
}
|
|
551
561
|
}
|
|
@@ -553,7 +563,6 @@ function procedureProcessObjectExpression(path, internal, state) {
|
|
|
553
563
|
for (const prop of path.get("properties")) {
|
|
554
564
|
const keyPath = prop.get("key");
|
|
555
565
|
const valuePath = prop.get("value");
|
|
556
|
-
/* istanbul ignore else */
|
|
557
566
|
if (prop.isObjectProperty()) {
|
|
558
567
|
// the property name is known in compile time
|
|
559
568
|
if ((!prop.node.computed || keyPath.isStringLiteral()) && valuePath.isExpression()) {
|
|
@@ -609,13 +618,16 @@ function procedureProcessObjectExpression(path, internal, state) {
|
|
|
609
618
|
meshStatement(prop.get("body"), internal);
|
|
610
619
|
internal.wrapFunctionBody(prop.node);
|
|
611
620
|
}
|
|
612
|
-
else
|
|
613
|
-
|
|
614
|
-
if (
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
621
|
+
else {
|
|
622
|
+
/* istanbul ignore else */
|
|
623
|
+
if (prop.isSpreadElement()) {
|
|
624
|
+
const argumentPath = prop.get("argument");
|
|
625
|
+
if (argumentPath.isObjectExpression()) {
|
|
626
|
+
procedureProcessObjectExpression(argumentPath, internal, state);
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
meshExpression(argumentPath, internal);
|
|
630
|
+
}
|
|
619
631
|
}
|
|
620
632
|
}
|
|
621
633
|
}
|
|
@@ -865,7 +877,6 @@ function meshStatement(path, internal) {
|
|
|
865
877
|
}
|
|
866
878
|
case "ExportDefaultDeclaration": {
|
|
867
879
|
const declarationPath = path.get("declaration");
|
|
868
|
-
/* istanbul ignore else */
|
|
869
880
|
// export default 23;
|
|
870
881
|
if (declarationPath.isExpression()) {
|
|
871
882
|
meshExpression(declarationPath, internal);
|
|
@@ -875,8 +886,11 @@ function meshStatement(path, internal) {
|
|
|
875
886
|
meshFunction(declarationPath, internal);
|
|
876
887
|
}
|
|
877
888
|
// export default class ..
|
|
878
|
-
else
|
|
879
|
-
|
|
889
|
+
else {
|
|
890
|
+
/* istanbul ignore else */
|
|
891
|
+
if (declarationPath.isClassDeclaration()) {
|
|
892
|
+
meshClassBody(declarationPath.get("body"), internal);
|
|
893
|
+
}
|
|
880
894
|
}
|
|
881
895
|
}
|
|
882
896
|
}
|
|
@@ -898,12 +912,14 @@ function meshFunction(path, internal) {
|
|
|
898
912
|
ignoreParams(param, internal, false);
|
|
899
913
|
}
|
|
900
914
|
const bodyPath = path.get("body");
|
|
901
|
-
/* istanbul ignore else */
|
|
902
915
|
if (bodyPath.isExpression()) {
|
|
903
916
|
meshExpression(bodyPath, internal);
|
|
904
917
|
}
|
|
905
|
-
else
|
|
906
|
-
|
|
918
|
+
else {
|
|
919
|
+
/* istanbul ignore else */
|
|
920
|
+
if (bodyPath.isBlockStatement()) {
|
|
921
|
+
meshStatement(bodyPath, internal);
|
|
922
|
+
}
|
|
907
923
|
}
|
|
908
924
|
if (path.isFunctionExpression() || path.isArrowFunctionExpression()) {
|
|
909
925
|
path.replaceWith(internal.wrapFunction(path.node));
|
|
@@ -918,7 +934,6 @@ function composeExpression(path, internal) {
|
|
|
918
934
|
switch (expr && expr.type) {
|
|
919
935
|
case "CallExpression":
|
|
920
936
|
case "OptionalCallExpression": {
|
|
921
|
-
/* istanbul ignore else */
|
|
922
937
|
if ((0, call_js_1.calls)(path, ["watch"], internal)) {
|
|
923
938
|
(0, lib_js_1.parseCalculateCall)(path, internal, path.node, undefined);
|
|
924
939
|
const args = path.node.arguments;
|
|
@@ -945,11 +960,14 @@ function composeExpression(path, internal) {
|
|
|
945
960
|
}
|
|
946
961
|
path.get("callee").replaceWith(t.memberExpression(internal_js_1.ctx, t.identifier("runOnDestroy")));
|
|
947
962
|
}
|
|
948
|
-
else
|
|
949
|
-
|
|
950
|
-
|
|
963
|
+
else {
|
|
964
|
+
/* istanbul ignore else */
|
|
965
|
+
if ((0, call_js_1.calls)(path, ["share"], internal)) {
|
|
966
|
+
if (internal.stateOnly) {
|
|
967
|
+
(0, lib_js_1.err)(lib_js_1.Errors.IncompatibleContext, path, "Stores/Models in Vasille.JS cannot share dependencies", internal);
|
|
968
|
+
}
|
|
969
|
+
path.node.arguments.unshift(internal_js_1.ctx);
|
|
951
970
|
}
|
|
952
|
-
path.node.arguments.unshift(internal_js_1.ctx);
|
|
953
971
|
}
|
|
954
972
|
break;
|
|
955
973
|
}
|
|
@@ -1016,7 +1034,6 @@ function composeStatement(path, internal) {
|
|
|
1016
1034
|
};
|
|
1017
1035
|
}
|
|
1018
1036
|
ignoreParams(declaration.get("id"), internal, ["id", "array"]);
|
|
1019
|
-
/* istanbul ignore else */
|
|
1020
1037
|
if ((0, call_js_1.calls)(declaration.get("init"), ["awaited"], internal)) {
|
|
1021
1038
|
const callPath = declaration.get("init");
|
|
1022
1039
|
reactiveArrayPattern(declaration.get("id"), internal);
|
|
@@ -1082,13 +1099,13 @@ function composeStatement(path, internal) {
|
|
|
1082
1099
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1083
1100
|
}
|
|
1084
1101
|
// const x = { .. }
|
|
1085
|
-
else if (t.isObjectExpression(init)) {
|
|
1102
|
+
else if (t.isObjectExpression(init) && !(kind === "let" && id.name.startsWith("$"))) {
|
|
1086
1103
|
internal.stack.set(id.name, processObjectExpression(initPath, internal));
|
|
1087
1104
|
meshInit = false;
|
|
1088
1105
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1089
1106
|
}
|
|
1090
1107
|
// const a = []
|
|
1091
|
-
else if (initPath.isArrayExpression()) {
|
|
1108
|
+
else if (initPath.isArrayExpression() && !(kind === "let" && id.name.startsWith("$"))) {
|
|
1092
1109
|
if (kind !== "const") {
|
|
1093
1110
|
(0, lib_js_1.err)(lib_js_1.Errors.RulesOfVasille, declaration, "Arrays must be must be declared as constants", internal);
|
|
1094
1111
|
}
|
|
@@ -1100,11 +1117,28 @@ function composeStatement(path, internal) {
|
|
|
1100
1117
|
// const s = new Set(), const m = new Map()
|
|
1101
1118
|
else if (initPath.isNewExpression() &&
|
|
1102
1119
|
t.isIdentifier(initPath.node.callee) &&
|
|
1103
|
-
["Set", "Map"].includes(initPath.node.callee.name)
|
|
1120
|
+
["Set", "Map"].includes(initPath.node.callee.name) &&
|
|
1121
|
+
!(kind === "let" && id.name.startsWith("$"))) {
|
|
1104
1122
|
(0, lib_js_1.processModelCall)(initPath, declaration.node, initPath.node.callee.name, kind === "const", internal, idName());
|
|
1105
1123
|
meshInit = false;
|
|
1106
1124
|
(0, lib_js_1.checkNonReactiveName)(idPath, internal);
|
|
1107
1125
|
}
|
|
1126
|
+
// const x = y[z]
|
|
1127
|
+
else if (kind === "const" &&
|
|
1128
|
+
(initPath.isOptionalMemberExpression() || initPath.isMemberExpression()) &&
|
|
1129
|
+
initPath.node.computed &&
|
|
1130
|
+
t.isIdentifier(initPath.node.property)) {
|
|
1131
|
+
const path = initPath;
|
|
1132
|
+
const property = path.get("property");
|
|
1133
|
+
meshExpression(path.get("object"), internal);
|
|
1134
|
+
/* istanbul ignore else */
|
|
1135
|
+
if (property.isExpression()) {
|
|
1136
|
+
meshExpression(property, internal);
|
|
1137
|
+
}
|
|
1138
|
+
meshInit = false;
|
|
1139
|
+
path.replaceWith(internal.match(t.stringLiteral(id.name.startsWith("$") ? "$" : ""), path.node, declaration.node));
|
|
1140
|
+
}
|
|
1141
|
+
// let x = ..
|
|
1108
1142
|
else if (kind === "let") {
|
|
1109
1143
|
meshExpression(declaration.get("init"), internal);
|
|
1110
1144
|
if (idPath.isIdentifier() && idPath.node.name.startsWith("$")) {
|
|
@@ -1115,6 +1149,7 @@ function composeStatement(path, internal) {
|
|
|
1115
1149
|
}
|
|
1116
1150
|
meshInit = false;
|
|
1117
1151
|
}
|
|
1152
|
+
// const x = ..
|
|
1118
1153
|
else {
|
|
1119
1154
|
const isReactive = (0, lib_js_1.exprCall)(declaration.get("init"), declaration.node.init, internal, {
|
|
1120
1155
|
name: idName(),
|
|
@@ -1129,9 +1164,6 @@ function composeStatement(path, internal) {
|
|
|
1129
1164
|
meshInit = !isReactive;
|
|
1130
1165
|
}
|
|
1131
1166
|
}
|
|
1132
|
-
else if (t.isObjectPattern(id)) {
|
|
1133
|
-
ignoreObjectPattern(declaration.get("id"), internal);
|
|
1134
|
-
}
|
|
1135
1167
|
if (meshInit) {
|
|
1136
1168
|
meshExpression(declaration.get("init"), internal);
|
|
1137
1169
|
}
|
|
@@ -1162,13 +1194,15 @@ function compose(path, internal, isInternalSlot, isSlot) {
|
|
|
1162
1194
|
if (!isSlot) {
|
|
1163
1195
|
internal.isComposing = true;
|
|
1164
1196
|
}
|
|
1165
|
-
/* istanbul ignore else */
|
|
1166
1197
|
if (body.isExpression()) {
|
|
1167
1198
|
composeExpression(body, internal);
|
|
1168
1199
|
}
|
|
1169
|
-
else
|
|
1170
|
-
|
|
1171
|
-
|
|
1200
|
+
else {
|
|
1201
|
+
/* istanbul ignore else */
|
|
1202
|
+
if (body.isBlockStatement()) {
|
|
1203
|
+
(0, order_check_1.checkOrder)(body.get("body"), internal);
|
|
1204
|
+
composeStatement(body, internal);
|
|
1205
|
+
}
|
|
1172
1206
|
}
|
|
1173
1207
|
if (!isSlot) {
|
|
1174
1208
|
internal.isComposing = false;
|
package/lib/transformer.js
CHANGED
|
@@ -78,25 +78,27 @@ function handleImportDeclaration(statementPath, internal, ids) {
|
|
|
78
78
|
statement.source.value = internal.replaceWeb;
|
|
79
79
|
internal.prefix = name;
|
|
80
80
|
for (const specifier of statement.specifiers) {
|
|
81
|
-
/* istanbul ignore else */
|
|
82
81
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
|
83
82
|
internal.global = specifier.local.name;
|
|
84
83
|
internal.stylesConnected = true;
|
|
85
84
|
}
|
|
86
|
-
else
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
internal.
|
|
85
|
+
else {
|
|
86
|
+
/* istanbul ignore else */
|
|
87
|
+
if (t.isImportSpecifier(specifier)) {
|
|
88
|
+
const imported = extractText(specifier.imported);
|
|
89
|
+
const local = specifier.local.name;
|
|
90
|
+
if (imported === "bind" || imported === "calculate" || imported === "watch") {
|
|
91
|
+
ids.expr = local;
|
|
92
|
+
}
|
|
93
|
+
if (imported in ids) {
|
|
94
|
+
ids[imported] = local;
|
|
95
|
+
}
|
|
96
|
+
internal.mapping.set(local, imported);
|
|
97
|
+
if (imported === "styleSheet") {
|
|
98
|
+
internal.stylesConnected = true;
|
|
99
|
+
}
|
|
100
|
+
internal.importStatement = statementPath;
|
|
98
101
|
}
|
|
99
|
-
internal.importStatement = statementPath;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
statement.specifiers = statement.specifiers.filter(spec => {
|
|
@@ -236,9 +238,9 @@ function transformProgram(path, filename, opts) {
|
|
|
236
238
|
},
|
|
237
239
|
match(name, arg, area) {
|
|
238
240
|
if (opts.devLayer) {
|
|
239
|
-
return call("match", [name, arg
|
|
241
|
+
return call("match", [name, arg, nodeToStaticPosition(area), getInspector()]);
|
|
240
242
|
}
|
|
241
|
-
return call("match",
|
|
243
|
+
return call("match", [name, arg]);
|
|
242
244
|
},
|
|
243
245
|
set(obj, field, value, area) {
|
|
244
246
|
if (opts.devLayer) {
|
|
@@ -263,12 +265,14 @@ function transformProgram(path, filename, opts) {
|
|
|
263
265
|
fn.body = t.blockStatement([
|
|
264
266
|
t.returnStatement(call("runFn", [
|
|
265
267
|
t.arrowFunctionExpression(params, body, fn.async),
|
|
266
|
-
args,
|
|
268
|
+
fn.params.length > 0 ? args : t.arrayExpression(),
|
|
267
269
|
nodeToStaticPosition(fn),
|
|
268
270
|
getInspector(),
|
|
269
271
|
])),
|
|
270
272
|
]);
|
|
271
|
-
fn.params
|
|
273
|
+
if (fn.params.length > 0) {
|
|
274
|
+
fn.params = [t.restElement(args)];
|
|
275
|
+
}
|
|
272
276
|
}
|
|
273
277
|
},
|
|
274
278
|
wrapFunction(fn) {
|