-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: correct start of {:else if}
and {:else}
#12043
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
Conversation
🦋 Changeset detectedLatest commit: a46c2de 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 |
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.
Why the change? What's currently there mimics what you get from the Svelte 4 AST - if you paste the code into the Svelte 4 REPL you get the same AST as on Svelte 5 preview.
If there is a good reason to change this we need to make sure to adjust the position to the start of the body when converting to the legacy AST.
On the AST, even though I have checked this in Svelte 4 now, and I think this should fix in Svelte 4 as well, I think. If there is an issue in some Svelte ecosystem, I can implement converting logic for the legacy AST. |
I am currently working on component-level tree shaking and needed this. |
I'm probably ok with changing the behavior for the new AST, but we absolutely should keep it as-is for the legacy AST. I'm pretty sure there's logic in language tools / prettier that relies on the start position being that way. |
I kinda wonder if we should change the shape of the AST in this case rather than just moving the Something like this: export interface IfBlock extends BaseNode {
type: 'IfBlock';
- elseif: boolean;
test: Expression;
consequent: Fragment;
- alternate: Fragment | null;
+ alternate: ElseIfBlock | Fragment | null;
}
+export interface ElseIfBlock extends IfBlock {
+ type: 'ElseIfBlock'
+} |
2c7758f
to
16d839c
Compare
In my personal conclusion, I believe it’s better to use Reason 1: It’s preferable to keep the structure consistent with the JavaScript AST. Different AST structures for JavaScript and Svelte IF statements can cause confusion. It’s better if only the Reason 2: DRY principle regression. |
Svelte 5 rewrite
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
Currently, the AST node for
{:else if}
and{:else}
has its start pointing to the start of the body. However, it should point to the start of the block.https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE2WQu27DMAxFf4VQl7h1amd1HkDHDl2KbnUHQaYTAhJlSFSQwvC_FzKcPtJBD-rcyytpVD1ZjKp5HxVrh6pRT8OgSiWfQy7iGa2gKlX0KZh8sosm0CCHllvpExshz3BEedXceffMsnLEJTh9KWDMIgBHDHt40XJ6NEg2C4rtgvTlinrrfVhl38ICSgr8G87bMAetCriHrIZ17l_Aw7xsoareTpj7kksOKAJejE2RzgiaO5AMia-QeIE5cspTHsZzFDA-scD-7-PWm7qETT3fkXfVz2fweEf94jlAPfca53LKQceAWjCAnDRD3fLYoI0I35bdf4vFGG_0t5IMKuqnllWpnO-oJ-xUIyHh9DF9AVb2PN_dAQAA
With the PR, AST will be like this.