a render tag needs a call, a duplicate clause and an elseif keep their own errors

goodbye-acorn
Nic 2 weeks ago
parent b77026cf26
commit 35e1e0baed

@ -322,7 +322,9 @@ class Finish {
case 'HtmlTag': case 'HtmlTag':
this.expression(node, node.expression); this.expression(node, node.expression);
return; return;
case 'RenderTag': case 'RenderTag': {
const call = node.expression.type === 'ChainExpression' ? node.expression.expression : node.expression;
if (call.type !== 'CallExpression') e.render_tag_invalid_expression(node.expression);
this.expression(node, node.expression); this.expression(node, node.expression);
node.metadata = { node.metadata = {
...node.metadata, ...node.metadata,
@ -332,6 +334,7 @@ class Finish {
snippets: new Set() snippets: new Set()
}; };
return; return;
}
case 'ConstTag': case 'ConstTag':
case 'DeclarationTag': case 'DeclarationTag':
this.expression(node, node.declaration); this.expression(node, node.declaration);
@ -591,7 +594,10 @@ function throw_error(error, template) {
} }
// a branch that fits no open block, reported at its sigil // a branch that fits no open block, reported at its sigil
if (what === 'else') e.expected_token(pos + 1, '{:else}'); if (what === 'else') e.expected_token(pos + 1, '{:else}');
if (what === 'else if or else') e.expected_token(pos + 1, '{:else} or {:else if}'); if (what === 'else if or else') {
if (template.startsWith('{:elseif', pos)) e.block_invalid_elseif(pos + 1);
e.expected_token(pos + 1, '{:else} or {:else if}');
}
if (what === 'then or catch') e.expected_token(pos + 1, '{:then ...} or {:catch ...}'); if (what === 'then or catch') e.expected_token(pos + 1, '{:then ...} or {:catch ...}');
if (what === 'a block name') e.expected_block_type(pos); if (what === 'a block name') e.expected_block_type(pos);
if (what === 'an attribute value') e.expected_attribute_value(pos); if (what === 'an attribute value') e.expected_attribute_value(pos);
@ -638,6 +644,7 @@ function throw_error(error, template) {
if (name === 'script') e.script_duplicate(pos); if (name === 'script') e.script_duplicate(pos);
if (name === 'style') e.style_duplicate(pos); if (name === 'style') e.style_duplicate(pos);
if (name.startsWith('svelte:')) e.svelte_meta_duplicate(pos, name); if (name.startsWith('svelte:')) e.svelte_meta_duplicate(pos, name);
if (name.startsWith('{:')) e.block_duplicate_clause(pos + 1, name);
e.attribute_duplicate(range); e.attribute_duplicate(range);
} }
// eslint-disable-next-line no-fallthrough // eslint-disable-next-line no-fallthrough

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
error: {
code: 'block_duplicate_clause',
message: '{:then} cannot appear more than once within a block',
position: [43, 43]
}
});

@ -0,0 +1 @@
<script>let p;</script>{#await p}{:then x}{:then y}{/await}

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
error: {
code: 'block_invalid_elseif',
message: "'elseif' should be 'else if'",
position: [34, 34]
}
});

@ -0,0 +1 @@
<script>let x, y;</script>{#if x}{:elseif y}{/if}

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
error: {
code: 'render_tag_invalid_expression',
message: '`{@render ...}` tags can only contain call expressions',
position: [34, 37]
}
});
Loading…
Cancel
Save