From 07bad96719c0154ba32c8dbcfed26fa7f8ffb20e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 16 Apr 2018 20:53:23 -0400 Subject: [PATCH] tidy up --- src/generators/Generator.ts | 4 ++-- src/generators/nodes/Component.ts | 8 ++++---- .../server-side-rendering/visitors/Component.ts | 4 ++-- src/parse/state/tag.ts | 10 +--------- src/validate/html/index.ts | 2 -- src/validate/html/validateElement.ts | 2 +- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 68c721fb2a..714945fba2 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -777,7 +777,7 @@ export default class Generator { node.generator = generator; - if (node.type === 'Element' && (node.name === ':Component' || node.name === ':Self' || node.name === 'svelte:component' || node.name === 'svelte:self' || generator.components.has(node.name))) { + if (node.type === 'Element' && (node.name === 'svelte:component' || node.name === 'svelte:self' || generator.components.has(node.name))) { node.type = 'Component'; Object.setPrototypeOf(node, nodes.Component.prototype); } else if (node.type === 'Element' && node.name === 'title' && parentIsHead(parent)) { // TODO do this in parse? @@ -861,7 +861,7 @@ export default class Generator { this.skip(); } - if (node.type === 'Component' && (node.name === ':Component' || node.name === 'svelte:component')) { + if (node.type === '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 fb881ef40e..7adacc9d0e 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -45,8 +45,8 @@ export default class Component extends Node { this.var = block.getUniqueName( ( - (this.name === ':Self' || this.name === 'svelte:self') ? this.generator.name : - (this.name === ':Component' || this.name === 'svelte:component') ? 'switch_instance' : + this.name === 'svelte:self' ? this.generator.name : + this.name === 'svelte:component' ? 'switch_instance' : this.name ).toLowerCase() ); @@ -293,7 +293,7 @@ export default class Component extends Node { `; } - if (this.name === ':Component' || this.name === 'svelte:component') { + if (this.name === 'svelte:component') { const switch_value = block.getUniqueName('switch_value'); const switch_props = block.getUniqueName('switch_props'); @@ -387,7 +387,7 @@ export default class Component extends Node { block.builders.destroy.addLine(`if (${name}) ${name}.destroy(false);`); } else { - const expression = (this.name === ':Self' || this.name === 'svelte:self') + const expression = this.name === 'svelte:self' ? generator.name : `%components-${this.name}`; diff --git a/src/generators/server-side-rendering/visitors/Component.ts b/src/generators/server-side-rendering/visitors/Component.ts index c31ddd917f..7ff6969983 100644 --- a/src/generators/server-side-rendering/visitors/Component.ts +++ b/src/generators/server-side-rendering/visitors/Component.ts @@ -87,11 +87,11 @@ export default function visitComponent( .concat(bindingProps) .join(', ')} }`; - const isDynamicComponent = node.name === ':Component' || node.name === 'svelte:component'; + const isDynamicComponent = node.name === 'svelte:component'; if (isDynamicComponent) block.contextualise(node.expression); const expression = ( - (node.name === ':Self' || node.name === 'svelte:self') ? generator.name : + node.name === 'svelte:self' ? generator.name : isDynamicComponent ? `((${node.metadata.snippet}) || __missingComponent)` : `%components-${node.name}` ); diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index e1f6af0ad4..cf0267c240 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -86,7 +86,7 @@ export default function tag(parser: Parser) { if (metaTags.has(name)) { const slug = metaTags.get(name).toLowerCase(); if (isClosingTag) { - if ((name === ':Window' || name === 'svelte:window') && parser.current().children.length) { + if (name === 'svelte:window' && parser.current().children.length) { parser.error({ code: `invalid-window-content`, message: `<${name}> cannot have children` @@ -176,14 +176,6 @@ export default function tag(parser: Parser) { } } - if (name === ':Component') { - parser.eat('{', true); - element.expression = readExpression(parser); - parser.allowWhitespace(); - parser.eat('}', true); - parser.allowWhitespace(); - } - const uniqueNames = new Set(); let attribute; diff --git a/src/validate/html/index.ts b/src/validate/html/index.ts index f543ebd27e..e471ff6b41 100644 --- a/src/validate/html/index.ts +++ b/src/validate/html/index.ts @@ -31,8 +31,6 @@ export default function validateHtml(validator: Validator, html: Node) { else if (node.type === 'Element') { const isComponent = - node.name === ':Self' || - node.name === ':Component' || node.name === 'svelte:self' || node.name === 'svelte:component' || validator.components.has(node.name); diff --git a/src/validate/html/validateElement.ts b/src/validate/html/validateElement.ts index 078f3f6458..2a32769797 100644 --- a/src/validate/html/validateElement.ts +++ b/src/validate/html/validateElement.ts @@ -297,7 +297,7 @@ function checkSlotAttribute(validator: Validator, node: Node, attribute: Node, s const parent = stack[i]; if (parent.type === 'Element') { // if we're inside a component or a custom element, gravy - if (parent.name === ':Self' || parent.name === ':Component' || parent.name === 'svelte:self' || parent.name === 'svelte:component' || validator.components.has(parent.name)) return; + if (parent.name === 'svelte:self' || parent.name === 'svelte:component' || validator.components.has(parent.name)) return; if (/-/.test(parent.name)) return; }