-
-
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
fix: allow multiple optional parameters with defaults #12070
fix: allow multiple optional parameters with defaults #12070
Conversation
🦋 Changeset detectedLatest commit: f952708 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/svelte/tests/runtime-runes/samples/snippet-optional-arguments-defaults/_config.js
Outdated
Show resolved
Hide resolved
packages/svelte/tests/runtime-runes/samples/snippet-optional-arguments-defaults/main.svelte
Outdated
Show resolved
Hide resolved
Gah, I thought I had it, but I don't — it fails if the sequence expression isn't the last default: {#snippet one(a, b = 1, c = (2, 3))}
{a}{b}{c}
{/snippet}
{#snippet two(a, b = (1, 2), c = 3)}
{a}{b}{c}
{/snippet}
{@render one(0)}/{@render two(0)} |
Someone suggested on discord if we could make parse the whole snippet as a function to acorn and then change stuff around. Do you think it's feasible? |
Seems worth a try, yeah |
I'll try it out and see what i can come up with. |
fa455c4
to
4b740ae
Compare
@paoloricciuti did you mean to force push? looks like previous commits got obliterated |
I just rebased main the hash has changed but the content should be the same.no? |
My bad — I thought I'd pushed the failing test in #12070 (comment) but I didn't |
@Rich-Harris i still need to work on a bunch of things but this seems to work...just pushing to get some feedback (maybe there are better ways to do what i'm doing or pre-existing functions i'm not aware of). |
while (!parser.match(')') || parentheses !== 1) { | ||
if (parser.match('(')) parentheses++; | ||
if (parser.match(')')) parentheses--; | ||
params += parser.read(/^./); |
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.
not a new bug, but this logic probably won't be sufficient because these characters could appear inside strings etc. we should probably fix it both here and inside read_pattern
...
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.
Uh right...would prevent the plus and minus between strings be sufficient? It should right?
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.
strings, comments and regular expressions
just pushed a couple of tweaks — the test is still failing because a |
Uhh I like those changes. Very smart. Btw I think this will also fix #12068 |
Opened #12131 for the bracket matching thing, no sense in letting it hold up this fix. Thanks! |
After sveltejs/svelte#12070 the AST for the SnippetBlock has changed (to be more correct). The problem is that svelte2tsx was using that wrong information for the transformation. This means that currently last version of svelte produces wrong ts code from svelte2tsx.
* fix: allow multiple optional parameters with defaults * Apply suggestions from code review * partial fix * feat: parse as a whole function * couple of fixes * work around acorn-typescript quirks * add the harder test * Update .changeset/ten-geese-share.md --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
Svelte 5 rewrite
Closes #12067 i was not totally confident this was an ok fix but i've seen that a similar trick is used in
read_type_annotation
too so i guess it can be good? Feel free to close if it's not the right fix.Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint