-
-
Notifications
You must be signed in to change notification settings - Fork 103
fix(emotion): merge target/label into non-object-literal styled() options #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Pedro Nascimento (lunks)
wants to merge
1
commit into
swc-project:main
Choose a base branch
from
lunks:fix/emotion-styled-identifier-options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "@swc/plugin-emotion": patch | ||
| --- | ||
|
|
||
| Merge generated `target`/`label` options into non-object-literal `styled` options instead of appending a third argument. | ||
|
|
||
| `styled('div', someIdentifier)` and `styled('div', config.opts)` previously emitted | ||
| `styled('div', someIdentifier, { target, label })`. `@emotion/styled` only reads two | ||
| arguments, so the generated `target` was silently dropped and `${Component}` selectors | ||
| against those components broke at runtime with no build-time signal. These now spread the | ||
| original expression into the options object, matching the existing handling of call | ||
| expressions such as `styled('div', makeOptions())`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/emotion/transform/tests/fixture/styled-non-literal-options/input.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import styled from "@emotion/styled"; | ||
|
|
||
| const opts = { shouldForwardProp: (p: string) => !p.startsWith("$") }; | ||
| const config = { opts }; | ||
|
|
||
| const IdentTpl = styled("div", opts)`color: red;`; | ||
| const IdentCall = styled("div", opts)({ color: "red" }); | ||
| const MemberTpl = styled("div", config.opts)`color: red;`; | ||
| const MemberCall = styled("div", config.opts)({ color: "red" }); |
31 changes: 31 additions & 0 deletions
31
packages/emotion/transform/tests/fixture/styled-non-literal-options/output.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import styled from "@emotion/styled"; | ||
| const opts = { | ||
| shouldForwardProp: (p: string)=>!p.startsWith("$") | ||
| }; | ||
| const config = { | ||
| opts | ||
| }; | ||
| const IdentTpl = /*#__PURE__*/ styled("div", { | ||
| target: "e18y1z280", | ||
| label: "IdentTpl", | ||
| ...opts | ||
| })("color:red;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSBcIkBlbW90aW9uL3N0eWxlZFwiO1xuXG5jb25zdCBvcHRzID0geyBzaG91bGRGb3J3YXJkUHJvcDogKHA6IHN0cmluZykgPT4gIXAuc3RhcnRzV2l0aChcIiRcIikgfTtcbmNvbnN0IGNvbmZpZyA9IHsgb3B0cyB9O1xuXG5jb25zdCBJZGVudFRwbCA9IHN0eWxlZChcImRpdlwiLCBvcHRzKWBjb2xvcjogcmVkO2A7XG5jb25zdCBJZGVudENhbGwgPSBzdHlsZWQoXCJkaXZcIiwgb3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbmNvbnN0IE1lbWJlclRwbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cylgY29sb3I6IHJlZDtgO1xuY29uc3QgTWVtYmVyQ2FsbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLaUIifQ== */"); | ||
| const IdentCall = /*#__PURE__*/ styled("div", { | ||
| target: "e18y1z281", | ||
| label: "IdentCall", | ||
| ...opts | ||
| })({ | ||
| color: "red" | ||
| }, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSBcIkBlbW90aW9uL3N0eWxlZFwiO1xuXG5jb25zdCBvcHRzID0geyBzaG91bGRGb3J3YXJkUHJvcDogKHA6IHN0cmluZykgPT4gIXAuc3RhcnRzV2l0aChcIiRcIikgfTtcbmNvbnN0IGNvbmZpZyA9IHsgb3B0cyB9O1xuXG5jb25zdCBJZGVudFRwbCA9IHN0eWxlZChcImRpdlwiLCBvcHRzKWBjb2xvcjogcmVkO2A7XG5jb25zdCBJZGVudENhbGwgPSBzdHlsZWQoXCJkaXZcIiwgb3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbmNvbnN0IE1lbWJlclRwbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cylgY29sb3I6IHJlZDtgO1xuY29uc3QgTWVtYmVyQ2FsbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNa0IifQ== */"); | ||
| const MemberTpl = /*#__PURE__*/ styled("div", { | ||
| target: "e18y1z282", | ||
| label: "MemberTpl", | ||
| ...config.opts | ||
| })("color:red;", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSBcIkBlbW90aW9uL3N0eWxlZFwiO1xuXG5jb25zdCBvcHRzID0geyBzaG91bGRGb3J3YXJkUHJvcDogKHA6IHN0cmluZykgPT4gIXAuc3RhcnRzV2l0aChcIiRcIikgfTtcbmNvbnN0IGNvbmZpZyA9IHsgb3B0cyB9O1xuXG5jb25zdCBJZGVudFRwbCA9IHN0eWxlZChcImRpdlwiLCBvcHRzKWBjb2xvcjogcmVkO2A7XG5jb25zdCBJZGVudENhbGwgPSBzdHlsZWQoXCJkaXZcIiwgb3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbmNvbnN0IE1lbWJlclRwbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cylgY29sb3I6IHJlZDtgO1xuY29uc3QgTWVtYmVyQ2FsbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFPa0IifQ== */"); | ||
| const MemberCall = /*#__PURE__*/ styled("div", { | ||
| target: "e18y1z283", | ||
| label: "MemberCall", | ||
| ...config.opts | ||
| })({ | ||
| color: "red" | ||
| }, "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSBcIkBlbW90aW9uL3N0eWxlZFwiO1xuXG5jb25zdCBvcHRzID0geyBzaG91bGRGb3J3YXJkUHJvcDogKHA6IHN0cmluZykgPT4gIXAuc3RhcnRzV2l0aChcIiRcIikgfTtcbmNvbnN0IGNvbmZpZyA9IHsgb3B0cyB9O1xuXG5jb25zdCBJZGVudFRwbCA9IHN0eWxlZChcImRpdlwiLCBvcHRzKWBjb2xvcjogcmVkO2A7XG5jb25zdCBJZGVudENhbGwgPSBzdHlsZWQoXCJkaXZcIiwgb3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbmNvbnN0IE1lbWJlclRwbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cylgY29sb3I6IHJlZDtgO1xuY29uc3QgTWVtYmVyQ2FsbCA9IHN0eWxlZChcImRpdlwiLCBjb25maWcub3B0cykoeyBjb2xvcjogXCJyZWRcIiB9KTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFRbUIifQ== */"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the second argument is itself spread, such as
styled("div", ...args)(styles), this arm replaces only its expression while retainingExprOrSpread.spread. The emitted call becomesstyled("div", ...{ target, label, ...args }), and attempting to spread that non-iterable object into the call throws at runtime. Check and handle the argument's spread marker before applying this wrapper; the mirrored tagged-template path has the same issue.Useful? React with 👍 / 👎.