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/jsx.js
DELETED
|
@@ -1,439 +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.transformJsx = transformJsx;
|
|
37
|
-
exports.transformJsxArray = transformJsxArray;
|
|
38
|
-
const t = __importStar(require("@babel/types"));
|
|
39
|
-
const internal_js_1 = require("./internal.js");
|
|
40
|
-
const lib_js_1 = require("./lib.js");
|
|
41
|
-
const mesh_js_1 = require("./mesh.js");
|
|
42
|
-
const jsx_detect_js_1 = require("./jsx-detect.js");
|
|
43
|
-
function transformJsx(path, internal) {
|
|
44
|
-
if (t.isJSXElement(path.node)) {
|
|
45
|
-
return [transformJsxElement(path, internal)];
|
|
46
|
-
}
|
|
47
|
-
return transformJsxArray(path.get("children"), internal);
|
|
48
|
-
}
|
|
49
|
-
function transformJsxArray(paths, internal) {
|
|
50
|
-
const result = [];
|
|
51
|
-
for (const path of paths) {
|
|
52
|
-
if (t.isJSXElement(path.node) || t.isJSXFragment(path.node)) {
|
|
53
|
-
result.push(...transformJsx(path, internal));
|
|
54
|
-
}
|
|
55
|
-
else if (t.isJSXText(path.node)) {
|
|
56
|
-
if (!/^\s+$/.test(path.node.value)) {
|
|
57
|
-
const fixed = path.node.value
|
|
58
|
-
.replace(/\n\s+$/m, "")
|
|
59
|
-
.replace(/^\s*\n\s+/m, "")
|
|
60
|
-
.replace(/\s*\n\s*/gm, "\n");
|
|
61
|
-
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)]);
|
|
62
|
-
call.loc = path.node.loc;
|
|
63
|
-
if (call.loc) {
|
|
64
|
-
for (const char of path.node.value) {
|
|
65
|
-
if (!/\s/.test(char)) {
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
if (char === "\n") {
|
|
69
|
-
call.loc.start.column = 0;
|
|
70
|
-
call.loc.start.line++;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
call.loc.start.column++;
|
|
74
|
-
}
|
|
75
|
-
call.loc.start.index++;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
result.push(t.expressionStatement(call));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (t.isJSXExpressionContainer(path.node)) {
|
|
82
|
-
const value = transformJsxExpressionContainer(path, internal, false, false);
|
|
83
|
-
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("text")), [value]);
|
|
84
|
-
call.loc = value.loc;
|
|
85
|
-
result.push(t.expressionStatement(call));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
throw path.buildCodeFrameError("Vasille: Spread child is not supported");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
function transformJsxExpressionContainer(path, internal, acceptSlots, isInternalSlot) {
|
|
94
|
-
const expression = path.node.expression;
|
|
95
|
-
const loc = expression.loc;
|
|
96
|
-
if (acceptSlots &&
|
|
97
|
-
(t.isFunctionExpression(expression) || t.isArrowFunctionExpression(expression)) &&
|
|
98
|
-
(0, jsx_detect_js_1.bodyHasJsx)(expression.body)) {
|
|
99
|
-
(0, mesh_js_1.compose)(path.get("expression"), internal, isInternalSlot);
|
|
100
|
-
if (!isInternalSlot) {
|
|
101
|
-
if (expression.params.length < 1) {
|
|
102
|
-
expression.params.push(t.identifier(`_${internal.prefix}`));
|
|
103
|
-
}
|
|
104
|
-
expression.params.push(internal_js_1.ctx);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
expression.params.unshift(internal_js_1.ctx);
|
|
108
|
-
}
|
|
109
|
-
expression.loc = loc;
|
|
110
|
-
return expression;
|
|
111
|
-
}
|
|
112
|
-
else if (isInternalSlot && (t.isFunctionExpression(expression) || t.isArrowFunctionExpression(expression))) {
|
|
113
|
-
expression.params.unshift(internal_js_1.ctx);
|
|
114
|
-
}
|
|
115
|
-
let call = (0, lib_js_1.exprCall)(path.get("expression"), expression, internal);
|
|
116
|
-
if (!call && t.isIdentifier(expression) && internal.stack.get(expression.name) === 3 /* VariableState.ReactiveObject */) {
|
|
117
|
-
call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [expression]);
|
|
118
|
-
}
|
|
119
|
-
const result = call !== null && call !== void 0 ? call : expression;
|
|
120
|
-
result.loc = loc;
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
function idToProp(id, value, from) {
|
|
124
|
-
let str = t.isIdentifier(id) || t.isJSXIdentifier(id) ? id.name : id.value;
|
|
125
|
-
let expr;
|
|
126
|
-
if (from) {
|
|
127
|
-
str = str.substring(from);
|
|
128
|
-
}
|
|
129
|
-
if (/^[\w_]+$/.test(str)) {
|
|
130
|
-
expr = t.identifier(str);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
expr = t.stringLiteral(str);
|
|
134
|
-
}
|
|
135
|
-
expr.loc = id.loc;
|
|
136
|
-
return t.objectProperty(expr, value);
|
|
137
|
-
}
|
|
138
|
-
function transformJsxElement(path, internal) {
|
|
139
|
-
var _a, _b, _c, _d, _e;
|
|
140
|
-
const name = path.node.openingElement.name;
|
|
141
|
-
if (t.isJSXIdentifier(name) && name.name[0].toLowerCase() === name.name[0]) {
|
|
142
|
-
const opening = path.get("openingElement");
|
|
143
|
-
const attrs = [];
|
|
144
|
-
const events = [];
|
|
145
|
-
const bind = [];
|
|
146
|
-
const classElements = [];
|
|
147
|
-
const classObject = [];
|
|
148
|
-
const classStatic = [];
|
|
149
|
-
const styleObject = [];
|
|
150
|
-
const styleStatic = [];
|
|
151
|
-
for (const attrPath of opening.get("attributes")) {
|
|
152
|
-
const attr = attrPath.node;
|
|
153
|
-
if (t.isJSXAttribute(attr)) {
|
|
154
|
-
const name = attr.name;
|
|
155
|
-
if (t.isJSXIdentifier(name)) {
|
|
156
|
-
if (name.name.startsWith("on")) {
|
|
157
|
-
if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
|
|
158
|
-
const path = attrPath.get("value");
|
|
159
|
-
if (t.isExpression(path.node.expression)) {
|
|
160
|
-
(0, mesh_js_1.meshExpression)(path.get("expression"), internal);
|
|
161
|
-
}
|
|
162
|
-
events.push(idToProp(name, path.node.expression, 2));
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
throw attrPath
|
|
166
|
-
.get("value")
|
|
167
|
-
.buildCodeFrameError("Vasille: Expected event handler.");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else if (name.name === "class") {
|
|
171
|
-
// class={[..]}
|
|
172
|
-
if (t.isJSXExpressionContainer(attr.value) && t.isArrayExpression(attr.value.expression)) {
|
|
173
|
-
const valuePath = attrPath.get("value");
|
|
174
|
-
const arrayExprPath = valuePath.get("expression");
|
|
175
|
-
for (const elementPath of arrayExprPath.get("elements")) {
|
|
176
|
-
const item = elementPath.node;
|
|
177
|
-
if (t.isExpression(item)) {
|
|
178
|
-
// class={[cond && "string"]}
|
|
179
|
-
if (t.isLogicalExpression(item) && item.operator === "&&" && t.isStringLiteral(item.right)) {
|
|
180
|
-
const call = (0, lib_js_1.exprCall)(elementPath.get("left"), item.left, internal);
|
|
181
|
-
classObject.push(idToProp(item.right, call !== null && call !== void 0 ? call : item.left));
|
|
182
|
-
}
|
|
183
|
-
// class={[{..}]}
|
|
184
|
-
else if (t.isObjectExpression(item)) {
|
|
185
|
-
for (const propPath of elementPath.get("properties")) {
|
|
186
|
-
// class={[{a: b}]}
|
|
187
|
-
if (t.isObjectProperty(propPath.node)) {
|
|
188
|
-
const prop = propPath;
|
|
189
|
-
const value = (_a = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
|
|
190
|
-
if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
|
|
191
|
-
(0, mesh_js_1.meshExpression)(prop.get("key"), internal);
|
|
192
|
-
}
|
|
193
|
-
classObject.push(t.objectProperty(prop.node.key, value));
|
|
194
|
-
}
|
|
195
|
-
// class={[{...a}]}
|
|
196
|
-
else if (t.isSpreadElement(propPath.node)) {
|
|
197
|
-
classObject.push(propPath.node);
|
|
198
|
-
}
|
|
199
|
-
// class={[{a(){}}]}
|
|
200
|
-
else {
|
|
201
|
-
throw propPath.buildCodeFrameError("Vasille: Methods are not allowed here");
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
// class={[".."]}
|
|
206
|
-
else if (t.isStringLiteral(elementPath.node)) {
|
|
207
|
-
classStatic.push(elementPath.node);
|
|
208
|
-
}
|
|
209
|
-
// class={[..]}
|
|
210
|
-
else {
|
|
211
|
-
const call = (0, lib_js_1.exprCall)(elementPath, item, internal);
|
|
212
|
-
classElements.push(call !== null && call !== void 0 ? call : item);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// class={[...array]}
|
|
216
|
-
else {
|
|
217
|
-
classElements.push(elementPath.node);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
// class={"a b"}
|
|
222
|
-
else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
|
|
223
|
-
attrs.push(t.objectProperty(t.identifier("class"), attr.value.expression));
|
|
224
|
-
}
|
|
225
|
-
// class={`a ${b}`}
|
|
226
|
-
else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
|
|
227
|
-
const jsxAttrPath = attrPath;
|
|
228
|
-
const jsxContainerPath = jsxAttrPath.get("value");
|
|
229
|
-
const value = (0, lib_js_1.exprCall)(jsxContainerPath.get("expression"), attr.value.expression, internal);
|
|
230
|
-
attrs.push(t.objectProperty(t.identifier("class"), value !== null && value !== void 0 ? value : attr.value.expression));
|
|
231
|
-
if (value) {
|
|
232
|
-
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// class={name}
|
|
236
|
-
else if (t.isJSXExpressionContainer(attr.value) && t.isIdentifier(attr.value.expression)) {
|
|
237
|
-
attrs.push(t.objectProperty(t.identifier("class"), attr.value.expression));
|
|
238
|
-
}
|
|
239
|
-
// class="a b"
|
|
240
|
-
else if (t.isStringLiteral(attr.value)) {
|
|
241
|
-
classStatic.push(attr.value);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else if (name.name === "style") {
|
|
245
|
-
// style={{..}}
|
|
246
|
-
if (t.isJSXExpressionContainer(attr.value) && t.isObjectExpression(attr.value.expression)) {
|
|
247
|
-
const valuePath = attrPath.get("value");
|
|
248
|
-
const objectPath = valuePath.get("expression");
|
|
249
|
-
for (const propPath of objectPath.get("properties")) {
|
|
250
|
-
// style={{a: b}}
|
|
251
|
-
if (t.isObjectProperty(propPath.node)) {
|
|
252
|
-
const prop = propPath;
|
|
253
|
-
const value = (_b = (0, lib_js_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
|
|
254
|
-
if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
|
|
255
|
-
(0, mesh_js_1.meshExpression)(prop.get("key"), internal);
|
|
256
|
-
}
|
|
257
|
-
// style={{a: "b"}} -> static in compile time
|
|
258
|
-
if (t.isIdentifier(prop.node.key) && t.isStringLiteral(prop.node.value)) {
|
|
259
|
-
styleStatic.push([prop.node.key, prop.node.value]);
|
|
260
|
-
}
|
|
261
|
-
// style={{a: 23}} -> static in compile time
|
|
262
|
-
else if (t.isIdentifier(prop.node.key) && t.isNumericLiteral(prop.node.value)) {
|
|
263
|
-
styleStatic.push([prop.node.key, t.stringLiteral(`${prop.node.value.value}px`)]);
|
|
264
|
-
}
|
|
265
|
-
// style={{a: [1, 2, 3]}} -> static in compile time
|
|
266
|
-
else if (t.isIdentifier(prop.node.key) &&
|
|
267
|
-
t.isArrayExpression(prop.node.value) &&
|
|
268
|
-
prop.node.value.elements.every(item => t.isNumericLiteral(item))) {
|
|
269
|
-
styleStatic.push([
|
|
270
|
-
prop.node.key,
|
|
271
|
-
t.stringLiteral(prop.node.value.elements
|
|
272
|
-
.map(item => {
|
|
273
|
-
return `${item.value}px`;
|
|
274
|
-
})
|
|
275
|
-
.join(" ")),
|
|
276
|
-
]);
|
|
277
|
-
}
|
|
278
|
-
// need processing in run time
|
|
279
|
-
else {
|
|
280
|
-
styleObject.push(t.objectProperty(prop.node.key, value));
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
// style={{...a}}
|
|
284
|
-
else if (t.isSpreadElement(propPath.node)) {
|
|
285
|
-
styleObject.push(propPath.node);
|
|
286
|
-
}
|
|
287
|
-
// style={{a(){}}}
|
|
288
|
-
else {
|
|
289
|
-
throw propPath.buildCodeFrameError("Vasille: Methods are not allowed here");
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
// style=".."
|
|
294
|
-
else if (t.isStringLiteral(attr.value)) {
|
|
295
|
-
attrs.push(t.objectProperty(t.identifier("style"), attr.value));
|
|
296
|
-
}
|
|
297
|
-
// style={".."}
|
|
298
|
-
else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression)) {
|
|
299
|
-
attrs.push(t.objectProperty(t.identifier("style"), attr.value.expression));
|
|
300
|
-
}
|
|
301
|
-
// style={`a: ${b}px`}
|
|
302
|
-
else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
|
|
303
|
-
const jsxAttrPath = attrPath;
|
|
304
|
-
const jsxContainerPath = jsxAttrPath.get("value");
|
|
305
|
-
const literalPath = jsxContainerPath.get("expression");
|
|
306
|
-
const value = (0, lib_js_1.exprCall)(literalPath, attr.value.expression, internal);
|
|
307
|
-
attrs.push(t.objectProperty(t.identifier("style"), value !== null && value !== void 0 ? value : attr.value.expression));
|
|
308
|
-
if (value) {
|
|
309
|
-
console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
if (!attr.value || t.isJSXExpressionContainer(attr.value)) {
|
|
315
|
-
attrs.push(idToProp(name, t.isExpression((_c = attr.value) === null || _c === void 0 ? void 0 : _c.expression) ? attr.value.expression : t.booleanLiteral(true)));
|
|
316
|
-
}
|
|
317
|
-
else if (t.isStringLiteral(attr.value)) {
|
|
318
|
-
attrs.push(idToProp(name, attr.value));
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if (t.isJSXNamespacedName(name)) {
|
|
323
|
-
if (name.namespace.name === "bind") {
|
|
324
|
-
if (t.isJSXExpressionContainer(attr.value) || !attr.value) {
|
|
325
|
-
const value = t.isExpression((_d = attr.value) === null || _d === void 0 ? void 0 : _d.expression)
|
|
326
|
-
? (0, lib_js_1.exprCall)(attrPath.get("value").get("expression"), attr.value.expression, internal)
|
|
327
|
-
: undefined;
|
|
328
|
-
bind.push(idToProp(name.name, value !== null && value !== void 0 ? value : (t.isExpression((_e = attr.value) === null || _e === void 0 ? void 0 : _e.expression) ? attr.value.expression : t.booleanLiteral(true))));
|
|
329
|
-
}
|
|
330
|
-
else if (t.isStringLiteral(attr.value)) {
|
|
331
|
-
bind.push(idToProp(name.name, attr.value));
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
throw attrPath.buildCodeFrameError("Vasille: only bind namespace is supported");
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
throw attrPath.buildCodeFrameError("Vasille: Spread attribute is not allowed on HTML tags.");
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (classStatic.length > 0) {
|
|
344
|
-
const first = classStatic[0];
|
|
345
|
-
const value = classStatic.length === 1 ? classStatic[0] : t.stringLiteral(classStatic.map(item => item.value).join(" "));
|
|
346
|
-
value.loc = first.loc;
|
|
347
|
-
attrs.push(t.objectProperty(t.identifier("class"), value));
|
|
348
|
-
}
|
|
349
|
-
if (styleStatic.length > 0) {
|
|
350
|
-
attrs.push(t.objectProperty(t.identifier("style"), t.stringLiteral(styleStatic.map(([id, value]) => `${id.name}:${value.value}`).join(";"))));
|
|
351
|
-
}
|
|
352
|
-
const statements = transformJsxArray(path.get("children"), internal);
|
|
353
|
-
const call = t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("tag")), [
|
|
354
|
-
t.stringLiteral(name.name),
|
|
355
|
-
t.objectExpression([
|
|
356
|
-
...(attrs.length > 0 ? [t.objectProperty(t.identifier("attr"), t.objectExpression(attrs))] : []),
|
|
357
|
-
...(events.length > 0 ? [t.objectProperty(t.identifier("events"), t.objectExpression(events))] : []),
|
|
358
|
-
...(bind.length > 0 ? [t.objectProperty(t.identifier("bind"), t.objectExpression(bind))] : []),
|
|
359
|
-
...(classElements.length > 0 || classObject.length
|
|
360
|
-
? [
|
|
361
|
-
t.objectProperty(t.identifier("class"), t.arrayExpression([
|
|
362
|
-
...classElements,
|
|
363
|
-
...(classObject.length > 0 ? [t.objectExpression(classObject)] : []),
|
|
364
|
-
])),
|
|
365
|
-
]
|
|
366
|
-
: []),
|
|
367
|
-
...(styleObject.length > 0 ? [t.objectProperty(t.identifier("style"), t.objectExpression(styleObject))] : []),
|
|
368
|
-
]),
|
|
369
|
-
...(statements.length > 0 ? [t.arrowFunctionExpression([internal_js_1.ctx], t.blockStatement(statements))] : []),
|
|
370
|
-
]);
|
|
371
|
-
call.loc = path.node.loc;
|
|
372
|
-
return t.expressionStatement(call);
|
|
373
|
-
}
|
|
374
|
-
if (t.isJSXIdentifier(name)) {
|
|
375
|
-
const element = path.node;
|
|
376
|
-
const opening = path.get("openingElement");
|
|
377
|
-
const props = [];
|
|
378
|
-
let run;
|
|
379
|
-
const mapped = internal.mapping.get(name.name);
|
|
380
|
-
if (mapped === "Debug" && internal.stack.get(name.name) === undefined && !internal.devMode) {
|
|
381
|
-
return t.emptyStatement();
|
|
382
|
-
}
|
|
383
|
-
for (const attrPath of opening.get("attributes")) {
|
|
384
|
-
const attr = attrPath.node;
|
|
385
|
-
// <A prop=../>
|
|
386
|
-
if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
|
|
387
|
-
// <A prop=".."/>
|
|
388
|
-
if (t.isStringLiteral(attr.value)) {
|
|
389
|
-
props.push(idToProp(attr.name, attr.value));
|
|
390
|
-
}
|
|
391
|
-
// <A prop={..}/>
|
|
392
|
-
else if (t.isJSXExpressionContainer(attr.value)) {
|
|
393
|
-
const isSystem = internal.mapping.has(name.name);
|
|
394
|
-
const value = transformJsxExpressionContainer(attrPath.get("value"), internal, !isSystem || attr.name.name === "slot", isSystem && attr.name.name === "slot");
|
|
395
|
-
props.push(idToProp(attr.name, value));
|
|
396
|
-
}
|
|
397
|
-
else if (!attr.value) {
|
|
398
|
-
props.push(idToProp(attr.name, t.booleanLiteral(true)));
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
// <A {...arg}/>
|
|
402
|
-
else if (t.isJSXSpreadAttribute(attr)) {
|
|
403
|
-
props.push(t.spreadElement(attr.argument));
|
|
404
|
-
}
|
|
405
|
-
// <A space:name=../>
|
|
406
|
-
else {
|
|
407
|
-
throw attrPath.buildCodeFrameError("Vasille: Namespaced attributes names are not supported");
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
const filteredChildren = element.children.filter(item => {
|
|
411
|
-
if (!t.isJSXText(item)) {
|
|
412
|
-
return true;
|
|
413
|
-
}
|
|
414
|
-
return !!item.value.trim();
|
|
415
|
-
});
|
|
416
|
-
const isInternal = internal.mapping.has(name.name);
|
|
417
|
-
if (filteredChildren.length === 1 &&
|
|
418
|
-
t.isJSXExpressionContainer(filteredChildren[0]) &&
|
|
419
|
-
(t.isFunctionExpression(filteredChildren[0].expression) ||
|
|
420
|
-
t.isArrowFunctionExpression(filteredChildren[0].expression))) {
|
|
421
|
-
transformJsxExpressionContainer(path.get("children")[element.children.indexOf(filteredChildren[0])], internal, true, isInternal);
|
|
422
|
-
run = filteredChildren[0].expression;
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
const statements = transformJsxArray(path.get("children"), internal);
|
|
426
|
-
if (statements.length > 0) {
|
|
427
|
-
const params = [internal_js_1.ctx];
|
|
428
|
-
if (!isInternal) {
|
|
429
|
-
params.unshift(t.identifier(`_${internal.prefix}`));
|
|
430
|
-
}
|
|
431
|
-
run = t.arrowFunctionExpression(params, t.blockStatement(statements));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
const call = t.callExpression(t.identifier(name.name), [internal_js_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]);
|
|
435
|
-
call.loc = path.node.loc;
|
|
436
|
-
return t.expressionStatement(call);
|
|
437
|
-
}
|
|
438
|
-
throw path.buildCodeFrameError("Vasille: Unsupported tag detected, html lowercase tag names and components are accepted");
|
|
439
|
-
}
|
package/lib-node/lib.js
DELETED
|
@@ -1,153 +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.named = named;
|
|
37
|
-
exports.parseCalculateCall = parseCalculateCall;
|
|
38
|
-
exports.exprCall = exprCall;
|
|
39
|
-
exports.forwardOnlyExpr = forwardOnlyExpr;
|
|
40
|
-
exports.own = own;
|
|
41
|
-
exports.ref = ref;
|
|
42
|
-
exports.reactiveObject = reactiveObject;
|
|
43
|
-
exports.arrayModel = arrayModel;
|
|
44
|
-
exports.setModel = setModel;
|
|
45
|
-
exports.mapModel = mapModel;
|
|
46
|
-
const t = __importStar(require("@babel/types"));
|
|
47
|
-
const expression_js_1 = require("./expression.js");
|
|
48
|
-
const internal_js_1 = require("./internal.js");
|
|
49
|
-
const call_js_1 = require("./call.js");
|
|
50
|
-
function named(call, name, internal, argPos) {
|
|
51
|
-
if (internal.devMode && !internal.stateOnly && name) {
|
|
52
|
-
while (argPos && call.arguments.length < argPos) {
|
|
53
|
-
call.arguments.push(t.buildUndefinedNode());
|
|
54
|
-
}
|
|
55
|
-
call.arguments.push(...(typeof name === "string" ? [t.stringLiteral(name)] : name.map(item => t.stringLiteral(item))));
|
|
56
|
-
}
|
|
57
|
-
return call;
|
|
58
|
-
}
|
|
59
|
-
function parseCalculateCall(path, internal) {
|
|
60
|
-
if (t.isCallExpression(path.node) && (0, call_js_1.calls)(path.node, ["calculate", "watch"], internal)) {
|
|
61
|
-
const call = path.node.arguments[0];
|
|
62
|
-
if (path.node.arguments.length !== 1) {
|
|
63
|
-
throw path.buildCodeFrameError("Vasille: Incorrect number of arguments");
|
|
64
|
-
}
|
|
65
|
-
if (t.isFunctionExpression(call) || t.isArrowFunctionExpression(call)) {
|
|
66
|
-
if (call.params.length > 0) {
|
|
67
|
-
throw path.buildCodeFrameError("Vasille: Argument of calculate cannot have parameters");
|
|
68
|
-
}
|
|
69
|
-
const exprData = (0, expression_js_1.checkNode)(path.get("arguments")[0], internal);
|
|
70
|
-
call.params = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
|
|
71
|
-
return [call, t.arrayExpression([...exprData.found.values()])];
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw path.buildCodeFrameError("Vasille: Argument of calculate must be a function");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
function exprCall(path, expr, internal, name) {
|
|
80
|
-
const calculateCall = parseCalculateCall(path, internal);
|
|
81
|
-
if (calculateCall) {
|
|
82
|
-
return named(t.callExpression(internal.stateOnly
|
|
83
|
-
? t.memberExpression(internal.id, t.identifier("ex"))
|
|
84
|
-
: t.memberExpression(internal_js_1.ctx, t.identifier("expr")), calculateCall), name, internal);
|
|
85
|
-
}
|
|
86
|
-
if (t.isCallExpression(expr) &&
|
|
87
|
-
(0, call_js_1.calls)(expr, ["forward"], internal) &&
|
|
88
|
-
expr.arguments.length === 1 &&
|
|
89
|
-
t.isExpression(expr.arguments[0])) {
|
|
90
|
-
const data = exprCall(path.get("arguments")[0], expr.arguments[0], internal);
|
|
91
|
-
if (data && !t.isCallExpression(data)) {
|
|
92
|
-
return t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [data]);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const exprData = (0, expression_js_1.checkNode)(path, internal);
|
|
96
|
-
if (exprData.self) {
|
|
97
|
-
return exprData.self;
|
|
98
|
-
}
|
|
99
|
-
const names = [...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name));
|
|
100
|
-
const dependencies = t.arrayExpression([...exprData.found.values()]);
|
|
101
|
-
if (names.length > 0 && expr) {
|
|
102
|
-
return named(t.callExpression(internal.stateOnly
|
|
103
|
-
? t.memberExpression(internal.id, t.identifier("ex"))
|
|
104
|
-
: t.memberExpression(internal_js_1.ctx, t.identifier("expr")), [t.arrowFunctionExpression(names, expr), dependencies]), name, internal);
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
function forwardOnlyExpr(path, expr, internal) {
|
|
109
|
-
const calculateCall = parseCalculateCall(path, internal);
|
|
110
|
-
if (calculateCall) {
|
|
111
|
-
return t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), calculateCall);
|
|
112
|
-
}
|
|
113
|
-
const exprData = (0, expression_js_1.checkNode)(path, internal);
|
|
114
|
-
return exprData.self
|
|
115
|
-
? t.callExpression(t.memberExpression(internal.id, t.identifier("fo")), [exprData.self])
|
|
116
|
-
: exprData.found.size > 0 && expr
|
|
117
|
-
? t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
|
|
118
|
-
t.arrowFunctionExpression([...exprData.found.keys()].map(name => (0, expression_js_1.encodeName)(name)), expr),
|
|
119
|
-
t.arrayExpression([...exprData.found.values()]),
|
|
120
|
-
])
|
|
121
|
-
: null;
|
|
122
|
-
}
|
|
123
|
-
function own(expr, internal, name) {
|
|
124
|
-
if (internal.stateOnly &&
|
|
125
|
-
t.isCallExpression(expr) &&
|
|
126
|
-
t.isMemberExpression(expr.callee) &&
|
|
127
|
-
t.isIdentifier(expr.callee.property) &&
|
|
128
|
-
expr.callee.property.name === "fo" &&
|
|
129
|
-
t.isIdentifier(expr.callee.object) &&
|
|
130
|
-
expr.callee.object === internal.id) {
|
|
131
|
-
return expr;
|
|
132
|
-
}
|
|
133
|
-
return named(t.callExpression(internal.stateOnly
|
|
134
|
-
? t.memberExpression(internal.id, t.identifier("fo"))
|
|
135
|
-
: t.memberExpression(internal_js_1.ctx, t.identifier("own")), [expr]), name, internal);
|
|
136
|
-
}
|
|
137
|
-
function ref(expr, internal, name) {
|
|
138
|
-
return named(t.callExpression(internal.stateOnly
|
|
139
|
-
? t.memberExpression(internal.id, t.identifier("r"))
|
|
140
|
-
: t.memberExpression(internal_js_1.ctx, t.identifier("ref")), expr ? [expr] : []), name, internal, 1);
|
|
141
|
-
}
|
|
142
|
-
function reactiveObject(init, internal, name) {
|
|
143
|
-
return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "sro" : "ro")), internal.stateOnly ? [init] : [internal_js_1.ctx, init]), name, internal);
|
|
144
|
-
}
|
|
145
|
-
function arrayModel(init, internal, name) {
|
|
146
|
-
return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "sam" : "am")), internal.stateOnly ? (init ? [init] : []) : [internal_js_1.ctx, ...(init ? [init] : [])]), name, internal, 2);
|
|
147
|
-
}
|
|
148
|
-
function setModel(args, internal, name) {
|
|
149
|
-
return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "ssm" : "sm")), internal.stateOnly ? args : [internal_js_1.ctx, ...args]), name, internal);
|
|
150
|
-
}
|
|
151
|
-
function mapModel(args, internal, name) {
|
|
152
|
-
return named(t.callExpression(t.memberExpression(internal.id, t.identifier(internal.stateOnly ? "smm" : "mm")), internal.stateOnly ? args : [internal_js_1.ctx, ...args]), name, internal);
|
|
153
|
-
}
|