Skip to content

Commit 345973e

Browse files
committed
Check for duplicate slot attributes on components
1 parent f178788 commit 345973e

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function validate_component(node, context) {
3737
) {
3838
error(attribute, 'invalid-event-modifier');
3939
}
40+
41+
if (attribute.type === 'Attribute' && attribute.name === 'slot') {
42+
validate_slot_attribute(context, attribute);
43+
}
4044
}
4145

4246
context.next({
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: {
5+
code: 'duplicate-slot-name',
6+
message: "Duplicate slot name 'foo' in <Nested>"
7+
}
8+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import Nested from './irrelevant';
3+
import Inner from './irrelevant';
4+
</script>
5+
6+
<Nested>
7+
<Inner slot="foo">{value}</Inner>
8+
<Inner slot="foo">{value}</Inner>
9+
</Nested>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: {
5+
code: 'duplicate-slot-name',
6+
message: "Duplicate slot name 'foo' in <Nested>"
7+
}
8+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import Nested from './irrelevant';
3+
import Inner from './irrelevant';
4+
</script>
5+
6+
<Nested>
7+
<p slot="foo">{value}</p>
8+
<Inner slot="foo">{value}</Inner>
9+
</Nested>

0 commit comments

Comments
 (0)