babel-plugin-vasille 5.1.2 → 5.1.3
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/lib/expression.js +10 -10
- package/lib/jsx.js +12 -19
- package/lib/lib.js +3 -0
- package/lib/mesh.js +16 -9
- package/lib/operators.js +90 -0
- package/package.json +2 -2
- package/types/operators.d.ts +25 -0
package/lib/expression.js
CHANGED
|
@@ -54,6 +54,7 @@ const lib_1 = require("./lib");
|
|
|
54
54
|
const mesh_1 = require("./mesh");
|
|
55
55
|
const router_1 = require("./router");
|
|
56
56
|
const utils_1 = require("./utils");
|
|
57
|
+
const operators_1 = require("./operators");
|
|
57
58
|
function insertName(name, search) {
|
|
58
59
|
const id = t.identifier(name);
|
|
59
60
|
search?.inserted.add(id);
|
|
@@ -69,7 +70,8 @@ function addExpression(path, search) {
|
|
|
69
70
|
let it = path.node;
|
|
70
71
|
while (t.isMemberExpression(it) || t.isIdentifier(it)) {
|
|
71
72
|
const name = (0, utils_1.stringify)(t.isMemberExpression(it) ? it.property : it);
|
|
72
|
-
|
|
73
|
+
const computed = t.isMemberExpression(it) ? it.computed : false;
|
|
74
|
+
if (it !== path.node && name.startsWith("$") && !computed) {
|
|
73
75
|
(0, lib_1.err)(lib_1.Errors.RulesOfVasille, path, "The reactive/observable value is nested", search.external, null);
|
|
74
76
|
}
|
|
75
77
|
it = t.isMemberExpression(it) ? it.object : null;
|
|
@@ -95,10 +97,11 @@ function meshIdentifier(path) {
|
|
|
95
97
|
}
|
|
96
98
|
function idIsIValue(path) {
|
|
97
99
|
const node = path.node;
|
|
98
|
-
return node.name.startsWith("$") &&
|
|
100
|
+
return (node.name.startsWith("$") &&
|
|
101
|
+
(!(t.isMemberExpression(path.parent) && !path.parent.computed) || path.parent.object === node));
|
|
99
102
|
}
|
|
100
103
|
function memberIsIValue(node) {
|
|
101
|
-
return ((t.isIdentifier(node.property) && node.property.name.startsWith("$")) ||
|
|
104
|
+
return ((t.isIdentifier(node.property) && node.property.name.startsWith("$") && !node.computed) ||
|
|
102
105
|
(t.isStringLiteral(node.property) && node.property.value.startsWith("$")));
|
|
103
106
|
}
|
|
104
107
|
function memberIsIValueInExpr(path, search) {
|
|
@@ -191,6 +194,9 @@ function checkNode(path, internal, area, name) {
|
|
|
191
194
|
path.replaceWith((0, lib_1.ref)(refValue, internal, area, name));
|
|
192
195
|
search.self = path.node;
|
|
193
196
|
}
|
|
197
|
+
if (path.isTSAsExpression() || path.isTSSatisfiesExpression()) {
|
|
198
|
+
return checkNode(path.get("expression"), internal, area, name);
|
|
199
|
+
}
|
|
194
200
|
if (search.self) {
|
|
195
201
|
return search;
|
|
196
202
|
}
|
|
@@ -302,13 +308,7 @@ function checkExpression(nodePath, search) {
|
|
|
302
308
|
const left = path.get("left");
|
|
303
309
|
const right = path.get("right");
|
|
304
310
|
if (left.isMemberExpression() && !exprIsSure(left, search.external)) {
|
|
305
|
-
|
|
306
|
-
(0, mesh_1.meshExpression)(left.get("object"), search.external);
|
|
307
|
-
checkExpression(right, search);
|
|
308
|
-
/* istanbul ignore else */
|
|
309
|
-
if (!t.isPrivateName(property)) {
|
|
310
|
-
path.replaceWith(search.external.set(left.node.object, !left.node.computed && t.isIdentifier(property) ? t.stringLiteral(property.name) : property, right.node, path.node));
|
|
311
|
-
}
|
|
311
|
+
(0, operators_1.meshAssigment)(path, left, right, left.node.property, search.external);
|
|
312
312
|
}
|
|
313
313
|
else {
|
|
314
314
|
meshLValue(left, search.external);
|
package/lib/jsx.js
CHANGED
|
@@ -48,18 +48,21 @@ function transformJsx(path, conditions, internal) {
|
|
|
48
48
|
}
|
|
49
49
|
return transformJsxArray(path.get("children"), internal);
|
|
50
50
|
}
|
|
51
|
+
function textIsSpacesOnly(node) {
|
|
52
|
+
return t.isJSXText(node) && /^\s+$/.test(node.value) && node.value !== " ";
|
|
53
|
+
}
|
|
51
54
|
function transformJsxArray(paths, internal) {
|
|
52
55
|
const result = [];
|
|
53
56
|
const conditions = { cases: null };
|
|
54
57
|
paths.forEach(path => {
|
|
55
|
-
if (!path.isJSXElement() && !(path.
|
|
58
|
+
if (!path.isJSXElement() && !textIsSpacesOnly(path.node)) {
|
|
56
59
|
result.push(...processConditions(conditions, internal));
|
|
57
60
|
}
|
|
58
61
|
if (path.isJSXElement() || path.isJSXFragment()) {
|
|
59
62
|
result.push(...transformJsx(path, conditions, internal));
|
|
60
63
|
}
|
|
61
64
|
else if (path.isJSXText()) {
|
|
62
|
-
if (
|
|
65
|
+
if (!textIsSpacesOnly(path.node)) {
|
|
63
66
|
const fixed = path.node.value
|
|
64
67
|
.replace(/\n\s+$/m, "")
|
|
65
68
|
.replace(/^\s*\n\s+/m, "")
|
|
@@ -561,26 +564,16 @@ function transformJsxElement(path, conditions, internal) {
|
|
|
561
564
|
if (!t.isJSXText(item)) {
|
|
562
565
|
return true;
|
|
563
566
|
}
|
|
564
|
-
return
|
|
567
|
+
return !textIsSpacesOnly(item);
|
|
565
568
|
});
|
|
566
569
|
const isInternal = internal.mapping.has(name.name);
|
|
567
|
-
|
|
568
|
-
if (
|
|
569
|
-
|
|
570
|
-
(
|
|
571
|
-
t.
|
|
572
|
-
transformJsxExpressionContainer(path.get("children")[element.children.indexOf(filteredChildren[0])], internal, true, isInternal, false, true);
|
|
573
|
-
run = filteredChildren[0].expression;
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
const statements = transformJsxArray(path.get("children"), internal);
|
|
577
|
-
if (statements.length > 0) {
|
|
578
|
-
const params = [internal_js_1.ctx];
|
|
579
|
-
if (!isInternal) {
|
|
580
|
-
params.unshift(t.identifier(`_${internal.prefix}`));
|
|
581
|
-
}
|
|
582
|
-
run = t.arrowFunctionExpression(params, t.blockStatement(statements));
|
|
570
|
+
const statements = transformJsxArray(path.get("children"), internal);
|
|
571
|
+
if (statements.length > 0) {
|
|
572
|
+
const params = [internal_js_1.ctx];
|
|
573
|
+
if (!isInternal) {
|
|
574
|
+
params.unshift(t.identifier(`_${internal.prefix}`));
|
|
583
575
|
}
|
|
576
|
+
run = t.arrowFunctionExpression(params, t.blockStatement(statements));
|
|
584
577
|
}
|
|
585
578
|
const ret = [];
|
|
586
579
|
const filter = (v) => {
|
package/lib/lib.js
CHANGED
|
@@ -112,6 +112,9 @@ function bindCall(path, expr, data, internal, name) {
|
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
114
114
|
function exprCall(path, expr, internal, opts, area) {
|
|
115
|
+
if (path.isTSAsExpression() || path.isTSSatisfiesExpression()) {
|
|
116
|
+
return exprCall(path.get("expression"), path.node.expression, internal, opts, area);
|
|
117
|
+
}
|
|
115
118
|
if (parseCalculateCall(path, internal, area, opts.name)) {
|
|
116
119
|
return true;
|
|
117
120
|
}
|
package/lib/mesh.js
CHANGED
|
@@ -61,6 +61,7 @@ const router_1 = require("./router");
|
|
|
61
61
|
const utils_1 = require("./utils");
|
|
62
62
|
const transformer_1 = require("./transformer");
|
|
63
63
|
const process_types_1 = require("./process-types");
|
|
64
|
+
const operators_1 = require("./operators");
|
|
64
65
|
function meshOrIgnoreAllExpressions(nodePaths, internal) {
|
|
65
66
|
for (const path of nodePaths) {
|
|
66
67
|
/* istanbul ignore else */
|
|
@@ -285,12 +286,7 @@ function meshExpression(nodePath, internal) {
|
|
|
285
286
|
property.name[0] === "$" &&
|
|
286
287
|
t.isThisExpression(left.node.object) &&
|
|
287
288
|
((right.isIdentifier() && (0, expression_js_1.idIsIValue)(right)) || (right.isMemberExpression() && (0, expression_js_1.memberIsIValue)(right.node))))) {
|
|
288
|
-
|
|
289
|
-
meshExpression(right, internal);
|
|
290
|
-
/* istanbul ignore else */
|
|
291
|
-
if (!t.isPrivateName(property)) {
|
|
292
|
-
path.replaceWith(internal.set(left.node.object, !left.node.computed && t.isIdentifier(property) ? t.stringLiteral(property.name) : property, right.node, path.node));
|
|
293
|
-
}
|
|
289
|
+
(0, operators_1.meshAssigment)(path, left, right, property, internal);
|
|
294
290
|
}
|
|
295
291
|
}
|
|
296
292
|
else if (internal.devLayer &&
|
|
@@ -309,9 +305,10 @@ function meshExpression(nodePath, internal) {
|
|
|
309
305
|
const path = nodePath;
|
|
310
306
|
const node = path.node;
|
|
311
307
|
const property = path.node.property;
|
|
308
|
+
const propertyPath = path.get("property");
|
|
312
309
|
meshExpression(path.get("object"), internal);
|
|
313
|
-
if (t.isExpression(property) && !
|
|
314
|
-
meshOrIgnoreExpression(
|
|
310
|
+
if (t.isExpression(property) && (!propertyPath.isIdentifier() || (node.computed && (0, expression_js_1.idIsIValue)(propertyPath)))) {
|
|
311
|
+
meshOrIgnoreExpression(propertyPath, internal);
|
|
315
312
|
}
|
|
316
313
|
if ((0, expression_js_1.memberIsIValue)(node)) {
|
|
317
314
|
if (!(0, expression_js_1.nodeIsMeshed)(path)) {
|
|
@@ -1113,6 +1110,15 @@ function composeStatement(path, internal) {
|
|
|
1113
1110
|
}
|
|
1114
1111
|
meshInit = false;
|
|
1115
1112
|
}
|
|
1113
|
+
else if ((0, call_js_1.calls)(declaration.get("init"), call_js_1.dependencyInjections, internal)) {
|
|
1114
|
+
const callPath = declaration.get("init");
|
|
1115
|
+
callPath.node.arguments.unshift(internal_js_1.ctx);
|
|
1116
|
+
meshAllUnknown(callPath.get("arguments"), internal);
|
|
1117
|
+
meshInit = false;
|
|
1118
|
+
if (t.isIdentifier(id)) {
|
|
1119
|
+
(0, lib_js_1.checkNonReactiveName)(declaration.get("id"), internal);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1116
1122
|
else if (t.isIdentifier(id)) {
|
|
1117
1123
|
const idPath = declaration.get("id");
|
|
1118
1124
|
internal.stack.set(id.name, {});
|
|
@@ -1187,7 +1193,8 @@ function composeStatement(path, internal) {
|
|
|
1187
1193
|
else if (kind === "const" &&
|
|
1188
1194
|
(initPath.isOptionalMemberExpression() || initPath.isMemberExpression()) &&
|
|
1189
1195
|
initPath.node.computed &&
|
|
1190
|
-
t.isIdentifier(initPath.node.property)
|
|
1196
|
+
t.isIdentifier(initPath.node.property) &&
|
|
1197
|
+
!(0, expression_js_1.idIsIValue)(initPath.get("property"))) {
|
|
1191
1198
|
const path = initPath;
|
|
1192
1199
|
const property = path.get("property");
|
|
1193
1200
|
meshExpression(path.get("object"), internal);
|
package/lib/operators.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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.assignmentToBinaryOperator = assignmentToBinaryOperator;
|
|
37
|
+
exports.assignmentToLogicalOperator = assignmentToLogicalOperator;
|
|
38
|
+
exports.meshAssigment = meshAssigment;
|
|
39
|
+
const internal_1 = require("./internal");
|
|
40
|
+
const mesh_1 = require("./mesh");
|
|
41
|
+
const t = __importStar(require("@babel/types"));
|
|
42
|
+
const assigmentToBinaryMap = {
|
|
43
|
+
"+=": "+",
|
|
44
|
+
"-=": "-",
|
|
45
|
+
"/=": "/",
|
|
46
|
+
"%=": "%",
|
|
47
|
+
"*=": "*",
|
|
48
|
+
"**=": "**",
|
|
49
|
+
"&=": "&",
|
|
50
|
+
"|=": "|",
|
|
51
|
+
">>=": ">>",
|
|
52
|
+
">>>=": ">>>",
|
|
53
|
+
"<<=": "<<",
|
|
54
|
+
"^=": "^",
|
|
55
|
+
};
|
|
56
|
+
const assigmentToLogicalMap = {
|
|
57
|
+
"&&=": "&&",
|
|
58
|
+
"||=": "||",
|
|
59
|
+
"??=": "??",
|
|
60
|
+
};
|
|
61
|
+
function assignmentToBinaryOperator(operator) {
|
|
62
|
+
if (operator in assigmentToBinaryMap) {
|
|
63
|
+
return assigmentToBinaryMap[operator];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function assignmentToLogicalOperator(operator) {
|
|
67
|
+
if (operator in assigmentToLogicalMap) {
|
|
68
|
+
return assigmentToLogicalMap[operator];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function meshAssigment(path, left, right, property, internal) {
|
|
72
|
+
const binary = assignmentToBinaryOperator(path.node.operator);
|
|
73
|
+
const logical = assignmentToLogicalOperator(path.node.operator);
|
|
74
|
+
(0, mesh_1.meshExpression)(left.get("object"), internal);
|
|
75
|
+
(0, mesh_1.meshExpression)(right, internal);
|
|
76
|
+
/* istanbul ignore else */
|
|
77
|
+
if (!t.isPrivateName(property)) {
|
|
78
|
+
let replaceWith = right.node;
|
|
79
|
+
if (logical || binary) {
|
|
80
|
+
const meshedLeft = t.optionalMemberExpression(left.node, internal_1.V, false, true);
|
|
81
|
+
if (binary) {
|
|
82
|
+
replaceWith = t.binaryExpression(binary, meshedLeft, right.node);
|
|
83
|
+
}
|
|
84
|
+
if (logical) {
|
|
85
|
+
replaceWith = t.logicalExpression(logical, meshedLeft, right.node);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
path.replaceWith(internal.set(left.node.object, !left.node.computed && t.isIdentifier(property) ? t.stringLiteral(property.name) : property, replaceWith, path.node));
|
|
89
|
+
}
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-vasille",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "Convert Vasille Meta Language code to pure JavaScript",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@types/babel__core": "^7.20.5",
|
|
42
42
|
"@types/jest": "^30.0.0",
|
|
43
43
|
"@types/jsdom": "^21.1.7",
|
|
44
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^25.6.0",
|
|
45
45
|
"cross-env": "^10.0.0",
|
|
46
46
|
"jest": "^30.0.5",
|
|
47
47
|
"jsdom": "^26.1.0",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NodePath, types } from "@babel/core";
|
|
2
|
+
import { Internal } from "./internal";
|
|
3
|
+
declare const assigmentToBinaryMap: {
|
|
4
|
+
readonly "+=": "+";
|
|
5
|
+
readonly "-=": "-";
|
|
6
|
+
readonly "/=": "/";
|
|
7
|
+
readonly "%=": "%";
|
|
8
|
+
readonly "*=": "*";
|
|
9
|
+
readonly "**=": "**";
|
|
10
|
+
readonly "&=": "&";
|
|
11
|
+
readonly "|=": "|";
|
|
12
|
+
readonly ">>=": ">>";
|
|
13
|
+
readonly ">>>=": ">>>";
|
|
14
|
+
readonly "<<=": "<<";
|
|
15
|
+
readonly "^=": "^";
|
|
16
|
+
};
|
|
17
|
+
declare const assigmentToLogicalMap: {
|
|
18
|
+
readonly "&&=": "&&";
|
|
19
|
+
readonly "||=": "||";
|
|
20
|
+
readonly "??=": "??";
|
|
21
|
+
};
|
|
22
|
+
export declare function assignmentToBinaryOperator(operator: string): (typeof assigmentToBinaryMap)[keyof typeof assigmentToBinaryMap] | undefined;
|
|
23
|
+
export declare function assignmentToLogicalOperator(operator: string): (typeof assigmentToLogicalMap)[keyof typeof assigmentToLogicalMap] | undefined;
|
|
24
|
+
export declare function meshAssigment(path: NodePath<types.AssignmentExpression>, left: NodePath<types.MemberExpression>, right: NodePath<types.Expression>, property: types.PrivateName | types.Expression, internal: Internal): void;
|
|
25
|
+
export {};
|