From df4a9421058def482ba6ea6b296cdd8afc0bd23b Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 28 Jun 2020 23:03:33 +0800 Subject: [PATCH] replace svelte:slot -> svelte:fragment --- src/compiler/compile/nodes/SlotTemplate.ts | 51 ++++++++++--------- src/compiler/parse/state/tag.ts | 8 +-- .../error-svelte-selfdestructive/error.json | 2 +- .../main.svelte | 4 +- .../main.svelte | 2 +- .../main.svelte | 2 +- .../component-svelte-slot-2/main.svelte | 8 +-- .../main.svelte | 4 +- .../component-svelte-slot-let-b/main.svelte | 4 +- .../component-svelte-slot-let-c/main.svelte | 4 +- .../component-svelte-slot-let-d/main.svelte | 4 +- .../main.svelte | 12 ++--- .../main.svelte | 4 +- .../component-svelte-slot-let-e/A.svelte | 4 +- .../component-svelte-slot-let-e/main.svelte | 8 +-- .../component-svelte-slot-let-f/main.svelte | 4 +- .../main.svelte | 4 +- .../main.svelte | 8 +-- .../samples/component-svelte-slot/main.svelte | 8 +-- .../svelte-slot-placement-2/errors.json | 2 +- .../svelte-slot-placement-2/input.svelte | 4 +- .../samples/svelte-slot-placement/errors.json | 2 +- .../svelte-slot-placement/input.svelte | 4 +- 23 files changed, 81 insertions(+), 76 deletions(-) diff --git a/src/compiler/compile/nodes/SlotTemplate.ts b/src/compiler/compile/nodes/SlotTemplate.ts index 3f44aeaae497..b41746eac878 100644 --- a/src/compiler/compile/nodes/SlotTemplate.ts +++ b/src/compiler/compile/nodes/SlotTemplate.ts @@ -1,61 +1,66 @@ -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'; +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'; + type: "SlotTemplate"; scope: TemplateScope; children: INode[]; lets: Let[] = []; slot_attribute: Attribute; - slot_template_name: string = 'default'; + slot_template_name: string = "default"; - constructor(component: Component, parent: INode, scope: TemplateScope, info: any) { + 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'); + const has_let = info.attributes.some((node) => node.type === "Let"); if (has_let) { scope = scope.child(); } - info.attributes.forEach(node => { + info.attributes.forEach((node) => { switch (node.type) { - case 'Let': { + 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 => { + l.names.forEach((name) => { scope.add(name, dependencies, this); }); break; } - case 'Attribute': { - if (node.name === 'slot') { + 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` + message: `slot attribute cannot have a dynamic value`, }); } const value = this.slot_attribute.get_static_value(); - if (typeof value === 'boolean') { + if (typeof value === "boolean") { component.error(node, { code: `invalid-slot-attribute`, - message: `slot attribute value is missing` + message: `slot attribute value is missing`, }); } - this.slot_template_name = this.slot_attribute.get_static_value() as string; + this.slot_template_name = value as string; break; } - throw new Error(`Invalid attribute "${node.name}" in `); + throw new Error(`Invalid attribute "${node.name}" in `); } default: throw new Error(`Not implemented: ${node.type}`); @@ -67,10 +72,10 @@ export default class SlotTemplate extends Node { } validate_slot_template_placement() { - if (this.parent.type !== 'InlineComponent') { + if (this.parent.type !== "InlineComponent") { this.component.error(this, { code: `invalid-slotted-content`, - message: ` must be a child of a component` + message: ` must be a child of a component`, }); } } diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 2ad96a983514..f89954aa0610 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -18,7 +18,7 @@ const meta_tags = new Map([ ['svelte:body', 'Body'], ]); -const valid_meta_tags = Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component', 'svelte:slot'); +const valid_meta_tags = Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component', 'svelte:fragment'); const specials = new Map([ [ @@ -39,7 +39,7 @@ const specials = new Map([ const SELF = /^svelte:self(?=[\s/>])/; const COMPONENT = /^svelte:component(?=[\s/>])/; -const SLOT = /^svelte:slot(?=[\s/>])/; +const SLOT = /^svelte:fragment(?=[\s/>])/; function parent_is_head(stack) { let i = stack.length; @@ -108,7 +108,7 @@ export default function tag(parser: Parser) { const type = meta_tags.has(name) ? meta_tags.get(name) : (/[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component') ? 'InlineComponent' - : name === 'svelte:slot' ? 'SlotTemplate' + : name === 'svelte:fragment' ? 'SlotTemplate' : name === 'title' && parent_is_head(parser.stack) ? 'Title' : name === 'slot' && !parser.customElement ? 'Slot' : 'Element'; @@ -274,7 +274,7 @@ function read_tag_name(parser: Parser) { if (parser.read(COMPONENT)) return 'svelte:component'; - if (parser.read(SLOT)) return 'svelte:slot'; + if (parser.read(SLOT)) return 'svelte:fragment'; const name = parser.read_until(/(\s|\/|>)/); diff --git a/test/parser/samples/error-svelte-selfdestructive/error.json b/test/parser/samples/error-svelte-selfdestructive/error.json index dcec676d78ae..52172c9b332c 100644 --- a/test/parser/samples/error-svelte-selfdestructive/error.json +++ b/test/parser/samples/error-svelte-selfdestructive/error.json @@ -1,6 +1,6 @@ { "code": "invalid-tag-name", - "message": "Valid tag names are svelte:head, svelte:options, svelte:window, svelte:body, svelte:self, svelte:component or svelte:slot", + "message": "Valid tag names are svelte:head, svelte:options, svelte:window, svelte:body, svelte:self, svelte:component or svelte:fragment", "pos": 10, "start": { "character": 10, diff --git a/test/runtime/samples/component-slot-duplicate-error-2/main.svelte b/test/runtime/samples/component-slot-duplicate-error-2/main.svelte index 6e423953badc..fefa1dc861cf 100644 --- a/test/runtime/samples/component-slot-duplicate-error-2/main.svelte +++ b/test/runtime/samples/component-slot-duplicate-error-2/main.svelte @@ -3,6 +3,6 @@ - {value} - {value} + {value} + {value} \ No newline at end of file diff --git a/test/runtime/samples/component-slot-duplicate-error-3/main.svelte b/test/runtime/samples/component-slot-duplicate-error-3/main.svelte index 22c10d7d4331..596c1313d600 100644 --- a/test/runtime/samples/component-slot-duplicate-error-3/main.svelte +++ b/test/runtime/samples/component-slot-duplicate-error-3/main.svelte @@ -3,6 +3,6 @@ - {value} + {value}

{value}

\ No newline at end of file diff --git a/test/runtime/samples/component-slot-duplicate-error-4/main.svelte b/test/runtime/samples/component-slot-duplicate-error-4/main.svelte index 559e17b86e0e..ee1dcfad7bfb 100644 --- a/test/runtime/samples/component-slot-duplicate-error-4/main.svelte +++ b/test/runtime/samples/component-slot-duplicate-error-4/main.svelte @@ -3,6 +3,6 @@ - value + value

value

\ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-2/main.svelte b/test/runtime/samples/component-svelte-slot-2/main.svelte index 9686ab39f125..8212f54cf849 100644 --- a/test/runtime/samples/component-svelte-slot-2/main.svelte +++ b/test/runtime/samples/component-svelte-slot-2/main.svelte @@ -3,13 +3,13 @@ - + Hello - +
- + world - +
\ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-aliased/main.svelte b/test/runtime/samples/component-svelte-slot-let-aliased/main.svelte index 9362795d57cf..dabf1d65ef0c 100644 --- a/test/runtime/samples/component-svelte-slot-let-aliased/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-aliased/main.svelte @@ -5,7 +5,7 @@ - + {x} - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-b/main.svelte b/test/runtime/samples/component-svelte-slot-let-b/main.svelte index c0107a1493f3..584240d14d27 100644 --- a/test/runtime/samples/component-svelte-slot-let-b/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-b/main.svelte @@ -3,7 +3,7 @@ - + {count} - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-c/main.svelte b/test/runtime/samples/component-svelte-slot-let-c/main.svelte index 54ae1bbf295f..9753c45075d5 100644 --- a/test/runtime/samples/component-svelte-slot-let-c/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-c/main.svelte @@ -3,7 +3,7 @@ - + {c} ({count}) - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-d/main.svelte b/test/runtime/samples/component-svelte-slot-let-d/main.svelte index b7003724b036..7ba94c7b8ad7 100644 --- a/test/runtime/samples/component-svelte-slot-let-d/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-d/main.svelte @@ -3,7 +3,7 @@ - +

{bar}

-
+
\ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-destructured-2/main.svelte b/test/runtime/samples/component-svelte-slot-let-destructured-2/main.svelte index 734e6b139059..d4d399188169 100644 --- a/test/runtime/samples/component-svelte-slot-let-destructured-2/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-destructured-2/main.svelte @@ -5,9 +5,9 @@
- + {pair[0]} {pair[1]} {c} {foo} - + @@ -15,9 +15,9 @@
- + {a} {b} {d} {foo} - + @@ -25,9 +25,9 @@
- + {a} {b} {e} {foo} - + diff --git a/test/runtime/samples/component-svelte-slot-let-destructured/main.svelte b/test/runtime/samples/component-svelte-slot-let-destructured/main.svelte index 1cf53a325546..923e96311c0e 100644 --- a/test/runtime/samples/component-svelte-slot-let-destructured/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-destructured/main.svelte @@ -5,7 +5,7 @@ - + {num} - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-e/A.svelte b/test/runtime/samples/component-svelte-slot-let-e/A.svelte index 5064635f28fe..3ba0e62cd961 100644 --- a/test/runtime/samples/component-svelte-slot-let-e/A.svelte +++ b/test/runtime/samples/component-svelte-slot-let-e/A.svelte @@ -4,8 +4,8 @@ - + {reflected} - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-e/main.svelte b/test/runtime/samples/component-svelte-slot-let-e/main.svelte index 2856d393ea62..80c9a868cd44 100644 --- a/test/runtime/samples/component-svelte-slot-let-e/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-e/main.svelte @@ -4,13 +4,13 @@ - + {reflected} - + - + {reflected} - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-f/main.svelte b/test/runtime/samples/component-svelte-slot-let-f/main.svelte index 721ca162aa27..a47f1ba6de3b 100644 --- a/test/runtime/samples/component-svelte-slot-let-f/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-f/main.svelte @@ -5,13 +5,13 @@ - + y = reflected} class={reflected} > {reflected} - + { y } \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-in-binding/main.svelte b/test/runtime/samples/component-svelte-slot-let-in-binding/main.svelte index 54b4f2974896..c6edd8200359 100644 --- a/test/runtime/samples/component-svelte-slot-let-in-binding/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-in-binding/main.svelte @@ -5,9 +5,9 @@ - + - + \ No newline at end of file diff --git a/test/runtime/samples/component-svelte-slot-let-in-slot/main.svelte b/test/runtime/samples/component-svelte-slot-let-in-slot/main.svelte index 11b9a4e91d96..2de0cb11ef44 100644 --- a/test/runtime/samples/component-svelte-slot-let-in-slot/main.svelte +++ b/test/runtime/samples/component-svelte-slot-let-in-slot/main.svelte @@ -6,11 +6,11 @@ - + - + {value} - + - + diff --git a/test/runtime/samples/component-svelte-slot/main.svelte b/test/runtime/samples/component-svelte-slot/main.svelte index c5c784c1577a..b27c3795ed73 100644 --- a/test/runtime/samples/component-svelte-slot/main.svelte +++ b/test/runtime/samples/component-svelte-slot/main.svelte @@ -4,10 +4,10 @@ const a = 'a'; - + content { a } - - + + - + diff --git a/test/validator/samples/svelte-slot-placement-2/errors.json b/test/validator/samples/svelte-slot-placement-2/errors.json index e3ee8b744594..6a35d97f66ec 100644 --- a/test/validator/samples/svelte-slot-placement-2/errors.json +++ b/test/validator/samples/svelte-slot-placement-2/errors.json @@ -1,7 +1,7 @@ [ { "code": "invalid-slotted-content", - "message": " must be a child of a component", + "message": " must be a child of a component", "start": { "line": 5, "column": 0, "character": 59 }, "end": { "line": 7, "column": 14, "character": 104 }, "pos": 59 diff --git a/test/validator/samples/svelte-slot-placement-2/input.svelte b/test/validator/samples/svelte-slot-placement-2/input.svelte index d5a83bf66446..4fad457bd8da 100644 --- a/test/validator/samples/svelte-slot-placement-2/input.svelte +++ b/test/validator/samples/svelte-slot-placement-2/input.svelte @@ -2,6 +2,6 @@ import Nested from './Nested.svelte'; - +
test
-
\ No newline at end of file +
\ No newline at end of file diff --git a/test/validator/samples/svelte-slot-placement/errors.json b/test/validator/samples/svelte-slot-placement/errors.json index 5843663f8ddb..9e960a263c69 100644 --- a/test/validator/samples/svelte-slot-placement/errors.json +++ b/test/validator/samples/svelte-slot-placement/errors.json @@ -1,7 +1,7 @@ [ { "code": "invalid-slotted-content", - "message": " must be a child of a component", + "message": " must be a child of a component", "start": { "line": 7, "column": 2, "character": 77 }, "end": { "line": 9, "column": 16, "character": 126 }, "pos": 77 diff --git a/test/validator/samples/svelte-slot-placement/input.svelte b/test/validator/samples/svelte-slot-placement/input.svelte index 4803e75da932..a09639dd7175 100644 --- a/test/validator/samples/svelte-slot-placement/input.svelte +++ b/test/validator/samples/svelte-slot-placement/input.svelte @@ -4,8 +4,8 @@
- +
test
-
+
\ No newline at end of file