Skip to content

Commit bec7ca7

Browse files
authored
fix: throw on invalid {@tag}s (#17256)
* fix: throw on invalid `{@tag}`s * fix
1 parent ae60046 commit bec7ca7

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

.changeset/six-lemons-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: throw on invalid `{@tag}`s

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ Expected an identifier
525525
Expected identifier or destructure pattern
526526
```
527527

528+
### expected_tag
529+
530+
```
531+
Expected 'html', 'render', 'attach', 'const', or 'debug'
532+
```
533+
528534
### expected_token
529535

530536
```

packages/svelte/messages/compile-errors/template.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ The same applies to components:
223223

224224
> Expected identifier or destructure pattern
225225
226+
## expected_tag
227+
228+
> Expected 'html', 'render', 'attach', 'const', or 'debug'
229+
226230
## expected_token
227231

228232
> Expected token %token%

packages/svelte/src/compiler/errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,15 @@ export function expected_pattern(node) {
11291129
e(node, 'expected_pattern', `Expected identifier or destructure pattern\nhttps://svelte.dev/e/expected_pattern`);
11301130
}
11311131

1132+
/**
1133+
* Expected 'html', 'render', 'attach', 'const', or 'debug'
1134+
* @param {null | number | NodeLike} node
1135+
* @returns {never}
1136+
*/
1137+
export function expected_tag(node) {
1138+
e(node, 'expected_tag', `Expected 'html', 'render', 'attach', 'const', or 'debug'\nhttps://svelte.dev/e/expected_tag`);
1139+
}
1140+
11321141
/**
11331142
* Expected token %token%
11341143
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ function special(parser) {
724724
expression: new ExpressionMetadata()
725725
}
726726
});
727+
return;
727728
}
728729

729730
if (parser.eat('render')) {
@@ -755,5 +756,7 @@ function special(parser) {
755756
snippets: new Set()
756757
}
757758
});
759+
return;
758760
}
761+
e.expected_tag(parser.index);
759762
}

0 commit comments

Comments
 (0)