diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index ce6c56fc7d..6d49faf906 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -875,7 +875,7 @@ export default class Generator { this.skip(); } - if (node.type === 'Component' && node.name === ':Component') { + if (node.type === 'Component' && (node.name === ':Component' || node.name === 'svelte:component')) { node.metadata = contextualise(node.expression, contextDependencies, indexes, false); } diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index 239dc4bed1..25d7508ac2 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -292,7 +292,7 @@ export default class Component extends Node { `; } - if (this.name === ':Component') { + if (this.name === ':Component' || this.name === 'svelte:component') { const switch_value = block.getUniqueName('switch_value'); const switch_props = block.getUniqueName('switch_props'); diff --git a/src/generators/server-side-rendering/visitors/Component.ts b/src/generators/server-side-rendering/visitors/Component.ts index d0df39c9be..9c7d7ce930 100644 --- a/src/generators/server-side-rendering/visitors/Component.ts +++ b/src/generators/server-side-rendering/visitors/Component.ts @@ -87,7 +87,7 @@ export default function visitComponent( .concat(bindingProps) .join(', ')} }`; - const isDynamicComponent = node.name === ':Component'; + const isDynamicComponent = node.name === ':Component' || node.name === 'svelte:component'; if (isDynamicComponent) block.contextualise(node.expression); const expression = ( diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index fbbb62bddb..dad44f81fe 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -169,7 +169,7 @@ export default function tag(parser: Parser) { } } - if (name === (parser.v2 ? 'svelte:component' : ':Component')) { + if (name === ':Component') { parser.eat('{', true); element.expression = readExpression(parser); parser.allowWhitespace(); @@ -189,6 +189,21 @@ export default function tag(parser: Parser) { parser.allowWhitespace(); } + if (parser.v2 && name === 'svelte:component') { + // TODO post v2, treat this just as any other attribute + const index = element.attributes.findIndex(attr => attr.name === 'this'); + if (!~index) { + parser.error(` must have a 'this' attribute`, start); + } + + const definition = element.attributes.splice(index, 1)[0]; + if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') { + parser.error(`invalid component definition`, definition.start); + } + + element.expression = definition.value[0].expression; + } + // special cases – top-level \ No newline at end of file diff --git a/test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html b/test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html new file mode 100644 index 0000000000..eb6e7d8e8e --- /dev/null +++ b/test/runtime/samples/dev-warning-dynamic-components-misplaced/main-v2.html @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html b/test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html new file mode 100644 index 0000000000..87b0403ee3 --- /dev/null +++ b/test/runtime/samples/dev-warning-readonly-window-binding/main-v2.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html b/test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html new file mode 100644 index 0000000000..b4faa1b662 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings-recreated/Green-v2.html @@ -0,0 +1 @@ +

green {foo}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html b/test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html new file mode 100644 index 0000000000..a3e3c792a0 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings-recreated/Red-v2.html @@ -0,0 +1 @@ +

red {foo}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html b/test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html new file mode 100644 index 0000000000..6d748ed217 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings-recreated/main-v2.html @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-bindings/main-v2.html b/test/runtime/samples/dynamic-component-bindings/main-v2.html new file mode 100644 index 0000000000..020855cb22 --- /dev/null +++ b/test/runtime/samples/dynamic-component-bindings/main-v2.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-events/main-v2.html b/test/runtime/samples/dynamic-component-events/main-v2.html new file mode 100644 index 0000000000..5fa66b2c61 --- /dev/null +++ b/test/runtime/samples/dynamic-component-events/main-v2.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/Bar-v2.html b/test/runtime/samples/dynamic-component-inside-element/Bar-v2.html new file mode 100644 index 0000000000..79e01b851c --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/Bar-v2.html @@ -0,0 +1 @@ +

{x}, therefore Bar

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/Foo-v2.html b/test/runtime/samples/dynamic-component-inside-element/Foo-v2.html new file mode 100644 index 0000000000..cb35cfc082 --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/Foo-v2.html @@ -0,0 +1 @@ +

{x}, therefore Foo

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/main-v2.html b/test/runtime/samples/dynamic-component-inside-element/main-v2.html new file mode 100644 index 0000000000..e889f2feb0 --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/main-v2.html @@ -0,0 +1,14 @@ +
+ +
+ + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-ref/main-v2.html b/test/runtime/samples/dynamic-component-ref/main-v2.html new file mode 100644 index 0000000000..1d54b17299 --- /dev/null +++ b/test/runtime/samples/dynamic-component-ref/main-v2.html @@ -0,0 +1,11 @@ + + + diff --git a/test/runtime/samples/dynamic-component-slot/main-v2.html b/test/runtime/samples/dynamic-component-slot/main-v2.html new file mode 100644 index 0000000000..e8b5c487ad --- /dev/null +++ b/test/runtime/samples/dynamic-component-slot/main-v2.html @@ -0,0 +1,45 @@ + +

element

+ + {tag} + + {#if foo} +

foo

+ {:elseif bar} +

bar

+ {:else} +

neither foo nor bar

+ {/if} + + text + + {#each things as thing} + {thing} + {/each} + + + +
what goes up must come down
+
+ + \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html b/test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html new file mode 100644 index 0000000000..36fa195dcd --- /dev/null +++ b/test/runtime/samples/dynamic-component-update-existing-instance/Bar-v2.html @@ -0,0 +1 @@ +

Bar {x}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html b/test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html new file mode 100644 index 0000000000..0a9cd0047a --- /dev/null +++ b/test/runtime/samples/dynamic-component-update-existing-instance/Foo-v2.html @@ -0,0 +1 @@ +

Foo {x}

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html b/test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html new file mode 100644 index 0000000000..4bdf36f529 --- /dev/null +++ b/test/runtime/samples/dynamic-component-update-existing-instance/main-v2.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/head-title-dynamic/main-v2.html b/test/runtime/samples/head-title-dynamic/main-v2.html new file mode 100644 index 0000000000..255f344c00 --- /dev/null +++ b/test/runtime/samples/head-title-dynamic/main-v2.html @@ -0,0 +1,4 @@ + + a {adjective} title + + \ No newline at end of file diff --git a/test/runtime/samples/head-title-static/main-v2.html b/test/runtime/samples/head-title-static/main-v2.html new file mode 100644 index 0000000000..7f9da20911 --- /dev/null +++ b/test/runtime/samples/head-title-static/main-v2.html @@ -0,0 +1,4 @@ + + changed + + \ No newline at end of file diff --git a/test/runtime/samples/self-reference-tree/main-v2.html b/test/runtime/samples/self-reference-tree/main-v2.html new file mode 100644 index 0000000000..6663cf9533 --- /dev/null +++ b/test/runtime/samples/self-reference-tree/main-v2.html @@ -0,0 +1,11 @@ +
+ {file.name} + + {#if file.type === 'folder'} +
    + {#each file.children as child} +
  • + {/each} +
+ {/if} +
\ No newline at end of file diff --git a/test/runtime/samples/self-reference/main-v2.html b/test/runtime/samples/self-reference/main-v2.html new file mode 100644 index 0000000000..e5581203c3 --- /dev/null +++ b/test/runtime/samples/self-reference/main-v2.html @@ -0,0 +1,4 @@ +{depth} +{#if depth > 0} + +{/if} \ No newline at end of file diff --git a/test/runtime/samples/window-bind-scroll-update/main-v2.html b/test/runtime/samples/window-bind-scroll-update/main-v2.html new file mode 100644 index 0000000000..107ebeef8f --- /dev/null +++ b/test/runtime/samples/window-bind-scroll-update/main-v2.html @@ -0,0 +1,3 @@ + + +
\ No newline at end of file diff --git a/test/runtime/samples/window-binding-resize/main-v2.html b/test/runtime/samples/window-binding-resize/main-v2.html new file mode 100644 index 0000000000..54a1762eb8 --- /dev/null +++ b/test/runtime/samples/window-binding-resize/main-v2.html @@ -0,0 +1,3 @@ + + +
{width}x{height}
\ No newline at end of file diff --git a/test/runtime/samples/window-event-context/main-v2.html b/test/runtime/samples/window-event-context/main-v2.html new file mode 100644 index 0000000000..af60672a2a --- /dev/null +++ b/test/runtime/samples/window-event-context/main-v2.html @@ -0,0 +1,3 @@ + + +{foo} \ No newline at end of file diff --git a/test/runtime/samples/window-event-custom/main-v2.html b/test/runtime/samples/window-event-custom/main-v2.html new file mode 100644 index 0000000000..515d5bc4ca --- /dev/null +++ b/test/runtime/samples/window-event-custom/main-v2.html @@ -0,0 +1,25 @@ + + +

escaped: {escaped}

+ + \ No newline at end of file