babel-plugin-vasille 3.1.1 → 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 +73 -25
- package/lib/css-transformer.js +43 -7
- package/lib/expression.js +120 -44
- package/lib/index.js +6 -3
- package/lib/internal.js +42 -5
- package/lib/jsx-detect.js +42 -4
- package/lib/jsx.js +83 -32
- package/lib/lib.js +94 -43
- package/lib/mesh.js +277 -97
- package/lib/router.js +41 -0
- package/lib/transformer.js +50 -9
- 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 -53
- package/lib-node/router.js +41 -0
- package/lib-node/transformer.js +6 -1
- package/lib-node/utils.js +50 -0
- package/package.json +10 -11
package/lib/mesh.js
CHANGED
|
@@ -1,40 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.meshOrIgnoreAllExpressions = meshOrIgnoreAllExpressions;
|
|
37
|
+
exports.meshAllExpressions = meshAllExpressions;
|
|
38
|
+
exports.meshComposeCall = meshComposeCall;
|
|
39
|
+
exports.meshAllUnknown = meshAllUnknown;
|
|
40
|
+
exports.meshLValue = meshLValue;
|
|
41
|
+
exports.meshOrIgnoreExpression = meshOrIgnoreExpression;
|
|
42
|
+
exports.meshExpression = meshExpression;
|
|
43
|
+
exports.meshStatements = meshStatements;
|
|
44
|
+
exports.ignoreParams = ignoreParams;
|
|
45
|
+
exports.reactiveArrayPattern = reactiveArrayPattern;
|
|
46
|
+
exports.meshStatement = meshStatement;
|
|
47
|
+
exports.meshFunction = meshFunction;
|
|
48
|
+
exports.composeExpression = composeExpression;
|
|
49
|
+
exports.composeStatements = composeStatements;
|
|
50
|
+
exports.composeStatement = composeStatement;
|
|
51
|
+
exports.compose = compose;
|
|
52
|
+
const t = __importStar(require("@babel/types"));
|
|
53
|
+
const bridge_1 = require("./bridge");
|
|
54
|
+
const call_js_1 = require("./call.js");
|
|
55
|
+
const expression_js_1 = require("./expression.js");
|
|
56
|
+
const internal_js_1 = require("./internal.js");
|
|
57
|
+
const jsx_js_1 = require("./jsx.js");
|
|
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
|
+
};
|
|
81
|
+
function meshOrIgnoreAllExpressions(nodePaths, internal) {
|
|
8
82
|
for (const path of nodePaths) {
|
|
83
|
+
/* istanbul ignore else */
|
|
9
84
|
if (t.isExpression(path.node)) {
|
|
10
85
|
meshExpression(path, internal);
|
|
11
86
|
}
|
|
12
87
|
}
|
|
13
88
|
}
|
|
14
|
-
|
|
89
|
+
function meshAllExpressions(nodePaths, internal) {
|
|
15
90
|
for (const path of nodePaths) {
|
|
16
91
|
meshExpression(path, internal);
|
|
17
92
|
}
|
|
18
93
|
}
|
|
19
|
-
|
|
94
|
+
function meshComposeCall(call, name, nodePath, method, internal) {
|
|
20
95
|
const arg = call.arguments[0];
|
|
21
96
|
if (call.arguments.length !== 1 || !(t.isFunctionExpression(arg) || t.isArrowFunctionExpression(arg))) {
|
|
22
97
|
throw nodePath.buildCodeFrameError("Vasille: Invalid arguments");
|
|
23
98
|
}
|
|
24
99
|
const fnPath = nodePath.get("arguments")[0];
|
|
25
|
-
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
|
+
}
|
|
26
104
|
if (!internal.stateOnly) {
|
|
27
|
-
arg.params.unshift(ctx);
|
|
105
|
+
arg.params.unshift(internal_js_1.ctx);
|
|
28
106
|
}
|
|
29
107
|
if (internal.devMode) {
|
|
30
108
|
call.arguments.push(t.stringLiteral(`${internal.prefix}:${name ? name.name : "#anonymouse"}`));
|
|
31
109
|
}
|
|
32
|
-
if (t.isIdentifier(call.callee) && call.callee.name === "state") {
|
|
33
|
-
nodePath.replaceWith(call.arguments[0]);
|
|
34
|
-
}
|
|
35
110
|
}
|
|
36
|
-
|
|
111
|
+
function meshAllUnknown(paths, internal) {
|
|
37
112
|
for (const path of paths) {
|
|
113
|
+
/* istanbul ignore else */
|
|
38
114
|
if (t.isSpreadElement(path.node)) {
|
|
39
115
|
meshExpression(path.get("argument"), internal);
|
|
40
116
|
}
|
|
@@ -43,24 +119,27 @@ export function meshAllUnknown(paths, internal) {
|
|
|
43
119
|
}
|
|
44
120
|
}
|
|
45
121
|
}
|
|
46
|
-
|
|
122
|
+
function meshLValue(path, internal) {
|
|
47
123
|
const node = path.node;
|
|
124
|
+
/* istanbul ignore else */
|
|
48
125
|
if (t.isExpression(node)) {
|
|
49
126
|
meshExpression(path, internal);
|
|
50
127
|
}
|
|
51
128
|
}
|
|
52
|
-
|
|
129
|
+
function meshOrIgnoreExpression(path, internal) {
|
|
130
|
+
/* istanbul ignore else */
|
|
53
131
|
if (t.isExpression(path.node)) {
|
|
54
132
|
meshExpression(path, internal);
|
|
55
133
|
}
|
|
56
134
|
}
|
|
57
|
-
|
|
135
|
+
function meshExpression(nodePath, internal, isRoot) {
|
|
58
136
|
const expr = nodePath.node;
|
|
59
137
|
if (!expr) {
|
|
60
138
|
return;
|
|
61
139
|
}
|
|
62
|
-
|
|
63
|
-
|
|
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);
|
|
64
143
|
return;
|
|
65
144
|
}
|
|
66
145
|
switch (expr.type) {
|
|
@@ -76,7 +155,7 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
76
155
|
}
|
|
77
156
|
case "Identifier": {
|
|
78
157
|
const state = internal.stack.get(expr.name);
|
|
79
|
-
if (idIsIValue(nodePath, internal)) {
|
|
158
|
+
if ((0, expression_js_1.idIsIValue)(nodePath, internal)) {
|
|
80
159
|
nodePath.replaceWith(t.memberExpression(expr, t.identifier(state === 4 /* VariableState.ReactivePointer */ ? "$$" : "$")));
|
|
81
160
|
}
|
|
82
161
|
break;
|
|
@@ -89,23 +168,26 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
89
168
|
case "CallExpression":
|
|
90
169
|
case "OptionalCallExpression": {
|
|
91
170
|
const path = nodePath;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
throw path.buildCodeFrameError(`Vasille: Usage of hint "${callsFn}" is restricted here`);
|
|
96
|
-
}
|
|
97
|
-
if (callsStyleHint) {
|
|
98
|
-
throw path.buildCodeFrameError(`Vasille: Usage of style hint "${callsStyleHint}" is restricted here`);
|
|
99
|
-
}
|
|
100
|
-
meshOrIgnoreExpression(path.get("callee"), internal);
|
|
101
|
-
meshAllUnknown(path.get("arguments"), internal);
|
|
102
|
-
if (calls(path.node, ["calculate"], internal)) {
|
|
103
|
-
if (path.node.arguments.length === 1 &&
|
|
104
|
-
(t.isFunctionExpression(path.node.arguments[0]) || t.isArrowFunctionExpression(path.node.arguments[0]))) {
|
|
105
|
-
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);
|
|
106
174
|
}
|
|
107
175
|
else {
|
|
108
|
-
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);
|
|
109
191
|
}
|
|
110
192
|
}
|
|
111
193
|
break;
|
|
@@ -116,7 +198,7 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
116
198
|
let replaced = false;
|
|
117
199
|
meshLValue(path.get("left"), internal);
|
|
118
200
|
if (t.isIdentifier(left) && internal.stack.get(left.name) === 4 /* VariableState.ReactivePointer */) {
|
|
119
|
-
const replaceWith = forwardOnlyExpr(path.get("right"), path.node.right, internal);
|
|
201
|
+
const replaceWith = (0, lib_js_1.forwardOnlyExpr)(path.get("right"), path.node.right, internal);
|
|
120
202
|
if (replaceWith) {
|
|
121
203
|
path.get("right").replaceWith(replaceWith);
|
|
122
204
|
replaced = true;
|
|
@@ -136,7 +218,7 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
136
218
|
if (t.isExpression(property) && !t.isIdentifier(property)) {
|
|
137
219
|
meshOrIgnoreExpression(path.get("property"), internal);
|
|
138
220
|
}
|
|
139
|
-
if (memberIsIValue(node, internal)) {
|
|
221
|
+
if ((0, expression_js_1.memberIsIValue)(node, internal)) {
|
|
140
222
|
path.replaceWith(t.memberExpression(node, t.identifier("$")));
|
|
141
223
|
}
|
|
142
224
|
break;
|
|
@@ -221,12 +303,12 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
221
303
|
let replaced = false;
|
|
222
304
|
if (isRoot &&
|
|
223
305
|
internal.stateOnly &&
|
|
224
|
-
!path.node.computed &&
|
|
225
|
-
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)) &&
|
|
226
308
|
t.isExpression(valuePath.node)) {
|
|
227
|
-
const call = exprCall(valuePath, valuePath.node, internal);
|
|
309
|
+
const call = (0, lib_js_1.exprCall)(valuePath, valuePath.node, internal);
|
|
228
310
|
if (call) {
|
|
229
|
-
if (path.node.key.
|
|
311
|
+
if ((0, utils_1.stringify)(path.node.key).startsWith("$")) {
|
|
230
312
|
valuePath.replaceWith(call);
|
|
231
313
|
}
|
|
232
314
|
else {
|
|
@@ -235,9 +317,13 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
235
317
|
replaced = true;
|
|
236
318
|
}
|
|
237
319
|
else if (t.isIdentifier(valuePath.node) &&
|
|
238
|
-
internal.stack.get(valuePath.node.name) === 3 /* VariableState.ReactiveObject */
|
|
239
|
-
!path.node.key.
|
|
240
|
-
|
|
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");
|
|
241
327
|
}
|
|
242
328
|
}
|
|
243
329
|
if (!replaced) {
|
|
@@ -245,6 +331,9 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
245
331
|
}
|
|
246
332
|
}
|
|
247
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
|
+
}
|
|
248
337
|
meshFunction(propPath, internal);
|
|
249
338
|
}
|
|
250
339
|
else if (isRoot && internal.stateOnly && t.isSpreadElement(prop)) {
|
|
@@ -276,15 +365,17 @@ export function meshExpression(nodePath, internal, isRoot) {
|
|
|
276
365
|
}
|
|
277
366
|
}
|
|
278
367
|
}
|
|
279
|
-
|
|
368
|
+
function meshStatements(paths, internal) {
|
|
280
369
|
for (const path of paths) {
|
|
281
370
|
meshStatement(path, internal);
|
|
282
371
|
}
|
|
283
372
|
}
|
|
284
|
-
|
|
373
|
+
function ignoreParams(val, internal) {
|
|
374
|
+
/* istanbul ignore else */
|
|
285
375
|
if (t.isAssignmentPattern(val)) {
|
|
286
376
|
val = val.left;
|
|
287
377
|
}
|
|
378
|
+
/* istanbul ignore else */
|
|
288
379
|
if (t.isIdentifier(val)) {
|
|
289
380
|
internal.stack.set(val.name, 1 /* VariableState.Ignored */);
|
|
290
381
|
}
|
|
@@ -301,7 +392,9 @@ export function ignoreParams(val, internal) {
|
|
|
301
392
|
}
|
|
302
393
|
function ignoreObjectPattern(pattern, internal) {
|
|
303
394
|
for (const property of pattern.properties) {
|
|
395
|
+
/* istanbul ignore else */
|
|
304
396
|
if (t.isObjectProperty(property)) {
|
|
397
|
+
/* istanbul ignore else */
|
|
305
398
|
if (t.isObjectPattern(property.value)) {
|
|
306
399
|
ignoreObjectPattern(property.value, internal);
|
|
307
400
|
}
|
|
@@ -312,14 +405,16 @@ function ignoreObjectPattern(pattern, internal) {
|
|
|
312
405
|
internal.stack.set(property.value.name, 1 /* VariableState.Ignored */);
|
|
313
406
|
}
|
|
314
407
|
}
|
|
408
|
+
/* istanbul ignore else */
|
|
315
409
|
if (t.isRestElement(property)) {
|
|
316
410
|
internal.stack.set(property.argument.name, 1 /* VariableState.Ignored */);
|
|
317
411
|
}
|
|
318
412
|
}
|
|
319
413
|
}
|
|
320
|
-
|
|
414
|
+
function reactiveArrayPattern(path, internal) {
|
|
321
415
|
if (t.isArrayPattern(path.node)) {
|
|
322
416
|
path.node.elements.forEach((element, index) => {
|
|
417
|
+
/* istanbul ignore else */
|
|
323
418
|
if (t.isIdentifier(element)) {
|
|
324
419
|
internal.stack.set(element.name, index < 2 ? 2 /* VariableState.Reactive */ : 1 /* VariableState.Ignored */);
|
|
325
420
|
}
|
|
@@ -332,12 +427,14 @@ export function reactiveArrayPattern(path, internal) {
|
|
|
332
427
|
function meshForEachHeader(path, internal) {
|
|
333
428
|
const left = path.node.left;
|
|
334
429
|
meshExpression(path.get("right"), internal);
|
|
430
|
+
/* istanbul ignore else */
|
|
335
431
|
if (t.isVariableDeclaration(left) && t.isVariableDeclarator(left.declarations[0])) {
|
|
336
432
|
ignoreParams(left.declarations[0].id, internal);
|
|
337
433
|
}
|
|
338
434
|
}
|
|
339
435
|
function meshForHeader(path, internal) {
|
|
340
436
|
const node = path.node;
|
|
437
|
+
/* istanbul ignore else */
|
|
341
438
|
if (node.init) {
|
|
342
439
|
if (t.isExpression(node.init)) {
|
|
343
440
|
meshExpression(path.get("init"), internal);
|
|
@@ -355,12 +452,18 @@ function meshForHeader(path, internal) {
|
|
|
355
452
|
}
|
|
356
453
|
function meshClassBody(path, internal) {
|
|
357
454
|
for (const item of path.get("body")) {
|
|
455
|
+
/* istanbul ignore else */
|
|
358
456
|
if (t.isClassMethod(item.node) || t.isClassPrivateMethod(item.node)) {
|
|
359
457
|
meshFunction(item, internal);
|
|
360
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
|
+
}
|
|
361
464
|
}
|
|
362
465
|
}
|
|
363
|
-
|
|
466
|
+
function meshStatement(path, internal) {
|
|
364
467
|
const statement = path.node;
|
|
365
468
|
switch (statement && statement.type) {
|
|
366
469
|
case "BlockStatement":
|
|
@@ -439,6 +542,7 @@ export function meshStatement(path, internal) {
|
|
|
439
542
|
break;
|
|
440
543
|
case "TryStatement":
|
|
441
544
|
meshStatement(path.get("block"), internal);
|
|
545
|
+
/* istanbul ignore else */
|
|
442
546
|
if (path.node.handler) {
|
|
443
547
|
meshStatement(path.get("handler").get("body"), internal);
|
|
444
548
|
}
|
|
@@ -448,8 +552,10 @@ export function meshStatement(path, internal) {
|
|
|
448
552
|
const _path = path;
|
|
449
553
|
for (const declaration of _path.get("declarations")) {
|
|
450
554
|
const expr = declaration.node.init;
|
|
451
|
-
|
|
452
|
-
|
|
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);
|
|
453
559
|
}
|
|
454
560
|
else {
|
|
455
561
|
meshExpression(declaration.get("init"), internal);
|
|
@@ -475,6 +581,7 @@ export function meshStatement(path, internal) {
|
|
|
475
581
|
break;
|
|
476
582
|
case "ExportDefaultDeclaration": {
|
|
477
583
|
const declarationPath = path.get("declaration");
|
|
584
|
+
/* istanbul ignore else */
|
|
478
585
|
if (t.isExpression(declarationPath.node)) {
|
|
479
586
|
meshExpression(declarationPath, internal);
|
|
480
587
|
}
|
|
@@ -487,7 +594,7 @@ export function meshStatement(path, internal) {
|
|
|
487
594
|
}
|
|
488
595
|
}
|
|
489
596
|
}
|
|
490
|
-
|
|
597
|
+
function meshFunction(path, internal) {
|
|
491
598
|
if (t.isFunctionDeclaration(path.node) && path.node.id) {
|
|
492
599
|
internal.stack.set(path.node.id.name, 1 /* VariableState.Ignored */);
|
|
493
600
|
}
|
|
@@ -508,7 +615,7 @@ export function meshFunction(path, internal) {
|
|
|
508
615
|
}
|
|
509
616
|
internal.stack.pop();
|
|
510
617
|
}
|
|
511
|
-
|
|
618
|
+
function composeExpression(path, internal, isRoot) {
|
|
512
619
|
const expr = path.node;
|
|
513
620
|
switch (expr && expr.type) {
|
|
514
621
|
case "AssignmentExpression": {
|
|
@@ -517,18 +624,26 @@ export function composeExpression(path, internal, isRoot) {
|
|
|
517
624
|
}
|
|
518
625
|
case "CallExpression":
|
|
519
626
|
case "OptionalCallExpression": {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
627
|
+
if ((0, call_js_1.calls)(path, ["watch"], internal)) {
|
|
628
|
+
const args = (0, lib_js_1.parseCalculateCall)(path, internal);
|
|
629
|
+
/* istanbul ignore else */
|
|
523
630
|
if (args) {
|
|
524
631
|
if (args[1].elements.length > 0) {
|
|
525
|
-
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));
|
|
526
635
|
}
|
|
527
636
|
else {
|
|
528
637
|
path.replaceWith(t.callExpression(args[0], []));
|
|
529
638
|
}
|
|
530
639
|
}
|
|
531
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
|
+
}
|
|
532
647
|
else {
|
|
533
648
|
meshExpression(path, internal);
|
|
534
649
|
}
|
|
@@ -548,18 +663,18 @@ export function composeExpression(path, internal, isRoot) {
|
|
|
548
663
|
if (internal.stateOnly) {
|
|
549
664
|
throw path.buildCodeFrameError("Vasille: JSX is not allowed in states");
|
|
550
665
|
}
|
|
551
|
-
path.replaceWithMultiple(transformJsx(path, internal));
|
|
666
|
+
path.replaceWithMultiple((0, jsx_js_1.transformJsx)(path, internal));
|
|
552
667
|
break;
|
|
553
668
|
default:
|
|
554
669
|
meshExpression(path, internal, isRoot);
|
|
555
670
|
}
|
|
556
671
|
}
|
|
557
|
-
|
|
672
|
+
function composeStatements(paths, internal, isRoot) {
|
|
558
673
|
for (const path of paths) {
|
|
559
674
|
composeStatement(path, internal, isRoot);
|
|
560
675
|
}
|
|
561
676
|
}
|
|
562
|
-
|
|
677
|
+
function composeStatement(path, internal, isRoot) {
|
|
563
678
|
const statement = path.node;
|
|
564
679
|
if (!statement) {
|
|
565
680
|
return;
|
|
@@ -641,14 +756,14 @@ export function composeStatement(path, internal, isRoot) {
|
|
|
641
756
|
const _path = path;
|
|
642
757
|
const kind = _path.node.kind;
|
|
643
758
|
const declares = kind === "const" ? 1 /* VariableState.Ignored */ : 2 /* VariableState.Reactive */;
|
|
644
|
-
|
|
645
|
-
_path.node.kind = "const";
|
|
646
|
-
}
|
|
759
|
+
let switchToConst = true;
|
|
647
760
|
for (const declaration of _path.get("declarations")) {
|
|
648
761
|
const id = declaration.node.id;
|
|
762
|
+
const bridgeMethod = (0, bridge_1.processBridgeCall)(declaration.get("init"), internal);
|
|
649
763
|
let meshInit = true;
|
|
650
764
|
function idName(target = id) {
|
|
651
765
|
let name = "#";
|
|
766
|
+
/* istanbul ignore else */
|
|
652
767
|
if (t.isIdentifier(target)) {
|
|
653
768
|
name = target.name;
|
|
654
769
|
}
|
|
@@ -659,35 +774,49 @@ export function composeStatement(path, internal, isRoot) {
|
|
|
659
774
|
return [idName(pattern.elements[0]), idName(pattern.elements[1])];
|
|
660
775
|
}
|
|
661
776
|
ignoreParams(declaration.node.id, internal);
|
|
662
|
-
|
|
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)) {
|
|
663
789
|
reactiveArrayPattern(declaration.get("id"), internal);
|
|
664
790
|
meshAllUnknown(declaration.get("init").get("arguments"), internal);
|
|
665
|
-
named(declaration.node.init, idDoubleName(), internal);
|
|
791
|
+
(0, lib_js_1.named)(declaration.node.init, idDoubleName(), internal);
|
|
666
792
|
meshInit = false;
|
|
667
793
|
}
|
|
668
794
|
else if (t.isIdentifier(id)) {
|
|
669
795
|
internal.stack.set(id.name, declares);
|
|
670
796
|
const init = declaration.node.init;
|
|
671
|
-
|
|
797
|
+
const initPath = declaration.get("init");
|
|
798
|
+
let callName = false;
|
|
799
|
+
if ((0, call_js_1.calls)(initPath, ["value"], internal)) {
|
|
672
800
|
internal.stack.set(id.name, 1 /* VariableState.Ignored */);
|
|
673
801
|
declaration.get("init").replaceWith(init.arguments[0]);
|
|
674
802
|
_path.node.kind = kind;
|
|
803
|
+
switchToConst = false;
|
|
675
804
|
}
|
|
676
|
-
else if (calls(
|
|
805
|
+
else if ((0, call_js_1.calls)(initPath, ["bind"], internal)) {
|
|
677
806
|
const argument = init.arguments[0];
|
|
678
807
|
const argumentPath = declaration.get("init").get("arguments")[0];
|
|
679
808
|
let replaceWith = declares === 2 /* VariableState.Reactive */
|
|
680
|
-
? forwardOnlyExpr(argumentPath, argument, internal)
|
|
681
|
-
: exprCall(argumentPath, argument, internal, idName());
|
|
809
|
+
? (0, lib_js_1.forwardOnlyExpr)(argumentPath, argument, internal)
|
|
810
|
+
: (0, lib_js_1.exprCall)(argumentPath, argument, internal, idName());
|
|
682
811
|
if (!replaceWith) {
|
|
683
812
|
replaceWith =
|
|
684
813
|
declares === 2 /* VariableState.Reactive */
|
|
685
814
|
? t.callExpression(t.memberExpression(internal.id, t.identifier("r")), [argument])
|
|
686
|
-
: ref(argument, internal, idName());
|
|
815
|
+
: (0, lib_js_1.ref)(argument, internal, idName());
|
|
687
816
|
}
|
|
688
817
|
if (declares === 2 /* VariableState.Reactive */) {
|
|
689
818
|
internal.stack.set(id.name, 4 /* VariableState.ReactivePointer */);
|
|
690
|
-
replaceWith = own(replaceWith, internal, idName());
|
|
819
|
+
replaceWith = (0, lib_js_1.own)(replaceWith, internal, idName());
|
|
691
820
|
}
|
|
692
821
|
else {
|
|
693
822
|
internal.stack.set(id.name, 2 /* VariableState.Reactive */);
|
|
@@ -695,58 +824,57 @@ export function composeStatement(path, internal, isRoot) {
|
|
|
695
824
|
declaration.get("init").replaceWith(replaceWith);
|
|
696
825
|
meshInit = !replaceWith;
|
|
697
826
|
}
|
|
698
|
-
else if (calls(
|
|
827
|
+
else if ((0, call_js_1.calls)(initPath, ["ref"], internal)) {
|
|
699
828
|
const argument = init.arguments[0];
|
|
700
829
|
internal.stack.set(id.name, 2 /* VariableState.Reactive */);
|
|
701
|
-
declaration.get("init").replaceWith(ref(t.isExpression(argument) ? argument : null, internal, idName()));
|
|
830
|
+
declaration.get("init").replaceWith((0, lib_js_1.ref)(t.isExpression(argument) ? argument : null, internal, idName()));
|
|
702
831
|
}
|
|
703
|
-
else if (calls(
|
|
832
|
+
else if ((0, call_js_1.calls)(initPath, ["reactiveObject"], internal)) {
|
|
704
833
|
const value = init.arguments[0];
|
|
705
834
|
if (kind !== "const") {
|
|
706
835
|
throw declaration.buildCodeFrameError(`Vasille: Reactive objects must be must be declared as constants`);
|
|
707
836
|
}
|
|
708
837
|
if (t.isObjectExpression(value)) {
|
|
709
|
-
declaration.get("init").replaceWith(reactiveObject(value, internal, idName()));
|
|
838
|
+
declaration.get("init").replaceWith((0, lib_js_1.reactiveObject)(value, internal, idName()));
|
|
710
839
|
internal.stack.set(id.name, 3 /* VariableState.ReactiveObject */);
|
|
711
840
|
}
|
|
712
841
|
else {
|
|
713
842
|
throw declaration.buildCodeFrameError(`Vasille: reactiveObject requires object expression as argument`);
|
|
714
843
|
}
|
|
715
844
|
}
|
|
716
|
-
else if (calls(
|
|
845
|
+
else if ((0, call_js_1.calls)(initPath, ["arrayModel"], internal)) {
|
|
717
846
|
const value = init.arguments[0];
|
|
718
847
|
if (kind !== "const") {
|
|
719
848
|
throw declaration.buildCodeFrameError(`Vasille: Array models must be must be declared as constants`);
|
|
720
849
|
}
|
|
721
850
|
if (t.isArrayExpression(value)) {
|
|
722
|
-
declaration.get("init").replaceWith(arrayModel(value, internal, idName()));
|
|
851
|
+
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(value, internal, idName()));
|
|
723
852
|
}
|
|
724
853
|
else {
|
|
725
|
-
declaration.get("init").replaceWith(arrayModel(null, internal, idName()));
|
|
854
|
+
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(null, internal, idName()));
|
|
726
855
|
}
|
|
727
856
|
}
|
|
728
|
-
else if (calls(
|
|
857
|
+
else if ((callName = (0, call_js_1.calls)(initPath, ["mapModel", "setModel"], internal))) {
|
|
729
858
|
const args = init.arguments;
|
|
730
|
-
const name = calls(init, ["mapModel", "setModel"], internal);
|
|
731
859
|
if (kind !== "const") {
|
|
732
|
-
throw declaration.buildCodeFrameError(`Vasille: ${
|
|
860
|
+
throw declaration.buildCodeFrameError(`Vasille: ${callName === "mapModel" ? "Map" : "Set"} models must be declared as constants`);
|
|
733
861
|
}
|
|
734
862
|
declaration
|
|
735
863
|
.get("init")
|
|
736
|
-
.replaceWith(
|
|
864
|
+
.replaceWith(callName === "mapModel" ? (0, lib_js_1.mapModel)(args, internal, idName()) : (0, lib_js_1.setModel)(args, internal, idName()));
|
|
737
865
|
}
|
|
738
866
|
else if (t.isObjectExpression(init)) {
|
|
739
867
|
if (kind !== "const") {
|
|
740
868
|
throw declaration.buildCodeFrameError(`Vasille: Objects must be must be declared as constants`);
|
|
741
869
|
}
|
|
742
|
-
declaration.get("init").replaceWith(reactiveObject(init, internal, idName()));
|
|
870
|
+
declaration.get("init").replaceWith((0, lib_js_1.reactiveObject)(init, internal, idName()));
|
|
743
871
|
internal.stack.set(id.name, 3 /* VariableState.ReactiveObject */);
|
|
744
872
|
}
|
|
745
873
|
else if (t.isArrayExpression(init)) {
|
|
746
874
|
if (kind !== "const") {
|
|
747
875
|
throw declaration.buildCodeFrameError(`Vasille: Arrays must be must be declared as constants`);
|
|
748
876
|
}
|
|
749
|
-
declaration.get("init").replaceWith(arrayModel(init, internal, idName()));
|
|
877
|
+
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(init, internal, idName()));
|
|
750
878
|
}
|
|
751
879
|
else if (t.isNewExpression(init) && t.isIdentifier(init.callee)) {
|
|
752
880
|
if (init.callee.name === "Map" || init.callee.name === "Set") {
|
|
@@ -756,35 +884,49 @@ export function composeStatement(path, internal, isRoot) {
|
|
|
756
884
|
declaration
|
|
757
885
|
.get("init")
|
|
758
886
|
.replaceWith(init.callee.name === "Map"
|
|
759
|
-
? mapModel(init.arguments, internal, idName())
|
|
760
|
-
: setModel(init.arguments, internal, idName()));
|
|
887
|
+
? (0, lib_js_1.mapModel)(init.arguments, internal, idName())
|
|
888
|
+
: (0, lib_js_1.setModel)(init.arguments, internal, idName()));
|
|
761
889
|
}
|
|
762
890
|
}
|
|
763
891
|
else if (declares === 2 /* VariableState.Reactive */) {
|
|
764
|
-
const replaceWith = forwardOnlyExpr(declaration.get("init"), declaration.node.init, internal);
|
|
892
|
+
const replaceWith = (0, lib_js_1.forwardOnlyExpr)(declaration.get("init"), declaration.node.init, internal);
|
|
765
893
|
meshInit = !replaceWith;
|
|
766
894
|
internal.stack.set(id.name, replaceWith ? 4 /* VariableState.ReactivePointer */ : 2 /* VariableState.Reactive */);
|
|
767
895
|
declaration
|
|
768
896
|
.get("init")
|
|
769
|
-
.replaceWith(replaceWith ? own(replaceWith, internal, idName()) : ref(declaration.node.init, internal, idName()));
|
|
897
|
+
.replaceWith(replaceWith ? (0, lib_js_1.own)(replaceWith, internal, idName()) : (0, lib_js_1.ref)(declaration.node.init, internal, idName()));
|
|
770
898
|
}
|
|
771
899
|
else {
|
|
772
|
-
const replaceWith = exprCall(declaration.get("init"), declaration.node.init, internal, idName());
|
|
900
|
+
const replaceWith = (0, lib_js_1.exprCall)(declaration.get("init"), declaration.node.init, internal, idName());
|
|
773
901
|
if (replaceWith) {
|
|
774
902
|
declaration.get("init").replaceWith(replaceWith);
|
|
775
903
|
}
|
|
776
904
|
internal.stack.set(id.name, replaceWith
|
|
777
905
|
? 2 /* VariableState.Reactive */
|
|
778
|
-
: nodeIsReactiveObject(declaration.get("init"), internal)
|
|
906
|
+
: (0, expression_js_1.nodeIsReactiveObject)(declaration.get("init"), internal)
|
|
779
907
|
? 3 /* VariableState.ReactiveObject */
|
|
780
908
|
: 1 /* VariableState.Ignored */);
|
|
781
909
|
meshInit = !replaceWith;
|
|
782
910
|
}
|
|
783
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
|
+
}
|
|
784
923
|
if (meshInit) {
|
|
785
924
|
meshExpression(declaration.get("init"), internal);
|
|
786
925
|
}
|
|
787
926
|
}
|
|
927
|
+
if (switchToConst && (kind === "let" || kind === "var")) {
|
|
928
|
+
_path.node.kind = "const";
|
|
929
|
+
}
|
|
788
930
|
break;
|
|
789
931
|
}
|
|
790
932
|
case "WhileStatement": {
|
|
@@ -807,26 +949,50 @@ export function composeStatement(path, internal, isRoot) {
|
|
|
807
949
|
meshStatement(path, internal);
|
|
808
950
|
}
|
|
809
951
|
}
|
|
810
|
-
|
|
952
|
+
function compose(path, internal, isInternalSlot, composeMethod) {
|
|
811
953
|
internal.stack.push();
|
|
812
954
|
const node = path.node;
|
|
813
955
|
const params = node.params;
|
|
814
956
|
const body = node.body;
|
|
957
|
+
const argsNumber = composeArgsNumber[composeMethod];
|
|
815
958
|
if (t.isFunctionExpression(node) && node.id) {
|
|
816
959
|
internal.stack.set(node.id.name, 1 /* VariableState.Ignored */);
|
|
817
960
|
}
|
|
818
|
-
if (params.length >
|
|
819
|
-
throw path.get("params")[
|
|
961
|
+
if (params.length > argsNumber && !isInternalSlot) {
|
|
962
|
+
throw path.get("params")[argsNumber].buildCodeFrameError("Vasille: Extra parameters are not allowed");
|
|
820
963
|
}
|
|
964
|
+
const cumulativeFields = new Set();
|
|
965
|
+
const nonPropsFields = [];
|
|
966
|
+
let index = 0;
|
|
821
967
|
for (const param of path.get("params")) {
|
|
822
968
|
const node = param.node;
|
|
969
|
+
const isProps = index === composePropsIndex[composeMethod];
|
|
823
970
|
if (t.isAssignmentPattern(node)) {
|
|
824
971
|
throw param.buildCodeFrameError("Vasille: No default value allowed here");
|
|
825
972
|
}
|
|
826
|
-
if (
|
|
827
|
-
|
|
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
|
+
}
|
|
828
991
|
}
|
|
829
|
-
|
|
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)) {
|
|
830
996
|
ignoreObjectPattern(node, internal);
|
|
831
997
|
}
|
|
832
998
|
else if (t.isObjectPattern(node)) {
|
|
@@ -835,6 +1001,7 @@ export function compose(path, internal, isInternalSlot) {
|
|
|
835
1001
|
if (t.isObjectProperty(node)) {
|
|
836
1002
|
const key = node.key;
|
|
837
1003
|
let keyName = "";
|
|
1004
|
+
/* istanbul ignore else */
|
|
838
1005
|
if (t.isIdentifier(node.value)) {
|
|
839
1006
|
keyName = node.value.name;
|
|
840
1007
|
}
|
|
@@ -858,14 +1025,27 @@ export function compose(path, internal, isInternalSlot) {
|
|
|
858
1025
|
}
|
|
859
1026
|
}
|
|
860
1027
|
else {
|
|
861
|
-
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");
|
|
862
1029
|
}
|
|
1030
|
+
index++;
|
|
1031
|
+
}
|
|
1032
|
+
if (argsNumber !== 1) {
|
|
1033
|
+
node.params = [
|
|
1034
|
+
t.objectPattern([
|
|
1035
|
+
...params[0].properties,
|
|
1036
|
+
...params[1].properties,
|
|
1037
|
+
]),
|
|
1038
|
+
];
|
|
863
1039
|
}
|
|
1040
|
+
internal.isComposing = true;
|
|
1041
|
+
/* istanbul ignore else */
|
|
864
1042
|
if (t.isExpression(body)) {
|
|
865
1043
|
composeExpression(path.get("body"), internal, true);
|
|
866
1044
|
}
|
|
867
1045
|
else if (t.isBlockStatement(body)) {
|
|
868
1046
|
composeStatement(path.get("body"), internal, true);
|
|
869
1047
|
}
|
|
1048
|
+
internal.isComposing = false;
|
|
870
1049
|
internal.stack.pop();
|
|
1050
|
+
return nonPropsFields;
|
|
871
1051
|
}
|