-
-
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
Svelte: Improve argTypes inference with svelte2tsx
- support runes
#29423
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 08c2bb9. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
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.
29 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
return; | ||
} | ||
|
||
const isTsFile = /<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(content); |
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.
style: Regex might not catch all TypeScript lang attributes. Consider using a parser
const isTsFile = /<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(content); | |
import { parse } from 'some-parser-library'; | |
const isTsFile = parse(content).hasTypeScriptLang(); |
export let number = 123; | ||
/** | ||
* True literal | ||
* @type {true=} |
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.
style: true= type annotation might be non-standard, consider using boolean=
* @type {true=} | |
* @type {boolean} |
* Event callback function | ||
* @type {(event: MouseEvent) => number} | ||
*/ | ||
export let func = () => 10; |
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.
style: func prop default value doesn't use event parameter
export let func = () => 10; | |
export let func = (event) => { return 10; }; |
I benchmarked the SvelteKit Prerelease sandbox: diff:
However the results are pretty flaky and I tried a few times. eg. My conclusion is that we're fine. |
This is a copy of #28492 by @ciscorn, only done to be able to apply changes and release with Storybook 8.4.0. See #28492 (review)
All props goes to @ciscorn, they've done all the work here. 🙏🙏🙏
What I did
To support Svelte 5 'runes mode', this PR modifies @storybook/svelte-vite to utilize Svelte’s official svelte2tsx +
typescript
instead of sveltedoc-parser for generating props documentation data.I found that others have mentioned the same idea as well:
Rationale:
sveltedoc-parser
cannot parse Svelte 5 ‘runes mode’ files at all, and it has not been maintained for 3 years.svelte2tsx
is an official component used by Svelte in its language server.typescript
, it provides perfect type resolution and can also handle type hints written in JavaScript + JSDoc as well as TypeScript.export let
style.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
svelte-kit/skeleton-ts
) and Svelte 5 (svelte-kit/prerelease-ts
) sandboxes (feel free to use Chromatic)/?path=/docs/stories-renderers-svelte-docs-ts--docs
/?path=/docs/stories-renderers-svelte-docs-jsdoc--docs
/?path=/docs/stories-renderers-svelte-docs-ts-inline-prop-types--docs
/?path=/docs/stories-renderers-svelte-docs-ts-referenced-prop-types--docs
/?path=/docs/stories-renderers-svelte-docs-jsdoc-runes--docs
example screenshot:
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
Greptile Summary
This pull request improves argTypes inference for Svelte components in Storybook, focusing on supporting Svelte 5's 'runes' mode and enhancing type resolution.