stylex icon indicating copy to clipboard operation
stylex copied to clipboard

[babel-plugin] Optimize dynamic styles output

Open mellyeliu opened this issue 5 months ago • 1 comments

Follow up to https://github.com/facebook/stylex/pull/1153

There are times in which we don't need to emit a ternary wrapping dynamic styles when we can confirm the expression is not null or undefined. We have coverage for binary and unary expressions, but there are a few more cases we can optimize for:

  • template literals
  • conditional exprs (recursively check both sides)
  • logical expressions like
    • nullish coalescing ?? (if left side is safe)
    • logical or || (if either side is safe)
    • logical && (both sides are safe ie. a string/binary/unary/template literal of course).

May be missing some cases

mellyeliu avatar Jul 28 '25 05:07 mellyeliu

  • same treatment for the inline styles portion

mellyeliu avatar Jul 28 '25 08:07 mellyeliu