Skip to content

Add error when a {#snippet} hide a props #11603

Closed
@adiguba

Description

@adiguba

Describe the problem

Snippet are passed as props, and they can therefore hide props of the same name.

Ex:

<Comp title="Title using props">
	{#snippet title()}
		Title using <b>snippet</b>
	{/snippet}
</Comp>

will be compiled to something like this :

		var title = ($$anchor) => {
			var fragment_4 = root_2();
			var b_1 = $.sibling($.first_child(fragment_4, true));

			$.append($$anchor, fragment_4);
		};

		Comp(node_2, { title: "Title using props", title });

Note that there are two attributes "title", and the snippet is hiding the props.

Exemple : REPL

Describe the proposed solution

Currently, Svelte generates an error when using the same attribute twice :

<Comp title="a" title="b"></Comp><!-- ERROR : Attributes need to be unique -->

I think it should be the same when a snippet collides with a prop :

<Comp title="prop">
	{#snippet title()} <!-- ERROR : Attribute and snippet need to be unique -->
		<b>snippet</b>
	{/snippet}
</Comp>

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions