a this given as text warns again, at the attribute as before

goodbye-acorn
Nic 2 weeks ago
parent 9fb5350b2b
commit b2d7d57b00

@ -299,8 +299,15 @@ class Finish {
: /** @type {any} */ ({}); : /** @type {any} */ ({});
if (node.type === 'SvelteElement') { if (node.type === 'SvelteElement') {
// a tag named in text is the literal Svelte writes by hand, quoted its way // a tag named in text is the literal Svelte writes by hand, quoted its way
if (node.tag.type === 'Literal' && node.tag.raw === node.tag.value) if (node.tag.type === 'Literal' && node.tag.raw === node.tag.value) {
const { start, end } = /** @type {{ start: number; end: number }} */ (node.tag);
const quoted = this.template[start - 1] === '"' || this.template[start - 1] === "'";
w.svelte_element_invalid_this({
start: this.template.lastIndexOf('this', start),
end: quoted ? end + 1 : end
});
node.tag.raw = `'${node.tag.value}'`; node.tag.raw = `'${node.tag.value}'`;
}
node.metadata.expression = new ExpressionMetadata(); node.metadata.expression = new ExpressionMetadata();
} }
if (node.type === 'SvelteComponent' || node.type === 'Component') { if (node.type === 'SvelteComponent' || node.type === 'Component') {

@ -0,0 +1,2 @@
<svelte:element this="div" />
<svelte:element this=span>text</svelte:element>

@ -0,0 +1,26 @@
[
{
"code": "svelte_element_invalid_this",
"message": "`this` should be an `{expression}`. Using a string attribute value will cause an error in future versions of Svelte",
"start": {
"column": 16,
"line": 1
},
"end": {
"column": 26,
"line": 1
}
},
{
"code": "svelte_element_invalid_this",
"message": "`this` should be an `{expression}`. Using a string attribute value will cause an error in future versions of Svelte",
"start": {
"column": 16,
"line": 2
},
"end": {
"column": 25,
"line": 2
}
}
]
Loading…
Cancel
Save