-
Notifications
You must be signed in to change notification settings - Fork 3
fix(styled-jsx): handle top-level & nesting selector correctly in scopeSelector
#95
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
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/investigate-issue-94
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
514fc5b
fix(styled-jsx): replace lone :scope with scope class to fix & :globa…
Copilot 662d7a5
fix(styled-jsx): strip :scope from all compound selectors, not just l…
Copilot 6005a77
refactor(styled-jsx): remove redundant type assertion in isScopePseudo
Copilot b9150ba
Replace &/:scope two-step with single in-place replacement in scopeSe…
Copilot 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
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,15 @@ | ||
| import css from 'styled-jsx/css' | ||
|
|
||
| // & :global() — leading & should become scope class, not .jsx-HASH:scope | ||
| export const style1 = css` | ||
| & :global(.foo) { | ||
| display: flex; | ||
| } | ||
| ` | ||
|
|
||
| // & .localClass — leading & should become scope class | ||
| export const style2 = css` | ||
| & .bar { | ||
| color: red; | ||
| } | ||
| ` |
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,7 @@ | ||
| //#region virtual:entry.jsx | ||
| const style1 = /* @__PURE__ */ new String(".jsx-16e7d486c32249a4 .foo{display:flex}"); | ||
| style1.__hash = "16e7d486c32249a4"; | ||
| const style2 = /* @__PURE__ */ new String(".jsx-b58be9352957b283 .bar.jsx-b58be9352957b283{color:red}"); | ||
| style2.__hash = "b58be9352957b283"; | ||
| //#endregion | ||
| export { style1, style2 }; |
57 changes: 57 additions & 0 deletions
57
packages/styled-jsx/tests/fixtures/scope-ampersand-patterns/input.jsx
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,57 @@ | ||
| import css from 'styled-jsx/css' | ||
|
|
||
| // Top-level & with additional class — &.foo should become .jsx-HASH.foo | ||
| export const s1 = css` | ||
| &.active { | ||
| color: blue; | ||
| } | ||
| ` | ||
|
|
||
| // Top-level & with pseudo-class — &:hover should become .jsx-HASH:hover | ||
| export const s2 = css` | ||
| &:hover { | ||
| opacity: 0.8; | ||
| } | ||
| ` | ||
|
|
||
| // Top-level & with pseudo-element — &::before should become .jsx-HASH::before | ||
| export const s3 = css` | ||
| &::before { | ||
| content: ''; | ||
| } | ||
| ` | ||
|
|
||
| // Top-level & with :not() — &:not(.foo) should become .jsx-HASH:not(.foo) | ||
| export const s4 = css` | ||
| &:not(.disabled) { | ||
| cursor: pointer; | ||
| } | ||
| ` | ||
|
|
||
| // Top-level & with combined class + pseudo — &.foo:hover should become .jsx-HASH.foo:hover | ||
| export const s5 = css` | ||
| &.active:hover { | ||
| color: green; | ||
| } | ||
| ` | ||
|
|
||
| // Top-level &:global(.foo) (no space) — :scope before :global should be stripped | ||
| export const s6 = css` | ||
| &:global(.theme-dark) { | ||
| background: black; | ||
| } | ||
| ` | ||
|
|
||
| // Adjacent sibling via & — & + .sibling should work | ||
| export const s7 = css` | ||
| & + .sibling { | ||
| margin-left: 8px; | ||
| } | ||
| ` | ||
|
|
||
| // Top-level & alone — already covered by issue-94 but verify | ||
| export const s8 = css` | ||
| & { | ||
| display: block; | ||
| } | ||
| ` |
19 changes: 19 additions & 0 deletions
19
packages/styled-jsx/tests/fixtures/scope-ampersand-patterns/output.jsx
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,19 @@ | ||
| //#region virtual:entry.jsx | ||
| const s1 = /* @__PURE__ */ new String(".jsx-15793d61bc2fad0f.active{color:#00f}"); | ||
| s1.__hash = "15793d61bc2fad0f"; | ||
| const s2 = /* @__PURE__ */ new String(".jsx-440b5f13169269c4:hover{opacity:.8}"); | ||
| s2.__hash = "440b5f13169269c4"; | ||
| const s3 = /* @__PURE__ */ new String(".jsx-ef070750fd73693f:before{content:\"\"}"); | ||
| s3.__hash = "ef070750fd73693f"; | ||
| const s4 = /* @__PURE__ */ new String(".jsx-b0ec419eba2f5953:not(.disabled){cursor:pointer}"); | ||
| s4.__hash = "b0ec419eba2f5953"; | ||
| const s5 = /* @__PURE__ */ new String(".jsx-994a45b09028427d.active:hover{color:green}"); | ||
| s5.__hash = "994a45b09028427d"; | ||
| const s6 = /* @__PURE__ */ new String(".theme-dark{background:#000}"); | ||
| s6.__hash = "b1ebcd8eee3f39f1"; | ||
| const s7 = /* @__PURE__ */ new String(".jsx-a67efca2ae41cf84+.sibling.jsx-a67efca2ae41cf84{margin-left:8px}"); | ||
| s7.__hash = "a67efca2ae41cf84"; | ||
| const s8 = /* @__PURE__ */ new String(".jsx-98cce0331566d37e{display:block}"); | ||
| s8.__hash = "98cce0331566d37e"; | ||
| //#endregion | ||
| export { s1, s2, s3, s4, s5, s6, s7, s8 }; |
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.
It's arguable that
&:global(.foo)should be.jsx-hash.foo, but I think either is fine as&:global(.foo)is contradictory.