Skip to content

Feat: styled - Support styled.div like shorthand API#275

Merged
github-actions[bot] merged 1 commit intomainfrom
styled-elements
Nov 8, 2025
Merged

Feat: styled - Support styled.div like shorthand API#275
github-actions[bot] merged 1 commit intomainfrom
styled-elements

Conversation

@black7375
Copy link
Contributor

@black7375 black7375 commented Nov 6, 2025

Description

styled support shorthand api

Related Issue

Summary by CodeRabbit

  • New Features

    • Added a shorthand property-access API for styled elements (e.g., styled.div, styled.button) alongside the existing function-call form.
  • Examples

    • Updated example app to use the new shorthand form for creating styled components.
  • Chores

    • Added a changeset entry documenting this minor release.

Additional context

Checklist

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

Adds a property-access styled API (e.g., styled.div(...)) alongside the existing call form, introduces a tags registry and SupportedElements types, rewires the styled export to attach per-tag factories at runtime, and updates the Babel plugin to recognize both API forms; example updated to use the shorthand.

Changes

Cohort / File(s) Summary
Changelog
\.changeset/stupid-hairs-behave.md
New changeset entry documenting the minor release that adds the styled.div shorthand.
Example Update
examples/react-babel/src/App.tsx
Replaced styled("div", {...}) with styled.div({...}) for BaseComponent.
Tag Registry
packages/react/src/tags.ts
New module exporting tags (const array of HTML/SVG tag names), KeyofIntrinsicElements and SupportedElements types; runtime/type-safe tag list.
Core API Refactor
packages/react/src/index.ts
Introduces styledImpl, builds taggedStyled at runtime by iterating tags, exposes styled as Object.assign(styledImpl, taggedStyled as TaggedStyled); updates IntrinsicProps, InferStyledComponentProps, InferStyledComponentElement to use SupportedElements; adds TaggedStyled mapped type.
Babel Plugin Enhancement
packages/babel/src/styled.ts
Adds normalizeStyledCall(callPath) to parse both call and member-expression forms of styled; refactors argument handling to use normalized (tag, styles, rest) and clones rest arguments; updates some import paths to relative.

Sequence Diagram(s)

sequenceDiagram
    actor Dev
    participant App as Application Code
    participant StyledAPI as styled export
    participant Runtime as Per-tag Factories

    Dev->>App: import styled
    App->>StyledAPI: use styled("div", {...})
    App->>StyledAPI: use styled.div({...})

    StyledAPI->>Runtime: Object.assign(styledImpl, taggedStyled)
    Runtime->>StyledAPI: attach per-tag factories (e.g., div)
    StyledAPI->>App: returns StyledComponent

    rect rgb(200,230,255)
      Note right of StyledAPI: styledImpl handles call form
    end

    rect rgb(200,255,220)
      Note right of Runtime: taggedStyled handles property-access form
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay special attention to:
    • packages/react/src/index.ts — runtime composition and typing of TaggedStyled and SupportedElements.
    • packages/babel/src/styled.ts — correctness of normalizeStyledCall for identifier vs member-expression and rest-argument cloning.
    • Cross-file type changes ensuring inference parity between call and property-access forms.

Possibly related PRs

Poem

🐰 I hopped through tags both near and far,
styled.div now shines like a star,
Factories stitched and types in tune,
Babel nods beneath the moon,
A little rabbit celebrates the new rune. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding shorthand API support for styled (e.g., styled.div).
Description check ✅ Passed The description is minimally complete with a topic statement but lacks detail, context, and reviewer guidance compared to the template.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch styled-elements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Triggered from #275 by @​black7375.

Checking if we can fast forward main (4a185b4) to styled-elements (fd03700).

Target branch (main):

commit 4a185b470a8d24ecc6badcb46ea4c0408e486a07 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Sep 27 00:00:00 2025 +0900

    Feat: `theme` - Support `alias` method #270

Pull request (styled-elements):

