fix: print a space before the catch binding in {#await ... catch x} - #18645
Open
winklemad wants to merge 1 commit into
Open
fix: print a space before the catch binding in {#await ... catch x}#18645winklemad wants to merge 1 commit into
{#await ... catch x}#18645winklemad wants to merge 1 commit into
Conversation
The AwaitBlock printer gated the space after `catch` on `node.value`,
which is the then binding, rather than `node.error`. With no then
clause `node.value` is null, so `{#await promise catch error}` printed
as `{#await promise catcherror}`, which no longer parses. The same line
also broke `{:then}` followed by `{:catch error}`, printing `{:catcherror}`.
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/831ffb315b90c0d93611308573c728913e64b88bOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 831ffb3 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 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
print()emits unparseable output for the shorthand{#await ... catch x}form. Round-tripping the example straight out of the await docs:The catch clause gates its trailing space on
node.value— the then binding — instead ofnode.error:if (node.catch) { - context.write(node.value ? 'catch ' : 'catch'); + context.write(node.error ? 'catch ' : 'catch'); if (node.error) context.visit(node.error);The
thenclause immediately above is correct (node.value ? 'then ' : 'then', paired withcontext.visit(node.value)), so this looks like it was copied down without swapping the property.It also affects the long form whenever
{:then}has no binding, sincenode.valueis null there too:{#await p}{:then v}{:catch e}round-trips today only incidentally, becausenode.valuehappens to be truthy.node.errorappears exactly once in the printer, and there are only two space-gating ternaries of this shape — line 692 (then, correct) and this one — so this is the whole class.Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.tests/print/samples/await-block-shorthand. Onmainit fails withexpected '{#await promise catcherror}…' to deeply equal '{#await promise catch error}…'. The sample also covers{:catch}and{#await p then v}with no binding, which must keep emitting a barecatch/then— so the fix can't over-correct.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lintpnpm test: 33 files, 7687 passed, 69 skipped, 0 failed.pnpm lint: eslint clean, prettier clean.