@homebound/truss 2.11.3 → 2.12.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/build/index.js +10 -0
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +27 -4
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -3111,10 +3111,6 @@ function transformCssTs(code, filename, mapping) {
|
|
|
3111
3111
|
sourceFilename: filename
|
|
3112
3112
|
});
|
|
3113
3113
|
const cssBindingName = findCssImportBinding(ast);
|
|
3114
|
-
if (!cssBindingName) {
|
|
3115
|
-
return `/* [truss] ${filename}: no Css import found */
|
|
3116
|
-
`;
|
|
3117
|
-
}
|
|
3118
3114
|
const cssExport = findNamedCssExportObject(ast);
|
|
3119
3115
|
if (!cssExport) {
|
|
3120
3116
|
return `/* [truss] ${filename}: expected \`export const css = { ... }\` with an object literal */
|
|
@@ -3137,10 +3133,19 @@ function transformCssTs(code, filename, mapping) {
|
|
|
3137
3133
|
continue;
|
|
3138
3134
|
}
|
|
3139
3135
|
const valueNode = prop.value;
|
|
3136
|
+
const rawCss = extractStaticStringValue(valueNode, cssBindingName);
|
|
3137
|
+
if (rawCss !== null) {
|
|
3138
|
+
rules.push(formatRawCssRule(selector, rawCss));
|
|
3139
|
+
continue;
|
|
3140
|
+
}
|
|
3140
3141
|
if (!t6.isExpression(valueNode)) {
|
|
3141
3142
|
rules.push(`/* [truss] unsupported: "${selector}" value is not an expression */`);
|
|
3142
3143
|
continue;
|
|
3143
3144
|
}
|
|
3145
|
+
if (!cssBindingName) {
|
|
3146
|
+
rules.push(`/* [truss] unsupported: "${selector}" \u2014 Css.*.$ chain requires a Css import */`);
|
|
3147
|
+
continue;
|
|
3148
|
+
}
|
|
3144
3149
|
const cssResult = resolveCssExpression(valueNode, cssBindingName, mapping, filename);
|
|
3145
3150
|
if ("error" in cssResult) {
|
|
3146
3151
|
rules.push(`/* [truss] unsupported: "${selector}" \u2014 ${cssResult.error} */`);
|
|
@@ -3174,6 +3179,16 @@ function objectPropertyStringKey(prop, stringBindings) {
|
|
|
3174
3179
|
if (prop.computed) return resolveStaticString(prop.key, stringBindings);
|
|
3175
3180
|
return null;
|
|
3176
3181
|
}
|
|
3182
|
+
function extractStaticStringValue(node, cssBindingName) {
|
|
3183
|
+
if (t6.isStringLiteral(node)) return node.value;
|
|
3184
|
+
if (t6.isTemplateLiteral(node) && node.expressions.length === 0 && node.quasis.length === 1) {
|
|
3185
|
+
return node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
3186
|
+
}
|
|
3187
|
+
if (t6.isTaggedTemplateExpression(node) && t6.isMemberExpression(node.tag) && !node.tag.computed && t6.isIdentifier(node.tag.property, { name: "raw" }) && t6.isIdentifier(node.tag.object, { name: cssBindingName ?? "" }) && node.quasi.expressions.length === 0 && node.quasi.quasis.length === 1) {
|
|
3188
|
+
return node.quasi.quasis[0].value.cooked ?? node.quasi.quasis[0].value.raw;
|
|
3189
|
+
}
|
|
3190
|
+
return null;
|
|
3191
|
+
}
|
|
3177
3192
|
function resolveCssExpression(node, cssBindingName, mapping, filename) {
|
|
3178
3193
|
if (!t6.isMemberExpression(node) || node.computed || !t6.isIdentifier(node.property, { name: "$" })) {
|
|
3179
3194
|
return { error: "value must be a Css.*.$ expression" };
|
|
@@ -3234,6 +3249,14 @@ function resolveCssExpression(node, cssBindingName, mapping, filename) {
|
|
|
3234
3249
|
}
|
|
3235
3250
|
return { declarations };
|
|
3236
3251
|
}
|
|
3252
|
+
function formatRawCssRule(selector, raw) {
|
|
3253
|
+
const trimmed = raw.trim();
|
|
3254
|
+
if (!trimmed) return `${selector} {}`;
|
|
3255
|
+
const body = trimmed.split("\n").map((line) => ` ${line.trim()}`).filter((line) => line.trim().length > 0).join("\n");
|
|
3256
|
+
return `${selector} {
|
|
3257
|
+
${body}
|
|
3258
|
+
}`;
|
|
3259
|
+
}
|
|
3237
3260
|
function formatCssRule(selector, declarations) {
|
|
3238
3261
|
if (declarations.length === 0) {
|
|
3239
3262
|
return `${selector} {}`;
|