Skip to content

Comments

feat(formatter): support css prop, styled jsx, and member/computed styled.tags#17990

Merged
leaysgur merged 9 commits intooxc-project:mainfrom
magic-akari:feat/embedded-formatting-full-support
Jan 16, 2026
Merged

feat(formatter): support css prop, styled jsx, and member/computed styled.tags#17990
leaysgur merged 9 commits intooxc-project:mainfrom
magic-akari:feat/embedded-formatting-full-support

Conversation

@magic-akari
Copy link
Contributor

@magic-akari magic-akari commented Jan 14, 2026

This PR adds support for embedded language formatting in styled-components and styled-jsx patterns:

Changes

  • Support styled.div`...` tagged templates: Allow formatting of tagged templates with member expressions like styled.div, enabling better support for styled-components
  • Support styled["computed"]`...` : Handle static computed member expressions in styled tags
  • Support styled(Component)`...` : Handle styled calls with component arguments for styled-components
  • Support <div css={`...`} />: Format CSS content in JSX css prop
  • Support <style jsx>{`...`}</style>: Format Styled JSX content in JSX elements

Related Issues

Known Limitations

  • Template substitution is not supported: Expressions inside template literals like css`color: ${THIS_VAR};` are not yet supported

@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Jan 14, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 14, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing magic-akari:feat/embedded-formatting-full-support (a210d8a) with main (125962d)

Summary

✅ 38 untouched benchmarks
⏩ 7 skipped benchmarks1

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Allow formatting of tagged templates with member expressions like `styled.div`,
enabling better support for styled-components and similar libraries.
@magic-akari magic-akari force-pushed the feat/embedded-formatting-full-support branch from a3342c1 to ae389fa Compare January 14, 2026 11:40
@magic-akari magic-akari changed the title feat(formatter): support styled.div tagged templates feat(formatter): support css prop, styled jsx, and member/computed styled.tags Jan 14, 2026
@magic-akari magic-akari marked this pull request as ready for review January 14, 2026 13:14
@magic-akari magic-akari requested a review from Dunqing as a code owner January 14, 2026 13:14
Copilot AI review requested due to automatic review settings January 14, 2026 13:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the formatter's embedded language support to handle CSS in styled-components and styled-jsx patterns, building on existing embedded language formatting infrastructure.

Changes:

  • Extended tag name extraction to support member expressions (styled.div) and computed members (styled["a"])
  • Added context tracking for template literals in CSS props and styled-jsx elements
  • Implemented formatting for CSS content in JSX css props and <style jsx> elements

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
crates/oxc_formatter/src/print/template.rs Added get_tag_name function to extract tag names from complex expressions; added try_format_css_template to format template literals in CSS contexts
crates/oxc_formatter/src/print/jsx/mod.rs Added context management for css prop and styled-jsx template literals with helper functions to detect these patterns
crates/oxc_formatter/src/formatter/context.rs Added TemplateLiteralContext enum and stack management methods for tracking template literal formatting contexts
crates/oxc_formatter/src/formatter/mod.rs Exported new TemplateLiteralContext type
apps/oxfmt/test/cli/embedded_languages/fixtures/embedded_languages.js Added test cases for member expression tags, css props, and styled-jsx
apps/oxfmt/test/cli/embedded_languages/__snapshots__/embedded_languages.test.ts.snap Updated snapshots with formatted output for new test cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Instead of manually maintaining a context stack for `styled-jsx` and `css` props, derive the context directly from the AST parent nodes.

This simplifies `FormatContext` and reduces state management overhead in JSX printing.
Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some refactoring needed.

@magic-akari magic-akari requested a review from Dunqing January 15, 2026 14:56
Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I pushed a commit to rename get_template_literal_context and add comments

@Dunqing Dunqing requested a review from leaysgur January 16, 2026 06:30
@Dunqing
Copy link
Member

Dunqing commented Jan 16, 2026

@leaysgur, would you mind reviewing this last round? If okay, merge it!

@leaysgur
Copy link
Member

Thanks, I will take a look soon. 🙆🏻

Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! LGMT this time. 🙆🏻

@leaysgur leaysgur merged commit fd2c792 into oxc-project:main Jan 16, 2026
27 checks passed
@magic-akari magic-akari deleted the feat/embedded-formatting-full-support branch January 16, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants