@homebound/truss 2.9.0 → 2.9.1
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/plugin/index.js +17 -16
- package/build/plugin/index.js.map +1 -1
- package/build/runtime.js +1 -1
- package/build/runtime.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -2142,10 +2142,25 @@ function buildStyleHashMembers(segments, options) {
|
|
|
2142
2142
|
}
|
|
2143
2143
|
flushNormal();
|
|
2144
2144
|
if (classNameArgs.length > 0) {
|
|
2145
|
-
members.push(
|
|
2145
|
+
members.push(...buildCustomClassNameMembers(classNameArgs));
|
|
2146
2146
|
}
|
|
2147
2147
|
return members;
|
|
2148
2148
|
}
|
|
2149
|
+
function buildCustomClassNameMembers(classNameArgs) {
|
|
2150
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2151
|
+
return classNameArgs.map((arg) => {
|
|
2152
|
+
const baseKey = `className_${sanitizeClassNameKey(arg)}`;
|
|
2153
|
+
const count = (counts.get(baseKey) ?? 0) + 1;
|
|
2154
|
+
counts.set(baseKey, count);
|
|
2155
|
+
const key = count === 1 ? baseKey : `${baseKey}_${count}`;
|
|
2156
|
+
return t3.objectProperty(t3.identifier(key), t3.cloneNode(arg, true));
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
function sanitizeClassNameKey(arg) {
|
|
2160
|
+
const raw = t3.isStringLiteral(arg) ? arg.value : t3.isTemplateLiteral(arg) && arg.expressions.length === 0 && arg.quasis.length === 1 ? arg.quasis[0].value.cooked ?? "" : generate(arg).code;
|
|
2161
|
+
const sanitized = raw.replace(/[^a-zA-Z0-9_$]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
2162
|
+
return sanitized || "value";
|
|
2163
|
+
}
|
|
2149
2164
|
function buildAddCssObjectMembers(styleObject) {
|
|
2150
2165
|
const members = [];
|
|
2151
2166
|
for (const property of styleObject.properties) {
|
|
@@ -2198,9 +2213,6 @@ function mergeConditionalBranchMembers(members, previousProperties, conditionalO
|
|
|
2198
2213
|
}
|
|
2199
2214
|
const prop = propertyName(member.key);
|
|
2200
2215
|
const prior = previousProperties.get(prop);
|
|
2201
|
-
if (prop === "className" && prior) {
|
|
2202
|
-
return t3.objectProperty(clonePropertyKey(member.key), mergeClassNameValues(prior.value, member.value));
|
|
2203
|
-
}
|
|
2204
2216
|
if (!prior || !conditionalOnlyProps.has(prop)) {
|
|
2205
2217
|
return member;
|
|
2206
2218
|
}
|
|
@@ -2226,17 +2238,6 @@ function mergePropertyValues(previousValue, currentValue) {
|
|
|
2226
2238
|
}
|
|
2227
2239
|
return t3.cloneNode(currentValue, true);
|
|
2228
2240
|
}
|
|
2229
|
-
function mergeClassNameValues(previousValue, currentValue) {
|
|
2230
|
-
return t3.arrayExpression([...toClassNameElements(previousValue), ...toClassNameElements(currentValue)]);
|
|
2231
|
-
}
|
|
2232
|
-
function toClassNameElements(value) {
|
|
2233
|
-
if (t3.isArrayExpression(value)) {
|
|
2234
|
-
return value.elements.flatMap((element) => {
|
|
2235
|
-
return element && !t3.isSpreadElement(element) ? [t3.cloneNode(element, true)] : [];
|
|
2236
|
-
});
|
|
2237
|
-
}
|
|
2238
|
-
return [t3.cloneNode(value, true)];
|
|
2239
|
-
}
|
|
2240
2241
|
function mergeTupleValue(tuple, classNames, prependClassNames, previousVars) {
|
|
2241
2242
|
const currentClassNames = tupleClassNames(tuple);
|
|
2242
2243
|
const mergedClassNames = prependClassNames ? `${classNames} ${currentClassNames}` : `${currentClassNames} ${classNames}`;
|
|
@@ -2285,7 +2286,7 @@ function clonePropertyKey(key) {
|
|
|
2285
2286
|
function injectDebugInfo(expr, line, options) {
|
|
2286
2287
|
if (!options.debug) return;
|
|
2287
2288
|
const firstProp = expr.properties.find((p) => {
|
|
2288
|
-
return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name
|
|
2289
|
+
return t3.isObjectProperty(p) && !(t3.isIdentifier(p.key) && p.key.name.startsWith("className_") || t3.isStringLiteral(p.key) && p.key.value.startsWith("className_") || t3.isIdentifier(p.key) && p.key.name === "__marker" || t3.isStringLiteral(p.key) && p.key.value === "__marker");
|
|
2289
2290
|
});
|
|
2290
2291
|
if (!firstProp) return;
|
|
2291
2292
|
options.needsTrussDebugInfo.current = true;
|