question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slotted elements missing in AST

See original GitHub issue

Describe the bug The AST for components using a slotted element is missing the slotted element.

Logs n/a

To Reproduce Compile <Component><div slot='foo'></div></Component> with Svelte 3.35.0 and look at the AST.

Expected behavior The AST should be as it was in 3.34.0 and include the <div>.

Stacktraces n/a

Information about your Svelte project: Svelte 3.35.0

Severity The right JS code looks like it’s still being generated, so this isn’t huge. But it will affect tooling. Medium-high I’d say.

Additional context This was brought to light by https://github.com/sveltejs/eslint-plugin-svelte3/issues/94

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
dummdidummcommented, Mar 12, 2021

I want to point out that language tools (with svelte2tsx), the prettier plugin and the eslint plugin all rely on the AST to some extend, so while the API is technically private, it’s still something we can’t change it at will.

3reactions
tanhauhaucommented, Mar 10, 2021

oh no 😦

I rearranged the children of the InlineComponent node to wrap <element slot="xxx">, <Component slot="xxx"> with <svelte:fragment slot="xxx">, and all the remaining elements with <svelte:fragment>

In this step, I mutated the AST node. (L114)

https://github.com/sveltejs/svelte/blob/1d6e20f2a967aebfa9c3eab769ca587345169632/src/compiler/compile/nodes/InlineComponent.ts#L109-L150

So, I have 2 options from here:

  1. used the updated AST with <svelte:fragment> inserted

+ // assign back the children with updated children
+ info.children = children
  this.children = map_children(component, this, this.scope, children);
  1. freeze the ast.html before mutation as well

https://github.com/sveltejs/svelte/blob/2925a00eff74414d5bc1d28a492e54ff827d00a6/src/compiler/compile/Component.ts#L117-L124

this.original_ast = {
	html: JSON.parse(JSON.stringify(ast.html)),
	css: ast.css,
	instance: ast.instance && JSON.parse(JSON.stringify(ast.instance)),
	module: ast.module
};

or rather

this.original_ast = JSON.parse(JSON.stringify({
	html: ast.html,
	css: ast.css,
	instance: ast.instance,
	module: ast.module
}));
Read more comments on GitHub >

github_iconTop Results From Across the Web

slotted() - CSS: Cascading Style Sheets - MDN Web Docs
The ::slotted() CSS pseudo-element represents any element that has been placed into a slot inside an HTML template (see Using templates and ...
Read more >
::slotted() - CSS: Cascading Style Sheets
The ::slotted() CSS pseudo-element represents any element that has been placed into a slot inside an HTML template (see Using templates and slots...
Read more >
litelement - styling nested elements within slotted elements
What am I missing so that I can apply the same style to the <a> element regardless of where it is within the...
Read more >
Working with Shadow DOM - Lit.dev
Lit components use shadow DOM to encapsulate their DOM. Shadow DOM provides a way to add a separate isolated and encapsulated DOM tree...
Read more >
Custom Element Best Practices - web.dev
Custom elements let you construct your own HTML tags. ... Use <slot> to project light DOM children into your shadow DOM.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found