babel-plugin-vasille 3.2.1 → 4.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 +5 -14
- package/lib/call.js +30 -30
- package/lib/css-transformer.js +42 -44
- package/lib/expression.js +116 -135
- package/lib/index.js +4 -1
- package/lib/internal.js +4 -19
- package/lib/jsx-detect.js +3 -54
- package/lib/jsx.js +244 -128
- package/lib/lib.js +103 -73
- package/lib/mesh.js +542 -494
- package/lib/order-check.js +48 -0
- package/lib/transformer.js +119 -79
- package/package.json +6 -7
- package/lib/bridge.js +0 -173
- package/lib-node/bridge.js +0 -173
- package/lib-node/call.js +0 -115
- package/lib-node/css-transformer.js +0 -248
- package/lib-node/expression.js +0 -600
- package/lib-node/index.js +0 -14
- package/lib-node/internal.js +0 -77
- package/lib-node/jsx-detect.js +0 -100
- package/lib-node/jsx.js +0 -453
- package/lib-node/lib.js +0 -159
- package/lib-node/mesh.js +0 -1051
- package/lib-node/router.js +0 -41
- package/lib-node/transformer.js +0 -150
- package/lib-node/utils.js +0 -50
package/lib-node/mesh.js
DELETED
|
@@ -1,1051 +0,0 @@
|
|
|
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) {
|
|
82
|
-
for (const path of nodePaths) {
|
|
83
|
-
/* istanbul ignore else */
|
|
84
|
-
if (t.isExpression(path.node)) {
|
|
85
|
-
meshExpression(path, internal);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function meshAllExpressions(nodePaths, internal) {
|
|
90
|
-
for (const path of nodePaths) {
|
|
91
|
-
meshExpression(path, internal);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function meshComposeCall(call, name, nodePath, method, internal) {
|
|
95
|
-
const arg = call.arguments[0];
|
|
96
|
-
if (call.arguments.length !== 1 || !(t.isFunctionExpression(arg) || t.isArrowFunctionExpression(arg))) {
|
|
97
|
-
throw nodePath.buildCodeFrameError("Vasille: Invalid arguments");
|
|
98
|
-
}
|
|
99
|
-
const fnPath = nodePath.get("arguments")[0];
|
|
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
|
-
}
|
|
104
|
-
if (!internal.stateOnly) {
|
|
105
|
-
arg.params.unshift(internal_js_1.ctx);
|
|
106
|
-
}
|
|
107
|
-
if (internal.devMode) {
|
|
108
|
-
call.arguments.push(t.stringLiteral(`${internal.prefix}:${name ? name.name : "#anonymouse"}`));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function meshAllUnknown(paths, internal) {
|
|
112
|
-
for (const path of paths) {
|
|
113
|
-
/* istanbul ignore else */
|
|
114
|
-
if (t.isSpreadElement(path.node)) {
|
|
115
|
-
meshExpression(path.get("argument"), internal);
|
|
116
|
-
}
|
|
117
|
-
else if (t.isExpression(path.node)) {
|
|
118
|
-
meshExpression(path, internal);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function meshLValue(path, internal) {
|
|
123
|
-
const node = path.node;
|
|
124
|
-
/* istanbul ignore else */
|
|
125
|
-
if (t.isExpression(node)) {
|
|
126
|
-
meshExpression(path, internal);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function meshOrIgnoreExpression(path, internal) {
|
|
130
|
-
/* istanbul ignore else */
|
|
131
|
-
if (t.isExpression(path.node)) {
|
|
132
|
-
meshExpression(path, internal);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
function meshExpression(nodePath, internal, isRoot) {
|
|
136
|
-
const expr = nodePath.node;
|
|
137
|
-
if (!expr) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
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);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
switch (expr.type) {
|
|
146
|
-
case "TemplateLiteral": {
|
|
147
|
-
const path = nodePath;
|
|
148
|
-
meshOrIgnoreAllExpressions(path.get("expressions"), internal);
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
case "TaggedTemplateExpression": {
|
|
152
|
-
const path = nodePath;
|
|
153
|
-
meshExpression(path.get("quasi"), internal);
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
case "Identifier": {
|
|
157
|
-
const state = internal.stack.get(expr.name);
|
|
158
|
-
if ((0, expression_js_1.idIsIValue)(nodePath, internal)) {
|
|
159
|
-
nodePath.replaceWith(t.memberExpression(expr, t.identifier(state === 4 /* VariableState.ReactivePointer */ ? "$$" : "$")));
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
case "ArrayExpression": {
|
|
164
|
-
const path = nodePath;
|
|
165
|
-
meshAllUnknown(path.get("elements"), internal);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case "CallExpression":
|
|
169
|
-
case "OptionalCallExpression": {
|
|
170
|
-
const path = nodePath;
|
|
171
|
-
if (internal.isComposing && (0, call_js_1.calls)(path, ["router"], internal)) {
|
|
172
|
-
if (!internal.stateOnly) {
|
|
173
|
-
(0, router_1.routerReplace)(path);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
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);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
case "AssignmentExpression": {
|
|
196
|
-
const path = nodePath;
|
|
197
|
-
const left = path.node.left;
|
|
198
|
-
let replaced = false;
|
|
199
|
-
meshLValue(path.get("left"), internal);
|
|
200
|
-
if (t.isIdentifier(left) && internal.stack.get(left.name) === 4 /* VariableState.ReactivePointer */) {
|
|
201
|
-
const replaceWith = (0, lib_js_1.forwardOnlyExpr)(path.get("right"), path.node.right, internal);
|
|
202
|
-
if (replaceWith) {
|
|
203
|
-
path.get("right").replaceWith(replaceWith);
|
|
204
|
-
replaced = true;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (!replaced) {
|
|
208
|
-
meshExpression(path.get("right"), internal);
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
case "MemberExpression":
|
|
213
|
-
case "OptionalMemberExpression": {
|
|
214
|
-
const path = nodePath;
|
|
215
|
-
const node = path.node;
|
|
216
|
-
const property = path.node.property;
|
|
217
|
-
meshExpression(path.get("object"), internal);
|
|
218
|
-
if (t.isExpression(property) && !t.isIdentifier(property)) {
|
|
219
|
-
meshOrIgnoreExpression(path.get("property"), internal);
|
|
220
|
-
}
|
|
221
|
-
if ((0, expression_js_1.memberIsIValue)(node, internal)) {
|
|
222
|
-
path.replaceWith(t.memberExpression(node, t.identifier("$")));
|
|
223
|
-
}
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
case "BinaryExpression": {
|
|
227
|
-
const path = nodePath;
|
|
228
|
-
meshOrIgnoreExpression(path.get("left"), internal);
|
|
229
|
-
meshExpression(path.get("right"), internal);
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
case "ConditionalExpression": {
|
|
233
|
-
const path = nodePath;
|
|
234
|
-
meshExpression(path.get("test"), internal);
|
|
235
|
-
meshExpression(path.get("consequent"), internal);
|
|
236
|
-
meshExpression(path.get("alternate"), internal);
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
case "LogicalExpression": {
|
|
240
|
-
const path = nodePath;
|
|
241
|
-
meshExpression(path.get("left"), internal);
|
|
242
|
-
meshExpression(path.get("right"), internal);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
case "NewExpression": {
|
|
246
|
-
const path = nodePath;
|
|
247
|
-
meshOrIgnoreExpression(path.get("callee"), internal);
|
|
248
|
-
meshAllUnknown(path.get("arguments"), internal);
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
case "SequenceExpression": {
|
|
252
|
-
const path = nodePath;
|
|
253
|
-
meshAllExpressions(path.get("expressions"), internal);
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
case "UnaryExpression": {
|
|
257
|
-
const path = nodePath;
|
|
258
|
-
meshExpression(path.get("argument"), internal);
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
case "UpdateExpression": {
|
|
262
|
-
const path = nodePath;
|
|
263
|
-
meshExpression(path.get("argument"), internal);
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
case "YieldExpression": {
|
|
267
|
-
const path = nodePath;
|
|
268
|
-
meshExpression(path.get("argument"), internal);
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
case "AwaitExpression": {
|
|
272
|
-
const path = nodePath;
|
|
273
|
-
meshExpression(path.get("argument"), internal);
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case "TSInstantiationExpression": {
|
|
277
|
-
const path = nodePath;
|
|
278
|
-
meshExpression(path.get("expression"), internal);
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
case "TSAsExpression": {
|
|
282
|
-
const path = nodePath;
|
|
283
|
-
meshExpression(path.get("expression"), internal);
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
case "TSSatisfiesExpression": {
|
|
287
|
-
const path = nodePath;
|
|
288
|
-
meshExpression(path.get("expression"), internal);
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
case "TSTypeAssertion": {
|
|
292
|
-
const path = nodePath;
|
|
293
|
-
meshExpression(path.get("expression"), internal);
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
case "ObjectExpression": {
|
|
297
|
-
const path = nodePath;
|
|
298
|
-
for (const propPath of path.get("properties")) {
|
|
299
|
-
const prop = propPath.node;
|
|
300
|
-
if (t.isObjectProperty(prop)) {
|
|
301
|
-
const path = propPath;
|
|
302
|
-
const valuePath = path.get("value");
|
|
303
|
-
let replaced = false;
|
|
304
|
-
if (isRoot &&
|
|
305
|
-
internal.stateOnly &&
|
|
306
|
-
(!path.node.computed || t.isStringLiteral(path.node.key)) &&
|
|
307
|
-
(t.isIdentifier(path.node.key) || t.isStringLiteral(path.node.key)) &&
|
|
308
|
-
t.isExpression(valuePath.node)) {
|
|
309
|
-
const call = (0, lib_js_1.exprCall)(valuePath, valuePath.node, internal);
|
|
310
|
-
if (call) {
|
|
311
|
-
if ((0, utils_1.stringify)(path.node.key).startsWith("$")) {
|
|
312
|
-
valuePath.replaceWith(call);
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
throw path.buildCodeFrameError("Vasille: Reactive value property name must start with $");
|
|
316
|
-
}
|
|
317
|
-
replaced = true;
|
|
318
|
-
}
|
|
319
|
-
else if (t.isIdentifier(valuePath.node) &&
|
|
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");
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (!replaced) {
|
|
330
|
-
meshOrIgnoreExpression(valuePath, internal);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
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
|
-
}
|
|
337
|
-
meshFunction(propPath, internal);
|
|
338
|
-
}
|
|
339
|
-
else if (isRoot && internal.stateOnly && t.isSpreadElement(prop)) {
|
|
340
|
-
throw propPath.buildCodeFrameError("Vasille: Spread element is not allowed here");
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
meshAllUnknown([propPath], internal);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
case "FunctionExpression": {
|
|
349
|
-
meshFunction(nodePath, internal);
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
case "ArrowFunctionExpression": {
|
|
353
|
-
meshFunction(nodePath, internal);
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
case "ClassExpression": {
|
|
357
|
-
meshClassBody(nodePath.get("body"), internal);
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
case "JSXFragment": {
|
|
361
|
-
throw nodePath.buildCodeFrameError("Vasille: JSX fragment is not allowed here");
|
|
362
|
-
}
|
|
363
|
-
case "JSXElement": {
|
|
364
|
-
throw nodePath.buildCodeFrameError("Vasille: JSX element is not allowed here");
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
function meshStatements(paths, internal) {
|
|
369
|
-
for (const path of paths) {
|
|
370
|
-
meshStatement(path, internal);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function ignoreParams(val, internal) {
|
|
374
|
-
/* istanbul ignore else */
|
|
375
|
-
if (t.isAssignmentPattern(val)) {
|
|
376
|
-
val = val.left;
|
|
377
|
-
}
|
|
378
|
-
/* istanbul ignore else */
|
|
379
|
-
if (t.isIdentifier(val)) {
|
|
380
|
-
internal.stack.set(val.name, 1 /* VariableState.Ignored */);
|
|
381
|
-
}
|
|
382
|
-
else if (t.isObjectPattern(val)) {
|
|
383
|
-
ignoreObjectPattern(val, internal);
|
|
384
|
-
}
|
|
385
|
-
else if (t.isArrayPattern(val)) {
|
|
386
|
-
for (const element of val.elements) {
|
|
387
|
-
if (element) {
|
|
388
|
-
ignoreParams(element, internal);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function ignoreObjectPattern(pattern, internal) {
|
|
394
|
-
for (const property of pattern.properties) {
|
|
395
|
-
/* istanbul ignore else */
|
|
396
|
-
if (t.isObjectProperty(property)) {
|
|
397
|
-
/* istanbul ignore else */
|
|
398
|
-
if (t.isObjectPattern(property.value)) {
|
|
399
|
-
ignoreObjectPattern(property.value, internal);
|
|
400
|
-
}
|
|
401
|
-
else if (t.isAssignmentPattern(property.value)) {
|
|
402
|
-
ignoreParams(property.value, internal);
|
|
403
|
-
}
|
|
404
|
-
else if (t.isIdentifier(property.value)) {
|
|
405
|
-
internal.stack.set(property.value.name, 1 /* VariableState.Ignored */);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
/* istanbul ignore else */
|
|
409
|
-
if (t.isRestElement(property)) {
|
|
410
|
-
internal.stack.set(property.argument.name, 1 /* VariableState.Ignored */);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
function reactiveArrayPattern(path, internal) {
|
|
415
|
-
if (t.isArrayPattern(path.node)) {
|
|
416
|
-
path.node.elements.forEach((element, index) => {
|
|
417
|
-
/* istanbul ignore else */
|
|
418
|
-
if (t.isIdentifier(element)) {
|
|
419
|
-
internal.stack.set(element.name, index < 2 ? 2 /* VariableState.Reactive */ : 1 /* VariableState.Ignored */);
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
throw path.buildCodeFrameError("Vasille: Expected array pattern");
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
function meshForEachHeader(path, internal) {
|
|
428
|
-
const left = path.node.left;
|
|
429
|
-
meshExpression(path.get("right"), internal);
|
|
430
|
-
/* istanbul ignore else */
|
|
431
|
-
if (t.isVariableDeclaration(left) && t.isVariableDeclarator(left.declarations[0])) {
|
|
432
|
-
ignoreParams(left.declarations[0].id, internal);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
function meshForHeader(path, internal) {
|
|
436
|
-
const node = path.node;
|
|
437
|
-
/* istanbul ignore else */
|
|
438
|
-
if (node.init) {
|
|
439
|
-
if (t.isExpression(node.init)) {
|
|
440
|
-
meshExpression(path.get("init"), internal);
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
const variablePath = path.get("init");
|
|
444
|
-
for (const declarationPath of variablePath.get("declarations")) {
|
|
445
|
-
meshExpression(declarationPath.get("init"), internal);
|
|
446
|
-
ignoreParams(declarationPath.node.id, internal);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
meshExpression(path.get("test"), internal);
|
|
451
|
-
meshExpression(path.get("update"), internal);
|
|
452
|
-
}
|
|
453
|
-
function meshClassBody(path, internal) {
|
|
454
|
-
for (const item of path.get("body")) {
|
|
455
|
-
/* istanbul ignore else */
|
|
456
|
-
if (t.isClassMethod(item.node) || t.isClassPrivateMethod(item.node)) {
|
|
457
|
-
meshFunction(item, internal);
|
|
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
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function meshStatement(path, internal) {
|
|
467
|
-
const statement = path.node;
|
|
468
|
-
switch (statement && statement.type) {
|
|
469
|
-
case "BlockStatement":
|
|
470
|
-
internal.stack.push();
|
|
471
|
-
meshStatements(path.get("body"), internal);
|
|
472
|
-
internal.stack.pop();
|
|
473
|
-
break;
|
|
474
|
-
case "DoWhileStatement": {
|
|
475
|
-
const _path = path;
|
|
476
|
-
meshExpression(_path.get("test"), internal);
|
|
477
|
-
internal.stack.push();
|
|
478
|
-
meshStatement(_path.get("body"), internal);
|
|
479
|
-
internal.stack.pop();
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
case "ExpressionStatement":
|
|
483
|
-
meshExpression(path.get("expression"), internal);
|
|
484
|
-
break;
|
|
485
|
-
case "ForInStatement": {
|
|
486
|
-
const _path = path;
|
|
487
|
-
internal.stack.push();
|
|
488
|
-
meshForEachHeader(_path, internal);
|
|
489
|
-
meshStatement(_path.get("body"), internal);
|
|
490
|
-
internal.stack.pop();
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
case "ForOfStatement": {
|
|
494
|
-
const _path = path;
|
|
495
|
-
internal.stack.push();
|
|
496
|
-
meshForEachHeader(_path, internal);
|
|
497
|
-
meshStatement(_path.get("body"), internal);
|
|
498
|
-
internal.stack.pop();
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
case "ForStatement": {
|
|
502
|
-
const _path = path;
|
|
503
|
-
internal.stack.push();
|
|
504
|
-
meshForHeader(_path, internal);
|
|
505
|
-
meshStatement(_path.get("body"), internal);
|
|
506
|
-
internal.stack.pop();
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
case "FunctionDeclaration":
|
|
510
|
-
meshFunction(path, internal);
|
|
511
|
-
break;
|
|
512
|
-
case "IfStatement": {
|
|
513
|
-
const _path = path;
|
|
514
|
-
meshExpression(_path.get("test"), internal);
|
|
515
|
-
internal.stack.push();
|
|
516
|
-
meshStatement(_path.get("consequent"), internal);
|
|
517
|
-
internal.stack.pop();
|
|
518
|
-
internal.stack.push();
|
|
519
|
-
meshStatement(_path.get("alternate"), internal);
|
|
520
|
-
internal.stack.pop();
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
case "LabeledStatement":
|
|
524
|
-
meshStatement(path.get("body"), internal);
|
|
525
|
-
break;
|
|
526
|
-
case "ReturnStatement":
|
|
527
|
-
meshExpression(path.get("argument"), internal);
|
|
528
|
-
break;
|
|
529
|
-
case "SwitchStatement": {
|
|
530
|
-
const _path = path;
|
|
531
|
-
meshExpression(_path.get("discriminant"), internal);
|
|
532
|
-
internal.stack.push();
|
|
533
|
-
for (const _case of _path.get("cases")) {
|
|
534
|
-
meshExpression(_case.get("test"), internal);
|
|
535
|
-
meshStatements(_case.get("consequent"), internal);
|
|
536
|
-
}
|
|
537
|
-
internal.stack.pop();
|
|
538
|
-
break;
|
|
539
|
-
}
|
|
540
|
-
case "ThrowStatement":
|
|
541
|
-
meshExpression(path.get("argument"), internal);
|
|
542
|
-
break;
|
|
543
|
-
case "TryStatement":
|
|
544
|
-
meshStatement(path.get("block"), internal);
|
|
545
|
-
/* istanbul ignore else */
|
|
546
|
-
if (path.node.handler) {
|
|
547
|
-
meshStatement(path.get("handler").get("body"), internal);
|
|
548
|
-
}
|
|
549
|
-
meshStatement(path.get("finalizer"), internal);
|
|
550
|
-
break;
|
|
551
|
-
case "VariableDeclaration": {
|
|
552
|
-
const _path = path;
|
|
553
|
-
for (const declaration of _path.get("declarations")) {
|
|
554
|
-
const expr = declaration.node.init;
|
|
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);
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
meshExpression(declaration.get("init"), internal);
|
|
562
|
-
ignoreParams(declaration.node.id, internal);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
break;
|
|
566
|
-
}
|
|
567
|
-
case "WhileStatement": {
|
|
568
|
-
const _path = path;
|
|
569
|
-
meshExpression(_path.get("test"), internal);
|
|
570
|
-
internal.stack.push();
|
|
571
|
-
meshStatement(_path.get("body"), internal);
|
|
572
|
-
internal.stack.pop();
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
case "ExportNamedDeclaration": {
|
|
576
|
-
meshStatement(path.get("declaration"), internal);
|
|
577
|
-
break;
|
|
578
|
-
}
|
|
579
|
-
case "ClassDeclaration":
|
|
580
|
-
meshClassBody(path.get("body"), internal);
|
|
581
|
-
break;
|
|
582
|
-
case "ExportDefaultDeclaration": {
|
|
583
|
-
const declarationPath = path.get("declaration");
|
|
584
|
-
/* istanbul ignore else */
|
|
585
|
-
if (t.isExpression(declarationPath.node)) {
|
|
586
|
-
meshExpression(declarationPath, internal);
|
|
587
|
-
}
|
|
588
|
-
else if (t.isFunctionDeclaration(declarationPath.node)) {
|
|
589
|
-
meshFunction(declarationPath, internal);
|
|
590
|
-
}
|
|
591
|
-
else if (t.isClassDeclaration(declarationPath.node)) {
|
|
592
|
-
meshClassBody(declarationPath.get("body"), internal);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
function meshFunction(path, internal) {
|
|
598
|
-
if (t.isFunctionDeclaration(path.node) && path.node.id) {
|
|
599
|
-
internal.stack.set(path.node.id.name, 1 /* VariableState.Ignored */);
|
|
600
|
-
}
|
|
601
|
-
internal.stack.push();
|
|
602
|
-
const node = path.node;
|
|
603
|
-
if (t.isFunctionExpression(node) && node.id) {
|
|
604
|
-
internal.stack.set(node.id.name, 1 /* VariableState.Ignored */);
|
|
605
|
-
}
|
|
606
|
-
for (const param of node.params) {
|
|
607
|
-
ignoreParams(param, internal);
|
|
608
|
-
}
|
|
609
|
-
if (t.isExpression(node.body)) {
|
|
610
|
-
meshExpression(path.get("body"), internal);
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
const bodyPath = path.get("body");
|
|
614
|
-
meshStatement(bodyPath, internal);
|
|
615
|
-
}
|
|
616
|
-
internal.stack.pop();
|
|
617
|
-
}
|
|
618
|
-
function composeExpression(path, internal, isRoot) {
|
|
619
|
-
const expr = path.node;
|
|
620
|
-
switch (expr && expr.type) {
|
|
621
|
-
case "AssignmentExpression": {
|
|
622
|
-
meshExpression(path, internal);
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
case "CallExpression":
|
|
626
|
-
case "OptionalCallExpression": {
|
|
627
|
-
if ((0, call_js_1.calls)(path, ["watch"], internal)) {
|
|
628
|
-
const args = (0, lib_js_1.parseCalculateCall)(path, internal);
|
|
629
|
-
/* istanbul ignore else */
|
|
630
|
-
if (args) {
|
|
631
|
-
if (args[1].elements.length > 0) {
|
|
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));
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
path.replaceWith(t.callExpression(args[0], []));
|
|
638
|
-
}
|
|
639
|
-
}
|
|
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
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
meshExpression(path, internal);
|
|
649
|
-
}
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
case "LogicalExpression":
|
|
653
|
-
composeExpression(path.get("left"), internal);
|
|
654
|
-
composeExpression(path.get("right"), internal);
|
|
655
|
-
break;
|
|
656
|
-
case "ConditionalExpression":
|
|
657
|
-
meshExpression(path.get("test"), internal);
|
|
658
|
-
composeExpression(path.get("consequent"), internal);
|
|
659
|
-
composeExpression(path.get("alternate"), internal);
|
|
660
|
-
break;
|
|
661
|
-
case "JSXElement":
|
|
662
|
-
case "JSXFragment":
|
|
663
|
-
if (internal.stateOnly) {
|
|
664
|
-
throw path.buildCodeFrameError("Vasille: JSX is not allowed in states");
|
|
665
|
-
}
|
|
666
|
-
path.replaceWithMultiple((0, jsx_js_1.transformJsx)(path, internal));
|
|
667
|
-
break;
|
|
668
|
-
default:
|
|
669
|
-
meshExpression(path, internal, isRoot);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
function composeStatements(paths, internal, isRoot) {
|
|
673
|
-
for (const path of paths) {
|
|
674
|
-
composeStatement(path, internal, isRoot);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
function composeStatement(path, internal, isRoot) {
|
|
678
|
-
const statement = path.node;
|
|
679
|
-
if (!statement) {
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
switch (statement.type) {
|
|
683
|
-
case "FunctionDeclaration": {
|
|
684
|
-
meshFunction(path, internal);
|
|
685
|
-
break;
|
|
686
|
-
}
|
|
687
|
-
case "BlockStatement": {
|
|
688
|
-
internal.stack.push();
|
|
689
|
-
composeStatements(path.get("body"), internal, isRoot);
|
|
690
|
-
internal.stack.pop();
|
|
691
|
-
break;
|
|
692
|
-
}
|
|
693
|
-
case "DoWhileStatement": {
|
|
694
|
-
const _path = path;
|
|
695
|
-
meshExpression(_path.get("test"), internal);
|
|
696
|
-
internal.stack.push();
|
|
697
|
-
composeStatement(_path.get("body"), internal);
|
|
698
|
-
internal.stack.pop();
|
|
699
|
-
break;
|
|
700
|
-
}
|
|
701
|
-
case "ExpressionStatement": {
|
|
702
|
-
composeExpression(path.get("expression"), internal);
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
case "ForInStatement": {
|
|
706
|
-
const _path = path;
|
|
707
|
-
internal.stack.push();
|
|
708
|
-
meshForEachHeader(_path, internal);
|
|
709
|
-
composeStatement(_path.get("body"), internal);
|
|
710
|
-
internal.stack.pop();
|
|
711
|
-
break;
|
|
712
|
-
}
|
|
713
|
-
case "ForStatement": {
|
|
714
|
-
const _path = path;
|
|
715
|
-
internal.stack.push();
|
|
716
|
-
meshForHeader(_path, internal);
|
|
717
|
-
composeStatement(_path.get("body"), internal);
|
|
718
|
-
internal.stack.pop();
|
|
719
|
-
break;
|
|
720
|
-
}
|
|
721
|
-
case "IfStatement": {
|
|
722
|
-
const _path = path;
|
|
723
|
-
meshExpression(_path.get("test"), internal);
|
|
724
|
-
internal.stack.push();
|
|
725
|
-
composeStatement(_path.get("consequent"), internal);
|
|
726
|
-
internal.stack.pop();
|
|
727
|
-
internal.stack.push();
|
|
728
|
-
composeStatement(_path.get("alternate"), internal);
|
|
729
|
-
internal.stack.pop();
|
|
730
|
-
break;
|
|
731
|
-
}
|
|
732
|
-
case "LabeledStatement":
|
|
733
|
-
composeStatement(path.get("body"), internal);
|
|
734
|
-
break;
|
|
735
|
-
case "ReturnStatement":
|
|
736
|
-
composeExpression(path.get("argument"), internal, isRoot);
|
|
737
|
-
break;
|
|
738
|
-
case "SwitchStatement": {
|
|
739
|
-
const _path = path;
|
|
740
|
-
meshExpression(_path.get("discriminant"), internal);
|
|
741
|
-
internal.stack.push();
|
|
742
|
-
for (const _case of _path.get("cases")) {
|
|
743
|
-
meshExpression(_case.get("test"), internal);
|
|
744
|
-
composeStatements(_case.get("consequent"), internal);
|
|
745
|
-
}
|
|
746
|
-
internal.stack.pop();
|
|
747
|
-
break;
|
|
748
|
-
}
|
|
749
|
-
case "TryStatement":
|
|
750
|
-
const tryHandler = path.get("handler");
|
|
751
|
-
composeStatement(path.get("block"), internal);
|
|
752
|
-
tryHandler.node && composeStatement(tryHandler.get("body"), internal);
|
|
753
|
-
composeStatement(path.get("finalizer"), internal);
|
|
754
|
-
break;
|
|
755
|
-
case "VariableDeclaration": {
|
|
756
|
-
const _path = path;
|
|
757
|
-
const kind = _path.node.kind;
|
|
758
|
-
const declares = kind === "const" ? 1 /* VariableState.Ignored */ : 2 /* VariableState.Reactive */;
|
|
759
|
-
let switchToConst = true;
|
|
760
|
-
for (const declaration of _path.get("declarations")) {
|
|
761
|
-
const id = declaration.node.id;
|
|
762
|
-
const bridgeMethod = (0, bridge_1.processBridgeCall)(declaration.get("init"), internal);
|
|
763
|
-
let meshInit = true;
|
|
764
|
-
function idName(target = id) {
|
|
765
|
-
let name = "#";
|
|
766
|
-
/* istanbul ignore else */
|
|
767
|
-
if (t.isIdentifier(target)) {
|
|
768
|
-
name = target.name;
|
|
769
|
-
}
|
|
770
|
-
return name;
|
|
771
|
-
}
|
|
772
|
-
function idDoubleName() {
|
|
773
|
-
const pattern = id;
|
|
774
|
-
return [idName(pattern.elements[0]), idName(pattern.elements[1])];
|
|
775
|
-
}
|
|
776
|
-
ignoreParams(declaration.node.id, internal);
|
|
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)) {
|
|
789
|
-
reactiveArrayPattern(declaration.get("id"), internal);
|
|
790
|
-
meshAllUnknown(declaration.get("init").get("arguments"), internal);
|
|
791
|
-
(0, lib_js_1.named)(declaration.node.init, idDoubleName(), internal);
|
|
792
|
-
meshInit = false;
|
|
793
|
-
}
|
|
794
|
-
else if (t.isIdentifier(id)) {
|
|
795
|
-
internal.stack.set(id.name, declares);
|
|
796
|
-
const init = declaration.node.init;
|
|
797
|
-
const initPath = declaration.get("init");
|
|
798
|
-
let callName = false;
|
|
799
|
-
if ((0, call_js_1.calls)(initPath, ["value"], internal)) {
|
|
800
|
-
internal.stack.set(id.name, 1 /* VariableState.Ignored */);
|
|
801
|
-
declaration.get("init").replaceWith(init.arguments[0]);
|
|
802
|
-
_path.node.kind = kind;
|
|
803
|
-
switchToConst = false;
|
|
804
|
-
}
|
|
805
|
-
else if ((0, call_js_1.calls)(initPath, ["bind"], internal)) {
|
|
806
|
-
const argument = init.arguments[0];
|
|
807
|
-
const argumentPath = declaration.get("init").get("arguments")[0];
|
|
808
|
-
let replaceWith = declares === 2 /* VariableState.Reactive */
|
|
809
|
-
? (0, lib_js_1.forwardOnlyExpr)(argumentPath, argument, internal)
|
|
810
|
-
: (0, lib_js_1.exprCall)(argumentPath, argument, internal, idName());
|
|
811
|
-
if (!replaceWith) {
|
|
812
|
-
replaceWith =
|
|
813
|
-
declares === 2 /* VariableState.Reactive */
|
|
814
|
-
? t.callExpression(t.memberExpression(internal.id, t.identifier("r")), [argument])
|
|
815
|
-
: (0, lib_js_1.ref)(argument, internal, idName());
|
|
816
|
-
}
|
|
817
|
-
if (declares === 2 /* VariableState.Reactive */) {
|
|
818
|
-
internal.stack.set(id.name, 4 /* VariableState.ReactivePointer */);
|
|
819
|
-
replaceWith = (0, lib_js_1.own)(replaceWith, internal, idName());
|
|
820
|
-
}
|
|
821
|
-
else {
|
|
822
|
-
internal.stack.set(id.name, 2 /* VariableState.Reactive */);
|
|
823
|
-
}
|
|
824
|
-
declaration.get("init").replaceWith(replaceWith);
|
|
825
|
-
meshInit = !replaceWith;
|
|
826
|
-
}
|
|
827
|
-
else if ((0, call_js_1.calls)(initPath, ["ref"], internal)) {
|
|
828
|
-
const argument = init.arguments[0];
|
|
829
|
-
internal.stack.set(id.name, 2 /* VariableState.Reactive */);
|
|
830
|
-
declaration.get("init").replaceWith((0, lib_js_1.ref)(t.isExpression(argument) ? argument : null, internal, idName()));
|
|
831
|
-
}
|
|
832
|
-
else if ((0, call_js_1.calls)(initPath, ["reactiveObject"], internal)) {
|
|
833
|
-
const value = init.arguments[0];
|
|
834
|
-
if (kind !== "const") {
|
|
835
|
-
throw declaration.buildCodeFrameError(`Vasille: Reactive objects must be must be declared as constants`);
|
|
836
|
-
}
|
|
837
|
-
if (t.isObjectExpression(value)) {
|
|
838
|
-
declaration.get("init").replaceWith((0, lib_js_1.reactiveObject)(value, internal, idName()));
|
|
839
|
-
internal.stack.set(id.name, 3 /* VariableState.ReactiveObject */);
|
|
840
|
-
}
|
|
841
|
-
else {
|
|
842
|
-
throw declaration.buildCodeFrameError(`Vasille: reactiveObject requires object expression as argument`);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
else if ((0, call_js_1.calls)(initPath, ["arrayModel"], internal)) {
|
|
846
|
-
const value = init.arguments[0];
|
|
847
|
-
if (kind !== "const") {
|
|
848
|
-
throw declaration.buildCodeFrameError(`Vasille: Array models must be must be declared as constants`);
|
|
849
|
-
}
|
|
850
|
-
if (t.isArrayExpression(value)) {
|
|
851
|
-
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(value, internal, idName()));
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(null, internal, idName()));
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
else if ((callName = (0, call_js_1.calls)(initPath, ["mapModel", "setModel"], internal))) {
|
|
858
|
-
const args = init.arguments;
|
|
859
|
-
if (kind !== "const") {
|
|
860
|
-
throw declaration.buildCodeFrameError(`Vasille: ${callName === "mapModel" ? "Map" : "Set"} models must be declared as constants`);
|
|
861
|
-
}
|
|
862
|
-
declaration
|
|
863
|
-
.get("init")
|
|
864
|
-
.replaceWith(callName === "mapModel" ? (0, lib_js_1.mapModel)(args, internal, idName()) : (0, lib_js_1.setModel)(args, internal, idName()));
|
|
865
|
-
}
|
|
866
|
-
else if (t.isObjectExpression(init)) {
|
|
867
|
-
if (kind !== "const") {
|
|
868
|
-
throw declaration.buildCodeFrameError(`Vasille: Objects must be must be declared as constants`);
|
|
869
|
-
}
|
|
870
|
-
declaration.get("init").replaceWith((0, lib_js_1.reactiveObject)(init, internal, idName()));
|
|
871
|
-
internal.stack.set(id.name, 3 /* VariableState.ReactiveObject */);
|
|
872
|
-
}
|
|
873
|
-
else if (t.isArrayExpression(init)) {
|
|
874
|
-
if (kind !== "const") {
|
|
875
|
-
throw declaration.buildCodeFrameError(`Vasille: Arrays must be must be declared as constants`);
|
|
876
|
-
}
|
|
877
|
-
declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(init, internal, idName()));
|
|
878
|
-
}
|
|
879
|
-
else if (t.isNewExpression(init) && t.isIdentifier(init.callee)) {
|
|
880
|
-
if (init.callee.name === "Map" || init.callee.name === "Set") {
|
|
881
|
-
if (kind !== "const") {
|
|
882
|
-
throw declaration.buildCodeFrameError(`Vasille: ${init.callee.name === "Map" ? "Maps" : "Sets"} must be declared as constants`);
|
|
883
|
-
}
|
|
884
|
-
declaration
|
|
885
|
-
.get("init")
|
|
886
|
-
.replaceWith(init.callee.name === "Map"
|
|
887
|
-
? (0, lib_js_1.mapModel)(init.arguments, internal, idName())
|
|
888
|
-
: (0, lib_js_1.setModel)(init.arguments, internal, idName()));
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
else if (declares === 2 /* VariableState.Reactive */) {
|
|
892
|
-
const replaceWith = (0, lib_js_1.forwardOnlyExpr)(declaration.get("init"), declaration.node.init, internal);
|
|
893
|
-
meshInit = !replaceWith;
|
|
894
|
-
internal.stack.set(id.name, replaceWith ? 4 /* VariableState.ReactivePointer */ : 2 /* VariableState.Reactive */);
|
|
895
|
-
declaration
|
|
896
|
-
.get("init")
|
|
897
|
-
.replaceWith(replaceWith ? (0, lib_js_1.own)(replaceWith, internal, idName()) : (0, lib_js_1.ref)(declaration.node.init, internal, idName()));
|
|
898
|
-
}
|
|
899
|
-
else {
|
|
900
|
-
const replaceWith = (0, lib_js_1.exprCall)(declaration.get("init"), declaration.node.init, internal, idName());
|
|
901
|
-
if (replaceWith) {
|
|
902
|
-
declaration.get("init").replaceWith(replaceWith);
|
|
903
|
-
}
|
|
904
|
-
internal.stack.set(id.name, replaceWith
|
|
905
|
-
? 2 /* VariableState.Reactive */
|
|
906
|
-
: (0, expression_js_1.nodeIsReactiveObject)(declaration.get("init"), internal)
|
|
907
|
-
? 3 /* VariableState.ReactiveObject */
|
|
908
|
-
: 1 /* VariableState.Ignored */);
|
|
909
|
-
meshInit = !replaceWith;
|
|
910
|
-
}
|
|
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
|
-
}
|
|
923
|
-
if (meshInit) {
|
|
924
|
-
meshExpression(declaration.get("init"), internal);
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
if (switchToConst && (kind === "let" || kind === "var")) {
|
|
928
|
-
_path.node.kind = "const";
|
|
929
|
-
}
|
|
930
|
-
break;
|
|
931
|
-
}
|
|
932
|
-
case "WhileStatement": {
|
|
933
|
-
const _path = path;
|
|
934
|
-
meshExpression(_path.get("test"), internal);
|
|
935
|
-
internal.stack.push();
|
|
936
|
-
composeStatement(_path.get("body"), internal);
|
|
937
|
-
internal.stack.pop();
|
|
938
|
-
break;
|
|
939
|
-
}
|
|
940
|
-
case "ForOfStatement": {
|
|
941
|
-
const _path = path;
|
|
942
|
-
internal.stack.push();
|
|
943
|
-
meshForEachHeader(_path, internal);
|
|
944
|
-
composeStatement(_path.get("body"), internal);
|
|
945
|
-
internal.stack.pop();
|
|
946
|
-
break;
|
|
947
|
-
}
|
|
948
|
-
default:
|
|
949
|
-
meshStatement(path, internal);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
function compose(path, internal, isInternalSlot, composeMethod) {
|
|
953
|
-
internal.stack.push();
|
|
954
|
-
const node = path.node;
|
|
955
|
-
const params = node.params;
|
|
956
|
-
const body = node.body;
|
|
957
|
-
const argsNumber = composeArgsNumber[composeMethod];
|
|
958
|
-
if (t.isFunctionExpression(node) && node.id) {
|
|
959
|
-
internal.stack.set(node.id.name, 1 /* VariableState.Ignored */);
|
|
960
|
-
}
|
|
961
|
-
if (params.length > argsNumber && !isInternalSlot) {
|
|
962
|
-
throw path.get("params")[argsNumber].buildCodeFrameError("Vasille: Extra parameters are not allowed");
|
|
963
|
-
}
|
|
964
|
-
const cumulativeFields = new Set();
|
|
965
|
-
const nonPropsFields = [];
|
|
966
|
-
let index = 0;
|
|
967
|
-
for (const param of path.get("params")) {
|
|
968
|
-
const node = param.node;
|
|
969
|
-
const isProps = index === composePropsIndex[composeMethod];
|
|
970
|
-
if (t.isAssignmentPattern(node)) {
|
|
971
|
-
throw param.buildCodeFrameError("Vasille: No default value allowed here");
|
|
972
|
-
}
|
|
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
|
-
}
|
|
991
|
-
}
|
|
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)) {
|
|
996
|
-
ignoreObjectPattern(node, internal);
|
|
997
|
-
}
|
|
998
|
-
else if (t.isObjectPattern(node)) {
|
|
999
|
-
for (const prop of param.get("properties")) {
|
|
1000
|
-
const node = prop.node;
|
|
1001
|
-
if (t.isObjectProperty(node)) {
|
|
1002
|
-
const key = node.key;
|
|
1003
|
-
let keyName = "";
|
|
1004
|
-
/* istanbul ignore else */
|
|
1005
|
-
if (t.isIdentifier(node.value)) {
|
|
1006
|
-
keyName = node.value.name;
|
|
1007
|
-
}
|
|
1008
|
-
else if (t.isIdentifier(key) && !node.computed) {
|
|
1009
|
-
keyName = key.name;
|
|
1010
|
-
}
|
|
1011
|
-
internal.stack.set(keyName, 2 /* VariableState.Reactive */);
|
|
1012
|
-
if (t.isAssignmentPattern(node.value)) {
|
|
1013
|
-
const assignPath = prop.get("value");
|
|
1014
|
-
assignPath
|
|
1015
|
-
.get("right")
|
|
1016
|
-
.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier("r")), [assignPath.node.right]));
|
|
1017
|
-
}
|
|
1018
|
-
else if (!t.isIdentifier(node.value)) {
|
|
1019
|
-
throw prop.buildCodeFrameError("Vasille: Value decomposition is not allowed here");
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
if (t.isRestElement(node)) {
|
|
1023
|
-
internal.stack.set(node.argument.name, 3 /* VariableState.ReactiveObject */);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
else {
|
|
1028
|
-
throw param.buildCodeFrameError(argsNumber === 1 ? "Vasille: Expected identifier or object pattern" : "Vasille: Expected object pattern here");
|
|
1029
|
-
}
|
|
1030
|
-
index++;
|
|
1031
|
-
}
|
|
1032
|
-
if (argsNumber !== 1) {
|
|
1033
|
-
node.params = [
|
|
1034
|
-
t.objectPattern([
|
|
1035
|
-
...params[0].properties,
|
|
1036
|
-
...params[1].properties,
|
|
1037
|
-
]),
|
|
1038
|
-
];
|
|
1039
|
-
}
|
|
1040
|
-
internal.isComposing = true;
|
|
1041
|
-
/* istanbul ignore else */
|
|
1042
|
-
if (t.isExpression(body)) {
|
|
1043
|
-
composeExpression(path.get("body"), internal, true);
|
|
1044
|
-
}
|
|
1045
|
-
else if (t.isBlockStatement(body)) {
|
|
1046
|
-
composeStatement(path.get("body"), internal, true);
|
|
1047
|
-
}
|
|
1048
|
-
internal.isComposing = false;
|
|
1049
|
-
internal.stack.pop();
|
|
1050
|
-
return nonPropsFields;
|
|
1051
|
-
}
|