-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validation and test replace svelte:slot -> svelte:fragment slot as a sugar syntax fix eslint
- Loading branch information
Showing
109 changed files
with
1,193 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Component from '../Component'; | ||
import TemplateScope from './shared/TemplateScope'; | ||
import Node from './shared/Node'; | ||
import Let from './Let'; | ||
import { INode } from './interfaces'; | ||
|
||
export default class DefaultSlotTemplate extends Node { | ||
type: 'SlotTemplate'; | ||
scope: TemplateScope; | ||
children: INode[]; | ||
lets: Let[] = []; | ||
slot_template_name = 'default'; | ||
|
||
constructor( | ||
component: Component, | ||
parent: INode, | ||
scope: TemplateScope, | ||
info: any, | ||
lets: Let[], | ||
children: INode[] | ||
) { | ||
super(component, parent, scope, info); | ||
this.type = 'SlotTemplate'; | ||
this.children = children; | ||
this.scope = scope; | ||
this.lets = lets; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import map_children from './shared/map_children'; | ||
import Component from '../Component'; | ||
import TemplateScope from './shared/TemplateScope'; | ||
import Node from './shared/Node'; | ||
import Let from './Let'; | ||
import Attribute from './Attribute'; | ||
import { INode } from './interfaces'; | ||
|
||
export default class SlotTemplate extends Node { | ||
type: 'SlotTemplate'; | ||
scope: TemplateScope; | ||
children: INode[]; | ||
lets: Let[] = []; | ||
slot_attribute: Attribute; | ||
slot_template_name: string = 'default'; | ||
|
||
constructor( | ||
component: Component, | ||
parent: INode, | ||
scope: TemplateScope, | ||
info: any | ||
) { | ||
super(component, parent, scope, info); | ||
|
||
this.validate_slot_template_placement(); | ||
|
||
const has_let = info.attributes.some((node) => node.type === 'Let'); | ||
if (has_let) { | ||
scope = scope.child(); | ||
} | ||
|
||
info.attributes.forEach((node) => { | ||
switch (node.type) { | ||
case 'Let': { | ||
const l = new Let(component, this, scope, node); | ||
this.lets.push(l); | ||
const dependencies = new Set([l.name.name]); | ||
|
||
l.names.forEach((name) => { | ||
scope.add(name, dependencies, this); | ||
}); | ||
break; | ||
} | ||
case 'Attribute': { | ||
if (node.name === 'slot') { | ||
this.slot_attribute = new Attribute(component, this, scope, node); | ||
if (!this.slot_attribute.is_static) { | ||
component.error(node, { | ||
code: 'invalid-slot-attribute', | ||
message: 'slot attribute cannot have a dynamic value' | ||
}); | ||
} | ||
const value = this.slot_attribute.get_static_value(); | ||
if (typeof value === 'boolean') { | ||
component.error(node, { | ||
code: 'invalid-slot-attribute', | ||
message: 'slot attribute value is missing' | ||
}); | ||
} | ||
this.slot_template_name = value as string; | ||
break; | ||
} | ||
throw new Error(`Invalid attribute '${node.name}' in <svelte:fragment>`); | ||
} | ||
default: | ||
throw new Error(`Not implemented: ${node.type}`); | ||
} | ||
}); | ||
|
||
this.scope = scope; | ||
this.children = map_children(component, this, this.scope, info.children); | ||
} | ||
|
||
validate_slot_template_placement() { | ||
if (this.parent.type !== 'InlineComponent') { | ||
this.component.error(this, { | ||
code: 'invalid-slotted-content', | ||
message: '<svelte:fragment> must be a child of a component' | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
src/compiler/compile/render_dom/wrappers/Element/create_slot_block.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.