@homebound/truss 2.3.0 → 2.3.2
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 +3 -3
- package/build/index.js.map +1 -1
- package/build/plugin/index.js +26 -12
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -602,13 +602,13 @@ var RELATIONSHIP_SHORT = {
|
|
|
602
602
|
siblingBefore: "sibB",
|
|
603
603
|
anySibling: "anyS"
|
|
604
604
|
};
|
|
605
|
-
var DEFAULT_MARKER_CLASS = "
|
|
605
|
+
var DEFAULT_MARKER_CLASS = "_mrk";
|
|
606
606
|
function markerClassName(markerNode) {
|
|
607
607
|
if (!markerNode) return DEFAULT_MARKER_CLASS;
|
|
608
608
|
if (markerNode.type === "Identifier" && markerNode.name) {
|
|
609
|
-
return `
|
|
609
|
+
return `_${markerNode.name}_mrk`;
|
|
610
610
|
}
|
|
611
|
-
return
|
|
611
|
+
return "_marker_mrk";
|
|
612
612
|
}
|
|
613
613
|
function whenPrefix(whenPseudo) {
|
|
614
614
|
const rel = RELATIONSHIP_SHORT[whenPseudo.relationship ?? "ancestor"] ?? "anc";
|
|
@@ -1615,10 +1615,10 @@ function resolveWhenMarker(node) {
|
|
|
1615
1615
|
if (node.type === "Identifier") {
|
|
1616
1616
|
return node;
|
|
1617
1617
|
}
|
|
1618
|
-
throw new UnsupportedPatternError(`when() marker must be a marker variable or
|
|
1618
|
+
throw new UnsupportedPatternError(`when() marker must be a marker variable or marker`);
|
|
1619
1619
|
}
|
|
1620
1620
|
function isDefaultMarkerNode(node) {
|
|
1621
|
-
if (node.type === "Identifier" && node.name === "defaultMarker") {
|
|
1621
|
+
if (node.type === "Identifier" && (node.name === "marker" || node.name === "defaultMarker")) {
|
|
1622
1622
|
return true;
|
|
1623
1623
|
}
|
|
1624
1624
|
return isLegacyDefaultMarkerExpression(node);
|
|
@@ -1858,6 +1858,17 @@ function findCssImportBinding(ast) {
|
|
|
1858
1858
|
}
|
|
1859
1859
|
return null;
|
|
1860
1860
|
}
|
|
1861
|
+
function findCssBuilderBinding(ast) {
|
|
1862
|
+
for (const node of ast.program.body) {
|
|
1863
|
+
if (!t2.isVariableDeclaration(node)) continue;
|
|
1864
|
+
for (const decl of node.declarations) {
|
|
1865
|
+
if (t2.isIdentifier(decl.id) && decl.init && t2.isNewExpression(decl.init) && t2.isIdentifier(decl.init.callee, { name: "CssBuilder" })) {
|
|
1866
|
+
return decl.id.name;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
return null;
|
|
1871
|
+
}
|
|
1861
1872
|
function hasCssMethodCall(ast, binding, method) {
|
|
1862
1873
|
let found = false;
|
|
1863
1874
|
t2.traverseFast(ast, (node) => {
|
|
@@ -2356,8 +2367,10 @@ function transformTruss(code, filename, mapping, options = {}) {
|
|
|
2356
2367
|
plugins: ["typescript", "jsx"],
|
|
2357
2368
|
sourceFilename: filename
|
|
2358
2369
|
});
|
|
2359
|
-
const
|
|
2370
|
+
const cssImportBinding = findCssImportBinding(ast);
|
|
2371
|
+
const cssBindingName = cssImportBinding ?? findCssBuilderBinding(ast);
|
|
2360
2372
|
if (!cssBindingName) return null;
|
|
2373
|
+
const cssIsImported = cssImportBinding !== null;
|
|
2361
2374
|
const sites = [];
|
|
2362
2375
|
const errorMessages = [];
|
|
2363
2376
|
traverse2(ast, {
|
|
@@ -2428,15 +2441,16 @@ function transformTruss(code, filename, mapping, options = {}) {
|
|
|
2428
2441
|
if (options.injectCss) {
|
|
2429
2442
|
runtimeImports.push({ importedName: "__injectTrussCSS", localName: "__injectTrussCSS" });
|
|
2430
2443
|
}
|
|
2431
|
-
|
|
2432
|
-
if (
|
|
2433
|
-
|
|
2434
|
-
}
|
|
2435
|
-
if (runtimeImports.length > 0) {
|
|
2444
|
+
let reusedCssImportLine = false;
|
|
2445
|
+
if (cssIsImported) {
|
|
2446
|
+
reusedCssImportLine = runtimeImports.length > 0 && findImportDeclaration(ast, "@homebound/truss/runtime") === null && replaceCssImportWithNamedImports(ast, cssBindingName, "@homebound/truss/runtime", runtimeImports);
|
|
2436
2447
|
if (!reusedCssImportLine) {
|
|
2437
|
-
|
|
2448
|
+
removeCssImport(ast, cssBindingName);
|
|
2438
2449
|
}
|
|
2439
2450
|
}
|
|
2451
|
+
if (runtimeImports.length > 0 && !reusedCssImportLine) {
|
|
2452
|
+
upsertNamedImports(ast, "@homebound/truss/runtime", runtimeImports);
|
|
2453
|
+
}
|
|
2440
2454
|
const declarationsToInsert = [];
|
|
2441
2455
|
if (maybeIncHelperName) {
|
|
2442
2456
|
declarationsToInsert.push(buildMaybeIncDeclaration(maybeIncHelperName, mapping.increment));
|