babel-plugin-vasille 0.99.1 → 0.99.2
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 +1 -1
- package/lib/call.js +35 -8
- package/lib/expression.js +48 -13
- package/lib/index.js +6 -3
- package/lib/internal.js +30 -3
- package/lib/jsx-detect.js +32 -4
- package/lib/jsx.js +114 -49
- package/lib/lib.js +65 -31
- package/lib/mesh.js +104 -62
- package/lib/transformer.js +36 -7
- package/lib-node/call.js +3 -3
- package/lib-node/expression.js +2 -2
- package/lib-node/index.js +2 -2
- package/lib-node/jsx.js +84 -46
- package/lib-node/lib.js +21 -21
- package/lib-node/mesh.js +44 -44
- package/lib-node/transformer.js +8 -5
- package/package.json +2 -2
package/lib-node/call.js
CHANGED
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.requiresContext = exports.composeOnly = void 0;
|
|
27
27
|
exports.calls = calls;
|
|
28
28
|
const t = __importStar(require("@babel/types"));
|
|
29
|
-
const
|
|
29
|
+
const internal_1 = require("./internal");
|
|
30
30
|
exports.composeOnly = [
|
|
31
31
|
"forward",
|
|
32
32
|
"watch",
|
|
@@ -48,7 +48,7 @@ function calls(node, names, internal) {
|
|
|
48
48
|
const mapped = internal.mapping.get(callee.name);
|
|
49
49
|
if (mapped && set.has(mapped) && internal.stack.get(callee.name) === undefined) {
|
|
50
50
|
if (requiresContextSet.has(callee.name) && t.isCallExpression(node)) {
|
|
51
|
-
node.arguments.unshift(
|
|
51
|
+
node.arguments.unshift(internal_1.ctx);
|
|
52
52
|
}
|
|
53
53
|
return mapped;
|
|
54
54
|
}
|
|
@@ -68,7 +68,7 @@ function calls(node, names, internal) {
|
|
|
68
68
|
if (t.isMemberExpression(callee) && t.isIdentifier(callee.object) && propName) {
|
|
69
69
|
if (callee.object.name === internal.global && set.has(propName)) {
|
|
70
70
|
if (requiresContextSet.has(callee.object.name) && t.isCallExpression(node)) {
|
|
71
|
-
node.arguments.unshift(
|
|
71
|
+
node.arguments.unshift(internal_1.ctx);
|
|
72
72
|
}
|
|
73
73
|
return callee.object.name;
|
|
74
74
|
}
|
package/lib-node/expression.js
CHANGED
|
@@ -34,7 +34,7 @@ exports.checkStatements = checkStatements;
|
|
|
34
34
|
exports.checkStatement = checkStatement;
|
|
35
35
|
exports.checkFunction = checkFunction;
|
|
36
36
|
const t = __importStar(require("@babel/types"));
|
|
37
|
-
const
|
|
37
|
+
const internal_1 = require("./internal");
|
|
38
38
|
function encodeName(name) {
|
|
39
39
|
return t.identifier(`Vasille_${name}`);
|
|
40
40
|
}
|
|
@@ -124,7 +124,7 @@ function checkNode(path, internal) {
|
|
|
124
124
|
external: internal,
|
|
125
125
|
found: new Map(),
|
|
126
126
|
self: null,
|
|
127
|
-
stack: new
|
|
127
|
+
stack: new internal_1.StackedStates(),
|
|
128
128
|
};
|
|
129
129
|
if (t.isIdentifier(path.node)) {
|
|
130
130
|
const state = internal.stack.get(path.node.name);
|
package/lib-node/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = default_1;
|
|
4
|
-
const
|
|
4
|
+
const transformer_1 = require("./transformer");
|
|
5
5
|
function default_1() {
|
|
6
6
|
return {
|
|
7
7
|
name: "Vasille",
|
|
8
8
|
visitor: {
|
|
9
9
|
Program(path, params) {
|
|
10
|
-
(0,
|
|
10
|
+
(0, transformer_1.trProgram)(path, params.opts.devMode !== false);
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
};
|
package/lib-node/jsx.js
CHANGED
|
@@ -26,10 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.transformJsx = transformJsx;
|
|
27
27
|
exports.transformJsxArray = transformJsxArray;
|
|
28
28
|
const t = __importStar(require("@babel/types"));
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
29
|
+
const internal_1 = require("./internal");
|
|
30
|
+
const lib_1 = require("./lib");
|
|
31
|
+
const mesh_1 = require("./mesh");
|
|
32
|
+
const jsx_detect_1 = require("./jsx-detect");
|
|
33
33
|
function transformJsx(path, internal) {
|
|
34
34
|
if (t.isJSXElement(path.node)) {
|
|
35
35
|
return [transformJsxElement(path, internal)];
|
|
@@ -48,12 +48,31 @@ function transformJsxArray(paths, internal) {
|
|
|
48
48
|
.replace(/\n\s+$/m, "")
|
|
49
49
|
.replace(/^\s*\n\s+/m, "")
|
|
50
50
|
.replace(/\s*\n\s*/gm, "\n");
|
|
51
|
-
|
|
51
|
+
const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)]);
|
|
52
|
+
call.loc = path.node.loc;
|
|
53
|
+
if (call.loc) {
|
|
54
|
+
for (const char of path.node.value) {
|
|
55
|
+
if (!/\s/.test(char)) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (char === "\n") {
|
|
59
|
+
call.loc.start.column = 0;
|
|
60
|
+
call.loc.start.line++;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
call.loc.start.column++;
|
|
64
|
+
}
|
|
65
|
+
call.loc.start.index++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
result.push(t.expressionStatement(call));
|
|
52
69
|
}
|
|
53
70
|
}
|
|
54
71
|
else if (t.isJSXExpressionContainer(path.node)) {
|
|
55
72
|
const value = transformJsxExpressionContainer(path, internal, false, false);
|
|
56
|
-
|
|
73
|
+
const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("text")), [value]);
|
|
74
|
+
call.loc = value.loc;
|
|
75
|
+
result.push(t.expressionStatement(call));
|
|
57
76
|
}
|
|
58
77
|
else {
|
|
59
78
|
throw path.buildCodeFrameError("Vasille: Spread child is not supported");
|
|
@@ -65,40 +84,51 @@ function transformJsxExpressionContainer(path, internal, acceptSlots, isInternal
|
|
|
65
84
|
if (!t.isExpression(path.node.expression)) {
|
|
66
85
|
return t.booleanLiteral(true);
|
|
67
86
|
}
|
|
87
|
+
const loc = path.node.expression.loc;
|
|
68
88
|
if (acceptSlots &&
|
|
69
89
|
(t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression)) &&
|
|
70
|
-
(0,
|
|
71
|
-
(0,
|
|
90
|
+
(0, jsx_detect_1.bodyHasJsx)(path.node.expression.body)) {
|
|
91
|
+
(0, mesh_1.compose)(path.get("expression"), internal, isInternalSlot);
|
|
72
92
|
if (!isInternalSlot) {
|
|
73
93
|
if (path.node.expression.params.length < 1) {
|
|
74
94
|
path.node.expression.params.push(t.identifier(internal.prefix));
|
|
75
95
|
}
|
|
76
|
-
path.node.expression.params.push(
|
|
96
|
+
path.node.expression.params.push(internal_1.ctx);
|
|
77
97
|
}
|
|
78
98
|
else {
|
|
79
|
-
path.node.expression.params.unshift(
|
|
99
|
+
path.node.expression.params.unshift(internal_1.ctx);
|
|
80
100
|
}
|
|
101
|
+
path.node.expression.loc = loc;
|
|
81
102
|
return path.node.expression;
|
|
82
103
|
}
|
|
83
104
|
else if (isInternalSlot &&
|
|
84
105
|
(t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression))) {
|
|
85
|
-
path.node.expression.params.unshift(
|
|
106
|
+
path.node.expression.params.unshift(internal_1.ctx);
|
|
86
107
|
}
|
|
87
|
-
let call = (0,
|
|
108
|
+
let call = (0, lib_1.exprCall)(path.get("expression"), path.node.expression, internal);
|
|
88
109
|
if (!call &&
|
|
89
110
|
t.isIdentifier(path.node.expression) &&
|
|
90
111
|
internal.stack.get(path.node.expression.name) === 3 /* VariableState.ReactiveObject */) {
|
|
91
112
|
call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [path.node.expression]);
|
|
92
113
|
}
|
|
93
|
-
|
|
114
|
+
const result = call !== null && call !== void 0 ? call : path.node.expression;
|
|
115
|
+
result.loc = loc;
|
|
116
|
+
return result;
|
|
94
117
|
}
|
|
95
|
-
function id
|
|
118
|
+
function idToProp(id, value, from) {
|
|
119
|
+
let str = t.isIdentifier(id) || t.isJSXIdentifier(id) ? id.name : id.value;
|
|
120
|
+
let expr;
|
|
121
|
+
if (from) {
|
|
122
|
+
str = str.substring(from);
|
|
123
|
+
}
|
|
96
124
|
if (/^[\w_]+$/.test(str)) {
|
|
97
|
-
|
|
125
|
+
expr = t.identifier(str);
|
|
98
126
|
}
|
|
99
127
|
else {
|
|
100
|
-
|
|
128
|
+
expr = t.stringLiteral(str);
|
|
101
129
|
}
|
|
130
|
+
expr.loc = id.loc;
|
|
131
|
+
return t.objectProperty(expr, value);
|
|
102
132
|
}
|
|
103
133
|
function transformJsxElement(path, internal) {
|
|
104
134
|
var _a, _b;
|
|
@@ -122,9 +152,9 @@ function transformJsxElement(path, internal) {
|
|
|
122
152
|
if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
|
|
123
153
|
const path = attrPath.get("value");
|
|
124
154
|
if (t.isExpression(path.node.expression)) {
|
|
125
|
-
(0,
|
|
155
|
+
(0, mesh_1.meshExpression)(path.get("expression"), internal);
|
|
126
156
|
}
|
|
127
|
-
events.push(
|
|
157
|
+
events.push(idToProp(name, path.node.expression, 2));
|
|
128
158
|
}
|
|
129
159
|
else {
|
|
130
160
|
throw attrPath
|
|
@@ -142,8 +172,8 @@ function transformJsxElement(path, internal) {
|
|
|
142
172
|
if (t.isExpression(item)) {
|
|
143
173
|
// class={[cond && "string"]}
|
|
144
174
|
if (t.isLogicalExpression(item) && item.operator === "&&" && t.isStringLiteral(item.right)) {
|
|
145
|
-
const call = (0,
|
|
146
|
-
classObject.push(
|
|
175
|
+
const call = (0, lib_1.exprCall)(elementPath.get("left"), item.left, internal);
|
|
176
|
+
classObject.push(idToProp(item.right, call !== null && call !== void 0 ? call : item.left));
|
|
147
177
|
}
|
|
148
178
|
// class={[{..}]}
|
|
149
179
|
else if (t.isObjectExpression(item)) {
|
|
@@ -151,9 +181,9 @@ function transformJsxElement(path, internal) {
|
|
|
151
181
|
// class={[{a: b}]}
|
|
152
182
|
if (t.isObjectProperty(propPath.node)) {
|
|
153
183
|
const prop = propPath;
|
|
154
|
-
const value = (_a = (0,
|
|
184
|
+
const value = (_a = (0, lib_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
|
|
155
185
|
if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
|
|
156
|
-
(0,
|
|
186
|
+
(0, mesh_1.meshExpression)(prop.get("key"), internal);
|
|
157
187
|
}
|
|
158
188
|
classObject.push(t.objectProperty(prop.node.key, value));
|
|
159
189
|
}
|
|
@@ -169,11 +199,11 @@ function transformJsxElement(path, internal) {
|
|
|
169
199
|
}
|
|
170
200
|
// class={[".."]}
|
|
171
201
|
else if (t.isStringLiteral(elementPath.node)) {
|
|
172
|
-
classStatic.push(elementPath.node
|
|
202
|
+
classStatic.push(elementPath.node);
|
|
173
203
|
}
|
|
174
204
|
// class={[..]}
|
|
175
205
|
else {
|
|
176
|
-
const call = (0,
|
|
206
|
+
const call = (0, lib_1.exprCall)(elementPath, item, internal);
|
|
177
207
|
classElements.push(call !== null && call !== void 0 ? call : item);
|
|
178
208
|
}
|
|
179
209
|
}
|
|
@@ -191,7 +221,7 @@ function transformJsxElement(path, internal) {
|
|
|
191
221
|
else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
|
|
192
222
|
const jsxAttrPath = attrPath;
|
|
193
223
|
const jsxContainerPath = jsxAttrPath.get("value");
|
|
194
|
-
const value = (0,
|
|
224
|
+
const value = (0, lib_1.exprCall)(jsxContainerPath.get("expression"), attr.value.expression, internal);
|
|
195
225
|
attrs.push(t.objectProperty(t.identifier("class"), value !== null && value !== void 0 ? value : attr.value.expression));
|
|
196
226
|
if (value) {
|
|
197
227
|
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
@@ -199,10 +229,7 @@ function transformJsxElement(path, internal) {
|
|
|
199
229
|
}
|
|
200
230
|
// class="a b"
|
|
201
231
|
else if (t.isStringLiteral(attr.value)) {
|
|
202
|
-
|
|
203
|
-
for (const item of splitted) {
|
|
204
|
-
classStatic.push(item);
|
|
205
|
-
}
|
|
232
|
+
classStatic.push(attr.value);
|
|
206
233
|
}
|
|
207
234
|
// class=<div/>
|
|
208
235
|
else {
|
|
@@ -218,9 +245,9 @@ function transformJsxElement(path, internal) {
|
|
|
218
245
|
// style={{a: b}}
|
|
219
246
|
if (t.isObjectProperty(propPath.node)) {
|
|
220
247
|
const prop = propPath;
|
|
221
|
-
const value = (_b = (0,
|
|
248
|
+
const value = (_b = (0, lib_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
|
|
222
249
|
if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
|
|
223
|
-
(0,
|
|
250
|
+
(0, mesh_1.meshExpression)(prop.get("key"), internal);
|
|
224
251
|
}
|
|
225
252
|
// style={{a: "b"}} -> static in compile time
|
|
226
253
|
if (t.isIdentifier(prop.node.key) && t.isStringLiteral(prop.node.value)) {
|
|
@@ -267,7 +294,7 @@ function transformJsxElement(path, internal) {
|
|
|
267
294
|
const jsxAttrPath = attrPath;
|
|
268
295
|
const jsxContainerPath = jsxAttrPath.get("value");
|
|
269
296
|
const literalPath = jsxContainerPath.get("expression");
|
|
270
|
-
const value = (0,
|
|
297
|
+
const value = (0, lib_1.exprCall)(literalPath, attr.value.expression, internal);
|
|
271
298
|
attrs.push(t.objectProperty(t.identifier("style"), value !== null && value !== void 0 ? value : attr.value.expression));
|
|
272
299
|
if (value) {
|
|
273
300
|
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
@@ -280,10 +307,10 @@ function transformJsxElement(path, internal) {
|
|
|
280
307
|
}
|
|
281
308
|
else {
|
|
282
309
|
if (t.isJSXExpressionContainer(attr.value)) {
|
|
283
|
-
attrs.push(
|
|
310
|
+
attrs.push(idToProp(name, t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true)));
|
|
284
311
|
}
|
|
285
312
|
else if (t.isStringLiteral(attr.value)) {
|
|
286
|
-
attrs.push(
|
|
313
|
+
attrs.push(idToProp(name, attr.value));
|
|
287
314
|
}
|
|
288
315
|
else {
|
|
289
316
|
throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
|
|
@@ -294,12 +321,12 @@ function transformJsxElement(path, internal) {
|
|
|
294
321
|
if (name.namespace.name === "bind") {
|
|
295
322
|
if (t.isJSXExpressionContainer(attr.value)) {
|
|
296
323
|
const value = t.isExpression(attr.value.expression)
|
|
297
|
-
? (0,
|
|
324
|
+
? (0, lib_1.exprCall)(attrPath.get("value"), attr.value.expression, internal)
|
|
298
325
|
: undefined;
|
|
299
|
-
bind.push(
|
|
326
|
+
bind.push(idToProp(name.name, value !== null && value !== void 0 ? value : (t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true))));
|
|
300
327
|
}
|
|
301
328
|
else if (t.isStringLiteral(attr.value)) {
|
|
302
|
-
bind.push(
|
|
329
|
+
bind.push(idToProp(name.name, attr.value));
|
|
303
330
|
}
|
|
304
331
|
else {
|
|
305
332
|
throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
|
|
@@ -315,13 +342,16 @@ function transformJsxElement(path, internal) {
|
|
|
315
342
|
}
|
|
316
343
|
}
|
|
317
344
|
if (classStatic.length > 0) {
|
|
318
|
-
|
|
345
|
+
const first = classStatic[0];
|
|
346
|
+
const value = classStatic.length === 1 ? classStatic[0] : t.stringLiteral(classStatic.map(item => item.value).join(" "));
|
|
347
|
+
value.loc = first.loc;
|
|
348
|
+
attrs.push(t.objectProperty(t.identifier("class"), value));
|
|
319
349
|
}
|
|
320
350
|
if (styleStatic.length > 0) {
|
|
321
351
|
attrs.push(t.objectProperty(t.identifier("style"), t.stringLiteral(styleStatic.map(([id, value]) => `${id.name}:${value.value}`).join(";"))));
|
|
322
352
|
}
|
|
323
353
|
const statements = transformJsxArray(path.get("children"), internal);
|
|
324
|
-
|
|
354
|
+
const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("tag")), [
|
|
325
355
|
t.stringLiteral(name.name),
|
|
326
356
|
t.objectExpression([
|
|
327
357
|
...(attrs.length > 0 ? [t.objectProperty(t.identifier("attr"), t.objectExpression(attrs))] : []),
|
|
@@ -337,27 +367,33 @@ function transformJsxElement(path, internal) {
|
|
|
337
367
|
: []),
|
|
338
368
|
...(styleObject.length > 0 ? [t.objectProperty(t.identifier("style"), t.objectExpression(styleObject))] : []),
|
|
339
369
|
]),
|
|
340
|
-
...(statements.length > 0 ? [t.arrowFunctionExpression([
|
|
341
|
-
])
|
|
370
|
+
...(statements.length > 0 ? [t.arrowFunctionExpression([internal_1.ctx], t.blockStatement(statements))] : []),
|
|
371
|
+
]);
|
|
372
|
+
call.loc = path.node.loc;
|
|
373
|
+
return t.expressionStatement(call);
|
|
342
374
|
}
|
|
343
375
|
if (t.isJSXIdentifier(name)) {
|
|
344
376
|
const element = path.node;
|
|
345
377
|
const opening = path.get("openingElement");
|
|
346
378
|
const props = [];
|
|
347
379
|
let run;
|
|
380
|
+
const mapped = internal.mapping.get(name.name);
|
|
381
|
+
if (mapped === "Debug" && internal.stack.get(name.name) === undefined && !internal.devMode) {
|
|
382
|
+
return t.emptyStatement();
|
|
383
|
+
}
|
|
348
384
|
for (const attrPath of opening.get("attributes")) {
|
|
349
385
|
const attr = attrPath.node;
|
|
350
386
|
// <A prop=../>
|
|
351
387
|
if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
|
|
352
388
|
// <A prop=".."/>
|
|
353
389
|
if (t.isStringLiteral(attr.value)) {
|
|
354
|
-
props.push(
|
|
390
|
+
props.push(idToProp(attr.name, attr.value));
|
|
355
391
|
}
|
|
356
392
|
// <A prop={..}/>
|
|
357
393
|
else if (t.isJSXExpressionContainer(attr.value)) {
|
|
358
394
|
const isSystem = internal.mapping.has(name.name);
|
|
359
395
|
const value = transformJsxExpressionContainer(attrPath.get("value"), internal, !isSystem || attr.name.name === "slot", isSystem && attr.name.name === "slot");
|
|
360
|
-
props.push(
|
|
396
|
+
props.push(idToProp(attr.name, value));
|
|
361
397
|
}
|
|
362
398
|
else {
|
|
363
399
|
throw attrPath.buildCodeFrameError("Vasille: JSX Elements/Fragments are not supported here");
|
|
@@ -377,15 +413,17 @@ function transformJsxElement(path, internal) {
|
|
|
377
413
|
(t.isFunctionExpression(element.children[0].expression) ||
|
|
378
414
|
t.isArrowFunctionExpression(element.children[0].expression))) {
|
|
379
415
|
run = element.children[0].expression;
|
|
380
|
-
run.params.push(
|
|
416
|
+
run.params.push(internal_1.ctx);
|
|
381
417
|
}
|
|
382
418
|
else {
|
|
383
419
|
const statements = transformJsxArray(path.get("children"), internal);
|
|
384
420
|
if (statements.length > 0) {
|
|
385
|
-
run = t.arrowFunctionExpression([
|
|
421
|
+
run = t.arrowFunctionExpression([internal_1.ctx], t.blockStatement(statements));
|
|
386
422
|
}
|
|
387
423
|
}
|
|
388
|
-
|
|
424
|
+
const call = t.callExpression(t.identifier(name.name), [internal_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]);
|
|
425
|
+
call.loc = path.node.loc;
|
|
426
|
+
return t.expressionStatement(call);
|
|
389
427
|
}
|
|
390
428
|
throw path.buildCodeFrameError("Vasille: Unsupported tag detected, html lowercase tagnames and components are accepted");
|
|
391
429
|
}
|
package/lib-node/lib.js
CHANGED
|
@@ -33,11 +33,11 @@ exports.arrayModel = arrayModel;
|
|
|
33
33
|
exports.setModel = setModel;
|
|
34
34
|
exports.mapModel = mapModel;
|
|
35
35
|
const t = __importStar(require("@babel/types"));
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
36
|
+
const expression_1 = require("./expression");
|
|
37
|
+
const internal_1 = require("./internal");
|
|
38
|
+
const call_1 = require("./call");
|
|
39
39
|
function parseCalculateCall(path, internal) {
|
|
40
|
-
if (t.isCallExpression(path.node) && (0,
|
|
40
|
+
if (t.isCallExpression(path.node) && (0, call_1.calls)(path.node, ["calculate", "watch"], internal)) {
|
|
41
41
|
if (path.node.arguments.length !== 1) {
|
|
42
42
|
throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
|
|
43
43
|
}
|
|
@@ -45,8 +45,8 @@ function parseCalculateCall(path, internal) {
|
|
|
45
45
|
if (path.node.arguments[0].params.length > 0) {
|
|
46
46
|
throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
|
|
47
47
|
}
|
|
48
|
-
const exprData = (0,
|
|
49
|
-
path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0,
|
|
48
|
+
const exprData = (0, expression_1.checkNode)(path.get("arguments")[0], internal);
|
|
49
|
+
path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0, expression_1.encodeName)(name));
|
|
50
50
|
return [path.node.arguments[0], ...exprData.found.values()];
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -58,20 +58,20 @@ function parseCalculateCall(path, internal) {
|
|
|
58
58
|
function exprCall(path, expr, internal) {
|
|
59
59
|
const calculateCall = parseCalculateCall(path, internal);
|
|
60
60
|
if (calculateCall) {
|
|
61
|
-
return t.callExpression(t.memberExpression(
|
|
61
|
+
return t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("expr")), calculateCall);
|
|
62
62
|
}
|
|
63
|
-
const exprData = (0,
|
|
63
|
+
const exprData = (0, expression_1.checkNode)(path, internal);
|
|
64
64
|
return exprData.self
|
|
65
65
|
? exprData.self
|
|
66
66
|
: exprData.found.size > 0 && expr
|
|
67
|
-
? t.callExpression(t.memberExpression(
|
|
68
|
-
t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0,
|
|
67
|
+
? t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("expr")), [
|
|
68
|
+
t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_1.encodeName)(name)), expr),
|
|
69
69
|
...exprData.found.values(),
|
|
70
70
|
])
|
|
71
71
|
: null;
|
|
72
72
|
}
|
|
73
73
|
function forwardOnlyExpr(path, expr, internal) {
|
|
74
|
-
if (t.isCallExpression(path.node) && (0,
|
|
74
|
+
if (t.isCallExpression(path.node) && (0, call_1.calls)(path.node, ["calculate"], internal)) {
|
|
75
75
|
if (path.node.arguments.length !== 1) {
|
|
76
76
|
throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
|
|
77
77
|
}
|
|
@@ -79,8 +79,8 @@ function forwardOnlyExpr(path, expr, internal) {
|
|
|
79
79
|
if (path.node.arguments[0].params.length > 0) {
|
|
80
80
|
throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
|
|
81
81
|
}
|
|
82
|
-
const exprData = (0,
|
|
83
|
-
path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0,
|
|
82
|
+
const exprData = (0, expression_1.checkNode)(path.get("arguments")[0], internal);
|
|
83
|
+
path.node.arguments[0].params = [...exprData.found.keys()].map(name => (0, expression_1.encodeName)(name));
|
|
84
84
|
return t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
|
|
85
85
|
path.node.arguments[0],
|
|
86
86
|
...exprData.found.values(),
|
|
@@ -94,31 +94,31 @@ function forwardOnlyExpr(path, expr, internal) {
|
|
|
94
94
|
if (calculateCall) {
|
|
95
95
|
return t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), calculateCall);
|
|
96
96
|
}
|
|
97
|
-
const exprData = (0,
|
|
97
|
+
const exprData = (0, expression_1.checkNode)(path, internal);
|
|
98
98
|
return exprData.self
|
|
99
99
|
? t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [exprData.self])
|
|
100
100
|
: exprData.found.size > 0 && expr
|
|
101
101
|
? t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
|
|
102
|
-
t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0,
|
|
102
|
+
t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_1.encodeName)(name)), expr),
|
|
103
103
|
...exprData.found.values(),
|
|
104
104
|
])
|
|
105
105
|
: null;
|
|
106
106
|
}
|
|
107
107
|
function own(expr) {
|
|
108
|
-
return t.callExpression(t.memberExpression(
|
|
108
|
+
return t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("own")), [expr]);
|
|
109
109
|
}
|
|
110
110
|
function ref(expr) {
|
|
111
|
-
return t.callExpression(t.memberExpression(
|
|
111
|
+
return t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("ref")), expr ? [expr] : []);
|
|
112
112
|
}
|
|
113
113
|
function reactiveObject(init, internal) {
|
|
114
|
-
return t.callExpression(t.memberExpression(internal.id, t.identifier("ro")), [
|
|
114
|
+
return t.callExpression(t.memberExpression(internal.id, t.identifier("ro")), [internal_1.ctx, init]);
|
|
115
115
|
}
|
|
116
116
|
function arrayModel(init, internal) {
|
|
117
|
-
return t.callExpression(t.memberExpression(internal.id, t.identifier("am")), [
|
|
117
|
+
return t.callExpression(t.memberExpression(internal.id, t.identifier("am")), [internal_1.ctx, ...(init ? [init] : [])]);
|
|
118
118
|
}
|
|
119
119
|
function setModel(args, internal) {
|
|
120
|
-
return t.callExpression(t.memberExpression(internal.id, t.identifier("sm")), [
|
|
120
|
+
return t.callExpression(t.memberExpression(internal.id, t.identifier("sm")), [internal_1.ctx, ...args]);
|
|
121
121
|
}
|
|
122
122
|
function mapModel(args, internal) {
|
|
123
|
-
return t.callExpression(t.memberExpression(internal.id, t.identifier("mm")), [
|
|
123
|
+
return t.callExpression(t.memberExpression(internal.id, t.identifier("mm")), [internal_1.ctx, ...args]);
|
|
124
124
|
}
|