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