commit fd03700029f5d7c61b9262af74146ee23567e008 (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Nov 7 02:24:26 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

It is possible to fast forward main (4a185b4) to styled-elements (fd03700). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-elements.

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2025

🦋 Changeset detected

Latest commit: 4504956

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@mincho-js/babel Minor
@mincho-js/react Minor
@mincho-js/integration Patch
react-babel Patch
@mincho-js/esbuild Patch
@mincho-js/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Triggered from #275 by @​black7375.

Checking if we can fast forward main (4a185b4) to styled-elements (ab4985e).

Target branch (main):

commit 4a185b470a8d24ecc6badcb46ea4c0408e486a07 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Sep 27 00:00:00 2025 +0900

    Feat: `theme` - Support `alias` method #270

Pull request (styled-elements):

commit ab4985e9cd12ea8f7bdb7ffc071901af7b5a8fc5 (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Oct 10 00:00:00 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

It is possible to fast forward main (4a185b4) to styled-elements (ab4985e). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-elements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/react-babel/src/App.tsx (1)

3-7: Example will fail at runtime without Babel plugin updates.

This example uses the new styled.div({...}) syntax, but the current Babel plugin (as noted in the review of packages/react/src/index.ts) doesn't handle MemberExpression callees. The plugin only transforms styled(...) calls, not styled.tag(...) calls.

Without the transformation, this code will throw: "This function shouldn't be there in your final code."

Ensure the Babel plugin is updated to handle the new syntax before merging this PR, or temporarily revert this example to use styled("div", {...}) until the plugin is updated.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a185b4 and ab4985e.

📒 Files selected for processing (5)
  • .changeset/mighty-nights-see.md (1 hunks)
  • .changeset/stupid-hairs-behave.md (1 hunks)
  • examples/react-babel/src/App.tsx (1 hunks)
  • packages/react/src/index.ts (6 hunks)
  • packages/react/src/tags.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-09T13:00:38.449Z
Learnt from: black7375
Repo: mincho-js/mincho PR: 113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.

Applied to files:

  • packages/react/src/index.ts
🧬 Code graph analysis (4)
.changeset/mighty-nights-see.md (2)
packages/babel/src/styled.ts (3)
  • styledComponentPlugin (13-103)
  • enter (18-99)
  • CallExpression (27-97)
packages/react/src/runtime.ts (1)
  • $$styled (17-81)
.changeset/stupid-hairs-behave.md (2)
packages/babel/src/styled.ts (3)
  • enter (18-99)
  • styledComponentPlugin (13-103)
  • CallExpression (27-97)
packages/esbuild/src/index.ts (1)
  • minchoEsbuildPlugin (25-131)
examples/react-babel/src/App.tsx (3)
packages/react/src/index.ts (1)
  • styled (152-152)
packages/babel/src/styled.ts (2)
  • enter (18-99)
  • CallExpression (27-97)
packages/react/src/runtime.ts (1)
  • $$styled (17-81)
packages/react/src/index.ts (1)
packages/react/src/tags.ts (2)
  • SupportedElements (4-4)
  • tags (11-148)
🪛 markdownlint-cli2 (0.18.1)
.changeset/mighty-nights-see.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (1)
packages/react/src/index.ts (1)

22-22: Code implementation verified—no changes needed.

All verification points check out:

  • Per-tag factories (lines 146-155): Correctly generated at module load time via tags.forEach, each factory captures the tag string in a closure and forwards to styledImpl
  • Object.assign merge (line 152): Properly combines the styledImpl function with the taggedStyled object, creating both styled("div", ...) and styled.div(...) call patterns
  • Type safety: SupportedElements is a union type derived from the tags array, and TaggedStyled is a mapped type ensuring all tags are available as typed properties
  • Runtime equivalence: Both API forms produce identical output since they both invoke styledImpl(tag, options) through their respective closures

---

**styled**
- Add `style.div` like shorthand API No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo: style.div should be styled.div.

The API name is styled.div, not style.div.

Apply this diff:

-  - Add `style.div` like shorthand API
+  - Add `styled.div` like shorthand API
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Add `style.div` like shorthand API
- Add `styled.div` like shorthand API
🤖 Prompt for AI Agents
In .changeset/mighty-nights-see.md around line 6, there's a typo: the note says
"style.div" but the correct API name is "styled.div"; update the text to replace
`style.div` with `styled.div` so the changelog accurately reflects the API.

Comment on lines +11 to +148
export const tags = [
"a",
"abbr",
"address",
"area",
"article",
"aside",
"audio",
"b",
"base",
"bdi",
"bdo",
"big",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"div",
"dl",
"dt",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"keygen",
"label",
"legend",
"li",
"link",
"main",
"map",
"mark",
"menu",
"menuitem",
"meta",
"meter",
"nav",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"pre",
"progress",
"q",
"rp",
"rt",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"small",
"source",
"span",
"strong",
"style",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"u",
"ul",
"use",
"var",
"video",
"wbr",

// SVG
"circle",
"clipPath",
"defs",
"ellipse",
"foreignObject",
"g",
"image",
"line",
"linearGradient",
"mask",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
"rect",
"stop",
"svg",
"text",
"tspan"
] as const satisfies Array<KeyofIntrinsicElements>;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove deprecated HTML elements from the tags list.

The tags array includes several elements that are deprecated or removed from the HTML5 specification:

  • Line 23: "big" - deprecated in HTML5
  • Line 68: "keygen" - removed from HTML5 specification
  • Line 77: "menuitem" - deprecated and not widely supported

Including these elements may cause issues if future versions of @types/react remove their type definitions, and they represent non-standard HTML practices.

Apply this diff to remove deprecated elements:

   "bdo",
-  "big",
   "blockquote",
   "ins",
   "kbd",
-  "keygen",
   "label",
   "mark",
   "menu",
-  "menuitem",
   "meta",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const tags = [
"a",
"abbr",
"address",
"area",
"article",
"aside",
"audio",
"b",
"base",
"bdi",
"bdo",
"big",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"div",
"dl",
"dt",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"keygen",
"label",
"legend",
"li",
"link",
"main",
"map",
"mark",
"menu",
"menuitem",
"meta",
"meter",
"nav",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"pre",
"progress",
"q",
"rp",
"rt",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"small",
"source",
"span",
"strong",
"style",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"u",
"ul",
"use",
"var",
"video",
"wbr",
// SVG
"circle",
"clipPath",
"defs",
"ellipse",
"foreignObject",
"g",
"image",
"line",
"linearGradient",
"mask",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
"rect",
"stop",
"svg",
"text",
"tspan"
] as const satisfies Array<KeyofIntrinsicElements>;
export const tags = [
"a",
"abbr",
"address",
"area",
"article",
"aside",
"audio",
"b",
"base",
"bdi",
"bdo",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"div",
"dl",
"dt",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"label",
"legend",
"li",
"link",
"main",
"map",
"mark",
"menu",
"meta",
"meter",
"nav",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"pre",
"progress",
"q",
"rp",
"rt",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"small",
"source",
"span",
"strong",
"style",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"u",
"ul",
"use",
"var",
"video",
"wbr",
// SVG
"circle",
"clipPath",
"defs",
"ellipse",
"foreignObject",
"g",
"image",
"line",
"linearGradient",
"mask",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
"rect",
"stop",
"svg",
"text",
"tspan"
] as const satisfies Array<KeyofIntrinsicElements>;
🤖 Prompt for AI Agents
In packages/react/src/tags.ts around lines 11 to 148, the tags array contains
deprecated/removed elements ("big" at ~line 23, "keygen" at ~line 68, and
"menuitem" at ~line 77); remove these three strings from the exported tags const
so the list only contains current HTML and SVG elements, and ensure the trailing
commas and formatting remain valid for the as const satisfies
Array<KeyofIntrinsicElements> declaration.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

Triggered from #275 by @​black7375.

Checking if we can fast forward main (4a185b4) to styled-elements (d2372a5).

Target branch (main):

commit 4a185b470a8d24ecc6badcb46ea4c0408e486a07 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Sep 27 00:00:00 2025 +0900

    Feat: `theme` - Support `alias` method #270

Pull request (styled-elements):

commit d2372a511bd0e3af767e31095805b61c18528d51 (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Oct 10 00:00:00 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

It is possible to fast forward main (4a185b4) to styled-elements (d2372a5). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-elements.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

Triggered from #275 by @​black7375.

Checking if we can fast forward main (4a185b4) to styled-elements (c8bb2b7).

Target branch (main):

commit 4a185b470a8d24ecc6badcb46ea4c0408e486a07 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Sep 27 00:00:00 2025 +0900

    Feat: `theme` - Support `alias` method #270

Pull request (styled-elements):

commit c8bb2b73506bd93c349720787e08275b3fcdc02b (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Oct 10 00:00:00 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

It is possible to fast forward main (4a185b4) to styled-elements (c8bb2b7). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-elements.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

Triggered from #275 by @​black7375.

Checking if we can fast forward main (4a185b4) to styled-elements (53a2a1f).

Target branch (main):

commit 4a185b470a8d24ecc6badcb46ea4c0408e486a07 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Sep 27 00:00:00 2025 +0900

    Feat: `theme` - Support `alias` method #270

Pull request (styled-elements):

commit 53a2a1f3b43babc46d6c21743533afc132ddf596 (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Oct 10 00:00:00 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

It is possible to fast forward main (4a185b4) to styled-elements (53a2a1f). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-elements.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

Triggered from #275 by @​black7375.

Checking if we can fast forward main (4ef0375) to styled-elements (4504956).

Target branch (main):

commit 4ef03753991571c260a79307cde319486b40d6b4 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Oct 10 00:00:00 2025 +0900

    Test: add `theme()` test cases

Pull request (styled-elements):

commit 4504956736658a23a6f0a5d9510bf066a43e614c (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Oct 11 00:00:00 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

It is possible to fast forward main (4ef0375) to styled-elements (4504956). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-elements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.changeset/stupid-hairs-behave.md (1)

6-7: Use a proper markdown heading instead of bold text.

Line 6 uses emphasis (**styled**) which should be a proper heading for better structure and consistency with markdown conventions.

Apply this diff:

-**styled**
-- Add `styled.div` like shorthand API
+## styled
+
+- Add `styled.div` like shorthand API
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53a2a1f and 4504956.

📒 Files selected for processing (5)
  • .changeset/stupid-hairs-behave.md (1 hunks)
  • examples/react-babel/src/App.tsx (1 hunks)
  • packages/babel/src/styled.ts (4 hunks)
  • packages/react/src/index.ts (8 hunks)
  • packages/react/src/tags.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react/src/tags.ts
  • examples/react-babel/src/App.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-12-03T11:16:32.528Z
Learnt from: black7375
Repo: mincho-js/mincho PR: 134
File: packages/transform-to-vanilla/src/transform.ts:49-51
Timestamp: 2024-12-03T11:16:32.528Z
Learning: In projects that target both CommonJS and ES modules, adjusting the TypeScript `module` option may not be feasible. Therefore, using `ts-ignore` comments to suppress TypeScript errors related to `import.meta` is acceptable.

Applied to files:

  • packages/react/src/index.ts
📚 Learning: 2024-10-09T13:00:38.449Z
Learnt from: black7375
Repo: mincho-js/mincho PR: 113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.

Applied to files:

  • packages/react/src/index.ts
🧬 Code graph analysis (2)
packages/babel/src/styled.ts (1)
packages/babel/src/transforms/callExpression.ts (2)
  • Expression (108-138)
  • transformCallExpression (13-81)
packages/react/src/index.ts (3)
packages/react/src/tags.ts (2)
  • SupportedElements (4-4)
  • tags (11-148)
packages/transform-to-vanilla/src/types/style-rule.ts (1)
  • CSSRule (33-33)
packages/react/src/runtime.ts (1)
  • $$styled (17-81)
🪛 markdownlint-cli2 (0.18.1)
.changeset/stupid-hairs-behave.md

6-6: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (5)
packages/react/src/index.ts (2)

119-135: Well-structured type definition for the shorthand API.

The TaggedStyled mapped type correctly captures the per-tag factory signatures, maintaining full type safety for variants and props while supporting the new shorthand syntax.


145-145: Clean composition of the styled API surface.

Using Object.assign to merge styledImpl with the tagged factories is an elegant approach that maintains backward compatibility with styled("div", ...) while adding the new styled.div(...) shorthand.

packages/babel/src/styled.ts (3)

94-170: Excellent implementation of dual-syntax support.

The normalizeStyledCall function correctly handles both API forms:

  • Direct calls: styled("div", {...}) where callee is an Identifier
  • Shorthand calls: styled.div({...}) where callee is a MemberExpression

The tag extraction logic (lines 147-159) properly handles computed properties, identifiers, and string literals, ensuring comprehensive coverage of valid JavaScript syntax.


29-35: Clean separation of concerns with normalization.

Extracting the call pattern recognition into normalizeStyledCall makes the main transform logic cleaner and easier to test. The early return pattern when normalization fails is idiomatic.


102-108: Robust argument filtering for rest parameters.

The toValidRestArguments helper ensures only valid Expression or SpreadElement nodes are propagated, preventing potential AST corruption from argument list holes or JSXText nodes.

Comment on lines +137 to +143
/** NOTE: Make simple type for avoid too complex error
* error TS2590: Expression produces a union type that is too complex to represent.
*/
const taggedStyled: Record<string, unknown> = {};
tags.forEach((tag) => {
taggedStyled[tag] = (options: CSSRule) => styledImpl(tag, options);
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Runtime factory type doesn't match the declared TaggedStyled type.

The runtime implementation at line 142 types the options parameter as CSSRule, but the TaggedStyled type definition (line 127) declares it should accept PatternOptions<RulesVariants, RulesToggleVariants, RulesProps>. CSSRule is narrower and doesn't include variant-related options, causing a type safety gap.

Apply this diff to align the runtime with the type declaration:

 const taggedStyled: Record<string, unknown> = {};
 tags.forEach((tag) => {
-  taggedStyled[tag] = (options: CSSRule) => styledImpl(tag, options);
+  taggedStyled[tag] = (options: PatternOptions) => styledImpl(tag, options);
 });

Note: You may need to import or use the full PatternOptions type. Alternatively, remove the type annotation entirely and let TypeScript infer from styledImpl's signature:

-  taggedStyled[tag] = (options: CSSRule) => styledImpl(tag, options);
+  taggedStyled[tag] = (options) => styledImpl(tag, options);

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/react/src/index.ts around lines 137 to 143, the runtime factory
types the options parameter as CSSRule which conflicts with the declared
TaggedStyled type that expects PatternOptions<RulesVariants,
RulesToggleVariants, RulesProps>; fix by changing the runtime signature to
accept PatternOptions<RulesVariants, RulesToggleVariants, RulesProps> (import
that type if necessary) or remove the explicit options annotation so TypeScript
infers the correct type from styledImpl; ensure the generic type parameters
exactly match those used in the TaggedStyled declaration.

@black7375
Copy link
Contributor Author

/fast-forward

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

Triggered from #275 (comment) by @​black7375.

Trying to fast forward main (4ef0375) to styled-elements (4504956).

Target branch (main):

commit 4ef03753991571c260a79307cde319486b40d6b4 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Fri Oct 10 00:00:00 2025 +0900

    Test: add `theme()` test cases

Pull request (styled-elements):

commit 4504956736658a23a6f0a5d9510bf066a43e614c (pull_request/styled-elements)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Oct 11 00:00:00 2025 +0900

    Feat: `styled` - Support `styled.div` like shorthand API

Fast forwarding main (4ef0375) to styled-elements (4504956).

$ git push origin 4504956736658a23a6f0a5d9510bf066a43e614c:main
To https://github.com/mincho-js/mincho.git
   4ef0375..4504956  4504956736658a23a6f0a5d9510bf066a43e614c -> main

@github-actions github-actions bot merged commit 4504956 into main Nov 8, 2025
12 checks passed
@github-actions github-actions bot deleted the styled-elements branch November 8, 2025 08:40
@github-actions github-actions bot mentioned this pull request Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant