@vertz/ui-compiler 0.2.3 → 0.2.5
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/dist/index.js +29 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -557,8 +557,12 @@ class ReactivityAnalyzer {
|
|
|
557
557
|
const name = decl.getName();
|
|
558
558
|
const deps = init ? collectIdentifierRefs(init) : [];
|
|
559
559
|
const entry = { start: decl.getStart(), end: decl.getEnd(), deps };
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
let callInit = init;
|
|
561
|
+
if (callInit?.isKind(SyntaxKind6.NonNullExpression)) {
|
|
562
|
+
callInit = callInit.getExpression();
|
|
563
|
+
}
|
|
564
|
+
if (callInit?.isKind(SyntaxKind6.CallExpression)) {
|
|
565
|
+
const callExpr = callInit.asKindOrThrow(SyntaxKind6.CallExpression);
|
|
562
566
|
const callName = callExpr.getExpression();
|
|
563
567
|
if (callName.isKind(SyntaxKind6.Identifier)) {
|
|
564
568
|
const fnName = callName.getText();
|
|
@@ -1106,6 +1110,24 @@ function transformComputedReads(source, bodyNode, computeds) {
|
|
|
1106
1110
|
|
|
1107
1111
|
// src/transformers/jsx-transformer.ts
|
|
1108
1112
|
import { SyntaxKind as SyntaxKind10 } from "ts-morph";
|
|
1113
|
+
function cleanJsxText(raw) {
|
|
1114
|
+
if (!raw.includes(`
|
|
1115
|
+
`) && !raw.includes("\r")) {
|
|
1116
|
+
return raw;
|
|
1117
|
+
}
|
|
1118
|
+
const lines = raw.split(/\r\n|\n|\r/);
|
|
1119
|
+
const cleaned = [];
|
|
1120
|
+
for (let i = 0;i < lines.length; i++) {
|
|
1121
|
+
let line = lines[i].replace(/\t/g, " ");
|
|
1122
|
+
if (i > 0)
|
|
1123
|
+
line = line.trimStart();
|
|
1124
|
+
if (i < lines.length - 1)
|
|
1125
|
+
line = line.trimEnd();
|
|
1126
|
+
if (line)
|
|
1127
|
+
cleaned.push(line);
|
|
1128
|
+
}
|
|
1129
|
+
return cleaned.join(" ");
|
|
1130
|
+
}
|
|
1109
1131
|
var varCounter = 0;
|
|
1110
1132
|
function genVar() {
|
|
1111
1133
|
return `__el${varCounter++}`;
|
|
@@ -1158,7 +1180,7 @@ function transformJsxNode(node, reactiveNames, jsxMap, source, formVarNames = ne
|
|
|
1158
1180
|
return transformFragment(node, reactiveNames, jsxMap, source, formVarNames);
|
|
1159
1181
|
}
|
|
1160
1182
|
if (node.isKind(SyntaxKind10.JsxText)) {
|
|
1161
|
-
const text = node.
|
|
1183
|
+
const text = cleanJsxText(node.getFullText());
|
|
1162
1184
|
if (!text)
|
|
1163
1185
|
return "";
|
|
1164
1186
|
return `__staticText(${JSON.stringify(text)})`;
|
|
@@ -1305,7 +1327,7 @@ function processAttribute(attr, elVar, jsxMap, source) {
|
|
|
1305
1327
|
}
|
|
1306
1328
|
function transformChild(child, reactiveNames, jsxMap, parentVar, source, formVarNames = new Set) {
|
|
1307
1329
|
if (child.isKind(SyntaxKind10.JsxText)) {
|
|
1308
|
-
const text = child.
|
|
1330
|
+
const text = cleanJsxText(child.getFullText());
|
|
1309
1331
|
if (!text)
|
|
1310
1332
|
return null;
|
|
1311
1333
|
return `__append(${parentVar}, __staticText(${JSON.stringify(text)}))`;
|
|
@@ -1325,7 +1347,7 @@ function transformChild(child, reactiveNames, jsxMap, parentVar, source, formVar
|
|
|
1325
1347
|
return listCode;
|
|
1326
1348
|
}
|
|
1327
1349
|
}
|
|
1328
|
-
const exprText =
|
|
1350
|
+
const exprText = sliceWithTransformedJsx(exprNode, reactiveNames, jsxMap, source, formVarNames);
|
|
1329
1351
|
if (exprInfo?.reactive) {
|
|
1330
1352
|
return `__append(${parentVar}, __child(() => ${exprText}))`;
|
|
1331
1353
|
}
|
|
@@ -1339,7 +1361,7 @@ function transformChild(child, reactiveNames, jsxMap, parentVar, source, formVar
|
|
|
1339
1361
|
}
|
|
1340
1362
|
function transformChildAsValue(child, reactiveNames, jsxMap, source, formVarNames = new Set) {
|
|
1341
1363
|
if (child.isKind(SyntaxKind10.JsxText)) {
|
|
1342
|
-
const text = child.
|
|
1364
|
+
const text = cleanJsxText(child.getFullText());
|
|
1343
1365
|
if (!text)
|
|
1344
1366
|
return null;
|
|
1345
1367
|
return `__staticText(${JSON.stringify(text)})`;
|
|
@@ -1355,7 +1377,7 @@ function transformChildAsValue(child, reactiveNames, jsxMap, source, formVarName
|
|
|
1355
1377
|
return conditionalCode;
|
|
1356
1378
|
}
|
|
1357
1379
|
}
|
|
1358
|
-
const exprText =
|
|
1380
|
+
const exprText = sliceWithTransformedJsx(exprNode, reactiveNames, jsxMap, source, formVarNames);
|
|
1359
1381
|
if (exprInfo?.reactive) {
|
|
1360
1382
|
return `__child(() => ${exprText})`;
|
|
1361
1383
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertz/ui-compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Vertz UI compiler — SSR and build-time optimizations",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ampproject/remapping": "^2.3.0",
|
|
31
|
-
"@vertz/ui": "0.2.2",
|
|
31
|
+
"@vertz/ui": "^0.2.2",
|
|
32
32
|
"magic-string": "^0.30.0",
|
|
33
33
|
"ts-morph": "^27.0.2"
|
|
34
34
|
},
|