-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Csf-tools: Add satisfies
support to ConfigFile
#20936
Csf-tools: Add satisfies
support to ConfigFile
#20936
Conversation
code/lib/csf-tools/src/ConfigFile.ts
Outdated
if (t.isObjectExpression(decl) || t.isTSSatisfiesExpression(decl)) { | ||
const expression = t.isTSSatisfiesExpression(decl) | ||
? (decl.expression as Extract<t.Expression, t.ObjectExpression>) | ||
: decl; | ||
self._exportsObject = expression; | ||
expression.properties.forEach((p: t.ObjectProperty) => { |
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.
satisfies
support to ConfigFile [csf-tools].
satisfies
support to ConfigFile [csf-tools].satisfies
support in ConfigFile
satisfies
support in ConfigFilesatisfies
support to ConfigFile
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.
Nice one @zhyd1997 !! Thanks for this 🙏
@shilman Thanks for your quick review! I am not familiar with the codebase, so please review the PR carefully to make sure it will not break something, If you have any questions , please let me know. |
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 didn't review closely enough. LMK what you think about this
code/lib/csf-tools/src/ConfigFile.ts
Outdated
decl.properties.forEach((p: t.ObjectProperty) => { | ||
if (t.isObjectExpression(decl) || t.isTSSatisfiesExpression(decl)) { | ||
const expression = t.isTSSatisfiesExpression(decl) | ||
? (decl.expression as Extract<t.Expression, t.ObjectExpression>) |
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'm suspicious of this line. I think it should be something like:
let decl =
t.isIdentifier(node.declaration) && t.isProgram(parent)
? _findVarInitialization(node.declaration.name, parent)
: node.declaration;
if(t.isAsExpression(decl) || t.isTSSatisfiesExpression(decl)) {
decl = decl.expression;
}
if(t.isObjectExpression(decl)) {
...
} else {
logger.warn(`Unexpected ${JSON.stringify(node)}`);
}
The problem with the current code is that it assumes the satisfies expression is an ObjectExpression, which might not be the case. For example:
export default 'foo' satisfies Bar;
Nice! Thanks for implementing this! |
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.
Looks great to me, thanks @zhyd1997 !!
Closes #20935
What I did
added
satisfies
support to.storybook/main.ts
:How to test
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]