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