-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 5: Creating snippets in .svelte.js
/ .svelte.ts
files
#11261
Comments
.svelte.js
/ .svelte.ts
files.svelte.js
/ .svelte.ts
files
This will mean that neither JS/TS parsers nor JSX parsers will be able to understand |
@7nik My bad! True, |
Hi! I made svelte-jsx-snippet to create snippets with JSX. |
Now, we can create snippet everywhere! |
Describe the problem
I would say that, undoubtedly, the biggest (and only?) advantage React has over Svelte, is jsx. Just open any js/ts file and write:
No need to create a component. This is incredibly helpful, for example, when using libraries like Storybook, with decorator functions. A decorator function in Storybook in React might look like this:
To implement this feature in Svelte, decorator functions return a component in Svelte Storybook. To do the same, one would have to write this as the decorator:
and
Generally, to bridge the gap between Svelte and regular JS/TS, one has to write a Svelte component file for everything. This is one of the less fun parts of Svelte - sometimes, you need to be able to write some Svelte code, and writing a new component file, giving it a name, figuring out where to place it just sucks. This is also a lot of work for library authors - for example, to this day, Storybook still doesn't support creating stories of components with slots. Additionally, just to make the feature above work, they inject the decorator code into an actual Svelte component, which allowed calling
setContext
from withing the decorator function.Describe the proposed solution
Since snippets, under the hood, are just plain JS values/functions, it would be awesome to be able to write snippets directly in
.svelte.ts
/.svelte.js
files. Then, one could write a decorator like this:Snippets with arguments could look like so:
The possibilities would be endless!
Alternative syntax
Regardless, I think the requirements for any syntax are:
.js
/.ts
a
/b
abovectx.globals.marginSize
aboveQuestions
How should
${...}
be treated/used? There are a couple of possibilities here:${}
the same as{}
is normally treated in.svelte
filesImportance
would make my life easier
The text was updated successfully, but these errors were encountered: