-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(makeStyles): correctly handle computed keys #20969
Merged
layershifter
merged 6 commits into
microsoft:master
from
layershifter:fix/mk-computed-keys
Dec 8, 2021
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed70842
fix(makeStyles): correctly handle computed keys
layershifter b5fe6e5
Change files
layershifter ed684bb
Update change/@fluentui-babel-make-styles-e24db7df-1613-42dd-aa1a-a4d…
layershifter 69922e6
add fixtures for function
layershifter f4b0aff
Merge branch 'fix/mk-computed-keys' of https://github.com/layershifte…
layershifter 7b9cb4c
fix fixtures for function
layershifter 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-babel-make-styles-e24db7df-1613-42dd-aa1a-a4ddb5b85b83.json
This file contains 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 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "fix: handle computed keys on objects", | ||
"packageName": "@fluentui/babel-make-styles", | ||
"email": "[email protected]", | ||
"dependentChangeType": "none" | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-make-styles/__fixtures__/function-imported-keys/code.ts
This file contains 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 { makeStyles } from '@fluentui/react-make-styles'; | ||
import { className, color, selector } from './consts'; | ||
|
||
export const useStyles = makeStyles({ | ||
root: { | ||
[selector]: () => ({ [color]: 'red' }), | ||
[`& .${className}`]: () => ({ color: 'blue' }), | ||
}, | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/babel-make-styles/__fixtures__/function-imported-keys/consts.ts
This file contains 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,3 @@ | ||
export const color = 'color'; | ||
export const className = 'component-foo'; | ||
export const selector = '& .component-bar'; |
13 changes: 13 additions & 0 deletions
13
packages/babel-make-styles/__fixtures__/function-imported-keys/output.ts
This file contains 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,13 @@ | ||
import { __styles } from '@fluentui/react-make-styles'; | ||
import { className, color, selector } from './consts'; | ||
export const useStyles = __styles( | ||
{ | ||
root: { | ||
B0egftl: 'f1wgwx3x', | ||
qhv8v2: 'fglt6ox', | ||
}, | ||
}, | ||
{ | ||
d: ['.f1wgwx3x .component-bar{color:red;}', '.fglt6ox .component-foo{color:blue;}'], | ||
}, | ||
); |
9 changes: 9 additions & 0 deletions
9
packages/babel-make-styles/__fixtures__/object-imported-keys/code.ts
This file contains 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 { makeStyles } from '@fluentui/react-make-styles'; | ||
import { className, selector } from './consts'; | ||
|
||
export const useStyles = makeStyles({ | ||
root: { | ||
[selector]: { color: 'red' }, | ||
[`& .${className}`]: { color: 'blue' }, | ||
}, | ||
}); |
2 changes: 2 additions & 0 deletions
2
packages/babel-make-styles/__fixtures__/object-imported-keys/consts.ts
This file contains 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,2 @@ | ||
export const className = 'component-foo'; | ||
export const selector = '& .component-bar'; |
13 changes: 13 additions & 0 deletions
13
packages/babel-make-styles/__fixtures__/object-imported-keys/output.ts
This file contains 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,13 @@ | ||
import { __styles } from '@fluentui/react-make-styles'; | ||
import { className, selector } from './consts'; | ||
export const useStyles = __styles( | ||
{ | ||
root: { | ||
B0egftl: 'f1wgwx3x', | ||
qhv8v2: 'fglt6ox', | ||
}, | ||
}, | ||
{ | ||
d: ['.f1wgwx3x .component-bar{color:red;}', '.fglt6ox .component-foo{color:blue;}'], | ||
}, | ||
); |
This file contains 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
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.
Can we add a case where the computation is a function call ?
also what happens if the result of the computation is undefined or null ? should we throw ?
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.
I added fixtures for function, that's fun as #20918 will remove it :)
It's tricky as in runtime there will be no errors 🙄
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.
ah I actually meant something along the lines of: