Skip to content

Commit b8bc122

Browse files
committed
simplify some slot_name stuff
1 parent af6f73c commit b8bc122

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/compile/nodes/Slot.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Attribute from './Attribute';
55
export default class Slot extends Element {
66
type: 'Element';
77
name: string;
8+
slot_name: string;
89
attributes: Attribute[];
910
children: Node[];
1011

@@ -27,8 +28,8 @@ export default class Slot extends Element {
2728
});
2829
}
2930

30-
const slot_name = attr.value[0].data;
31-
if (slot_name === 'default') {
31+
this.slot_name = attr.value[0].data;
32+
if (this.slot_name === 'default') {
3233
component.error(attr, {
3334
code: `invalid-slot-name`,
3435
message: `default is a reserved word — it cannot be used as a slot name`
@@ -46,6 +47,8 @@ export default class Slot extends Element {
4647
// validator.slots.add(slot_name);
4748
});
4849

50+
if (!this.slot_name) this.slot_name = 'default';
51+
4952
// if (node.attributes.length === 0) && validator.slots.has('default')) {
5053
// validator.error(node, {
5154
// code: `duplicate-slot`,

src/compile/render-dom/wrappers/Element/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import add_event_handlers from '../shared/add_event_handlers';
2020
import add_actions from '../shared/add_actions';
2121
import create_debugging_comment from '../shared/create_debugging_comment';
2222
import { get_context_merger } from '../shared/get_context_merger';
23+
import Slot from '../../../nodes/Slot';
2324

2425
const events = [
2526
{
@@ -213,8 +214,7 @@ export default class ElementWrapper extends Wrapper {
213214
const { renderer } = this;
214215

215216
if (this.node.name === 'slot') {
216-
const slot_name = this.node.get_static_attribute_value('name') || 'default';
217-
renderer.slots.add(slot_name);
217+
renderer.slots.add((this.node as Slot).slot_name);
218218
}
219219

220220
if (this.node.name === 'noscript') return;

src/compile/render-dom/wrappers/Slot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class SlotWrapper extends Wrapper {
5555
) {
5656
const { renderer } = this;
5757

58-
const slot_name = this.node.get_static_attribute_value('name') || 'default';
58+
const { slot_name } = this.node;
5959
renderer.slots.add(slot_name);
6060

6161
let get_slot_changes;

src/compile/render-ssr/handlers/Slot.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { quote_prop_if_necessary } from '../../../utils/names';
22
import get_slot_data from '../../utils/get_slot_data';
33

44
export default function(node, renderer, options) {
5-
const name = node.attributes.find(attribute => attribute.name === 'name');
6-
7-
const slot_name = name && name.chunks[0].data || 'default';
8-
const prop = quote_prop_if_necessary(slot_name);
5+
const prop = quote_prop_if_necessary(node.slot_name);
96

107
const slot_data = get_slot_data(node.attributes, true);
118

0 commit comments

Comments
 (0)