@aerobuilt/core 0.2.4 → 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/vite/index.js +35 -11
- package/package.json +2 -2
package/dist/vite/index.js
CHANGED
|
@@ -283,6 +283,19 @@ function parse(html) {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
// src/compiler/helpers.ts
|
|
286
|
+
function validateSingleBracedExpression(value, options = {}) {
|
|
287
|
+
const trimmed = value.trim();
|
|
288
|
+
const segments = tokenizeCurlyInterpolation(trimmed, { attributeMode: true });
|
|
289
|
+
const ok = segments.length === 1 && segments[0].kind === "interpolation" && segments[0].start === 0 && segments[0].end === trimmed.length;
|
|
290
|
+
if (!ok) {
|
|
291
|
+
const directive = options.directive ?? "directive";
|
|
292
|
+
const tagName = options.tagName ?? "element";
|
|
293
|
+
throw new Error(
|
|
294
|
+
`Directive \`${directive}\` on <${tagName}> must use a braced expression, e.g. ${directive}="{ expression }".`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
return trimmed;
|
|
298
|
+
}
|
|
286
299
|
function compileInterpolation(text) {
|
|
287
300
|
if (!text) return "";
|
|
288
301
|
const segments = tokenizeCurlyInterpolation(text, { attributeMode: false });
|
|
@@ -592,7 +605,17 @@ var Lowerer = class {
|
|
|
592
605
|
}
|
|
593
606
|
return null;
|
|
594
607
|
}
|
|
595
|
-
|
|
608
|
+
/**
|
|
609
|
+
* Require directive value to be a braced expression; optionally strip outer braces.
|
|
610
|
+
*
|
|
611
|
+
* @param value - Raw attribute value.
|
|
612
|
+
* @param directive - Attribute name for error message (e.g. `each`, `pass:data`).
|
|
613
|
+
* @param node - DOM node for error message (tag name).
|
|
614
|
+
* @param options - `strip: true` (default) returns inner expression; `strip: false` returns trimmed value including braces (e.g. for pass:data).
|
|
615
|
+
* @returns Trimmed value, with or without outer braces per options.
|
|
616
|
+
*/
|
|
617
|
+
requireBracedExpression(value, directive, node, options) {
|
|
618
|
+
const strip = options?.strip !== false;
|
|
596
619
|
const trimmed = value.trim();
|
|
597
620
|
if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
|
|
598
621
|
const tagName = node?.tagName?.toLowerCase?.() || "element";
|
|
@@ -600,7 +623,7 @@ var Lowerer = class {
|
|
|
600
623
|
`Directive \`${directive}\` on <${tagName}> must use a braced expression, e.g. ${directive}="{ expression }".`
|
|
601
624
|
);
|
|
602
625
|
}
|
|
603
|
-
return stripBraces(trimmed);
|
|
626
|
+
return strip ? stripBraces(trimmed) : trimmed;
|
|
604
627
|
}
|
|
605
628
|
isSingleWrappedExpression(value) {
|
|
606
629
|
const trimmed = value.trim();
|
|
@@ -680,7 +703,10 @@ var Lowerer = class {
|
|
|
680
703
|
if (isAttr(attr.name, ATTR_ELSE_IF, ATTR_PREFIX)) continue;
|
|
681
704
|
if (isAttr(attr.name, ATTR_ELSE, ATTR_PREFIX)) continue;
|
|
682
705
|
if (isAttr(attr.name, ATTR_PASS_DATA, ATTR_PREFIX)) {
|
|
683
|
-
passDataExpr =
|
|
706
|
+
passDataExpr = validateSingleBracedExpression(attr.value || "", {
|
|
707
|
+
directive: attr.name,
|
|
708
|
+
tagName: node?.tagName?.toLowerCase?.() || "element"
|
|
709
|
+
});
|
|
684
710
|
continue;
|
|
685
711
|
}
|
|
686
712
|
if (attr.name === ATTR_IS_INLINE) {
|
|
@@ -1009,7 +1035,7 @@ function compile(parsed, options) {
|
|
|
1009
1035
|
const tagExpr = `'<script ${baseAttrsEscaped} src="'+${urlExpr}+'"></script>'`;
|
|
1010
1036
|
const isHead = clientScript.injectInHead;
|
|
1011
1037
|
if (clientScript.passDataExpr) {
|
|
1012
|
-
const jsonExpr = `JSON.stringify(${
|
|
1038
|
+
const jsonExpr = `JSON.stringify(${clientScript.passDataExpr})`;
|
|
1013
1039
|
if (isHead) {
|
|
1014
1040
|
headScripts.push(
|
|
1015
1041
|
`(function(){const __pid=Aero.nextPassDataId();\`<\`+'script type="application/json" id="'+__pid+'" class="__aero_data">'+${jsonExpr}+'</'+'script>';window.__aero_data_next=JSON.parse(document.getElementById("'+__pid+'").textContent);})();${tagExpr}`
|
|
@@ -1031,13 +1057,11 @@ function compile(parsed, options) {
|
|
|
1031
1057
|
if (options.blockingScripts) {
|
|
1032
1058
|
for (const blockingScript of options.blockingScripts) {
|
|
1033
1059
|
if (blockingScript.passDataExpr) {
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}
|
|
1040
|
-
const jsMapExpr = `Object.entries(${stripBraces(blockingScript.passDataExpr)}).map(([k, v]) => "\\nconst " + k + " = " + JSON.stringify(v) + ";").join("")`;
|
|
1060
|
+
const passDataExpr = validateSingleBracedExpression(blockingScript.passDataExpr, {
|
|
1061
|
+
directive: "pass:data",
|
|
1062
|
+
tagName: "script"
|
|
1063
|
+
});
|
|
1064
|
+
const jsMapExpr = `Object.entries(${passDataExpr}).map(([k, v]) => "\\nconst " + k + " = " + JSON.stringify(v) + ";").join("")`;
|
|
1041
1065
|
headScripts.push(
|
|
1042
1066
|
`\`<script${blockingScript.attrs ? " " + blockingScript.attrs : ""}>\${${jsMapExpr}}${blockingScript.content.replace(/`/g, "\\`")}</script>\``
|
|
1043
1067
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerobuilt/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jamie Wilson",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"sharp": "^0.34.5",
|
|
56
56
|
"svgo": "^4.0.0",
|
|
57
57
|
"vite-plugin-image-optimizer": "^2.0.3",
|
|
58
|
-
"@aerobuilt/interpolation": "0.2.
|
|
58
|
+
"@aerobuilt/interpolation": "0.2.5"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"vite": "^8.0.0-0"
|