@homebound/truss 2.3.1 → 2.3.3
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 +24 -10
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -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, {
|
|
@@ -2416,27 +2429,28 @@ function transformTruss(code, filename, mapping, options = {}) {
|
|
|
2416
2429
|
runtimeLookupNames
|
|
2417
2430
|
});
|
|
2418
2431
|
const runtimeImports = [];
|
|
2419
|
-
if (needsTrussPropsHelper.current) {
|
|
2432
|
+
if (needsTrussPropsHelper.current && !existingTrussPropsHelperName) {
|
|
2420
2433
|
runtimeImports.push({ importedName: "trussProps", localName: trussPropsHelperName });
|
|
2421
2434
|
}
|
|
2422
|
-
if (needsMergePropsHelper.current) {
|
|
2435
|
+
if (needsMergePropsHelper.current && !existingMergePropsHelperName) {
|
|
2423
2436
|
runtimeImports.push({ importedName: "mergeProps", localName: mergePropsHelperName });
|
|
2424
2437
|
}
|
|
2425
|
-
if (needsTrussDebugInfo.current) {
|
|
2438
|
+
if (needsTrussDebugInfo.current && !existingTrussDebugInfoName) {
|
|
2426
2439
|
runtimeImports.push({ importedName: "TrussDebugInfo", localName: trussDebugInfoName });
|
|
2427
2440
|
}
|
|
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));
|