@homebound/truss 2.11.0 → 2.11.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.
@@ -2848,7 +2848,7 @@ function hasExistingAttribute(path, attrName) {
2848
2848
  var traverse2 = _traverse2.default ?? _traverse2;
2849
2849
  var generate2 = _generate2.default ?? _generate2;
2850
2850
  function transformTruss(code, filename, mapping, options = {}) {
2851
- if (!code.includes("Css")) return null;
2851
+ if (!code.includes("Css") && !code.includes("css=")) return null;
2852
2852
  const ast = parse(code, {
2853
2853
  sourceType: "module",
2854
2854
  plugins: ["typescript", "jsx"],
@@ -2856,14 +2856,15 @@ function transformTruss(code, filename, mapping, options = {}) {
2856
2856
  });
2857
2857
  const cssImportBinding = findCssImportBinding(ast);
2858
2858
  const cssBindingName = cssImportBinding ?? findCssBuilderBinding(ast);
2859
- if (!cssBindingName) return null;
2860
2859
  const cssIsImported = cssImportBinding !== null;
2861
2860
  const sites = [];
2862
2861
  const errorMessages = [];
2863
2862
  let hasCssPropsCall = false;
2863
+ let hasJsxCssAttribute = false;
2864
2864
  traverse2(ast, {
2865
2865
  // -- Css.*.$ chain collection --
2866
2866
  MemberExpression(path) {
2867
+ if (!cssBindingName) return;
2867
2868
  if (!t4.isIdentifier(path.node.property, { name: "$" })) return;
2868
2869
  if (path.node.computed) return;
2869
2870
  const chain = extractChain(path.node.object, cssBindingName);
@@ -2881,14 +2882,21 @@ function transformTruss(code, filename, mapping, options = {}) {
2881
2882
  },
2882
2883
  // -- Css.props() detection (so we don't bail early when there are no Css.*.$ sites) --
2883
2884
  CallExpression(path) {
2884
- if (hasCssPropsCall) return;
2885
+ if (!cssBindingName || hasCssPropsCall) return;
2885
2886
  const callee = path.node.callee;
2886
2887
  if (t4.isMemberExpression(callee) && !callee.computed && t4.isIdentifier(callee.object, { name: cssBindingName }) && t4.isIdentifier(callee.property, { name: "props" })) {
2887
2888
  hasCssPropsCall = true;
2888
2889
  }
2890
+ },
2891
+ // -- JSX css={...} attribute detection (so we don't bail when there are only css props) --
2892
+ JSXAttribute(path) {
2893
+ if (hasJsxCssAttribute) return;
2894
+ if (t4.isJSXIdentifier(path.node.name, { name: "css" })) {
2895
+ hasJsxCssAttribute = true;
2896
+ }
2889
2897
  }
2890
2898
  });
2891
- if (sites.length === 0 && !hasCssPropsCall) return null;
2899
+ if (sites.length === 0 && !hasCssPropsCall && !hasJsxCssAttribute) return null;
2892
2900
  const chains = sites.map((s) => s.resolvedChain);
2893
2901
  const { rules, needsMaybeInc } = collectAtomicRules(chains, mapping);
2894
2902
  const cssText = generateCssText(rules);
@@ -2911,7 +2919,7 @@ function transformTruss(code, filename, mapping, options = {}) {
2911
2919
  rewriteExpressionSites({
2912
2920
  ast,
2913
2921
  sites,
2914
- cssBindingName,
2922
+ cssBindingName: cssBindingName ?? "",
2915
2923
  filename: basename(filename),
2916
2924
  debug: options.debug ?? false,
2917
2925
  mapping,
@@ -2939,9 +2947,9 @@ function transformTruss(code, filename, mapping, options = {}) {
2939
2947
  }
2940
2948
  let reusedCssImportLine = false;
2941
2949
  if (cssIsImported) {
2942
- reusedCssImportLine = runtimeImports.length > 0 && findImportDeclaration(ast, "@homebound/truss/runtime") === null && replaceCssImportWithNamedImports(ast, cssBindingName, "@homebound/truss/runtime", runtimeImports);
2950
+ reusedCssImportLine = runtimeImports.length > 0 && findImportDeclaration(ast, "@homebound/truss/runtime") === null && replaceCssImportWithNamedImports(ast, cssImportBinding, "@homebound/truss/runtime", runtimeImports);
2943
2951
  if (!reusedCssImportLine) {
2944
- removeCssImport(ast, cssBindingName);
2952
+ removeCssImport(ast, cssImportBinding);
2945
2953
  }
2946
2954
  }
2947
2955
  if (runtimeImports.length > 0 && !reusedCssImportLine) {