Skip to content

Some remarks about set_attributes() #15399

@adiguba

Description

@adiguba

Describe the bug

Not really a bug, but some stuff I noticed while reading the code and testing with REPL with set_attributes().

This function accept 3 optionnals booleans :

/**
 * ...
 * @param {boolean} [preserve_attribute_case]
 * @param {boolean} [is_custom_element]
 * @param {boolean} [skip_warning]
 */

But I think that the generated code is inconsistent between nodes and <svelte:element> :

tagpreserve_attribute_caseis_custom_elementskip_warning
<div>
<custom-elem>truetrue
<svg>true
<math>true
<svelte:element>$$element.namespaceURI === $.NAMESPACE_SVG$$element.nodeName.includes('-')

So :

  • preserve_attribute_case is inconsistent between regular and <svelte:element> nodes.
    On regular node it's true for custom-elements, SVG and MathML nodes.
    On <svelte:element> it's only true for SVG nodes.
  • skip_warning is never passed, and it's even never used inside the function.
    I was also unable to generate any code that used it on set_attribute() (without 's'), even in DEV mode.
    Either it is useless and can be deleted, or this needs to be corrected.
  • Also I think that preserve_attribute_case/is_custom_element (and perhaps skip_warning if it's needed) can be replaced by a single flag inside set_attributes().
    Something like that :
	// flag is a number :
	//      * 0 : svelte-element
	//      * 1 : HTML nodes
	//      * 2 : Custom Element
	//      * 3 : SVG
	//      * 4 : MathML
	//
	let is_custom_element = flag === 2 || (flag === 0 && element.nodeName.includes('-'));
	let preserve_attribute_case = flag > 1 || is_custom_element  || (flag === 0 && element.namespaceURI !== NAMESPACE_HTML)

Reproduction

Exemple in REPL (see generated code)

Logs

-

System Info

REPL

Severity

annoyance

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