pull/1348/head
Rich Harris 7 years ago
parent b9fcc16d68
commit 07bad96719

@ -777,7 +777,7 @@ export default class Generator {
node.generator = 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'; node.type = 'Component';
Object.setPrototypeOf(node, nodes.Component.prototype); Object.setPrototypeOf(node, nodes.Component.prototype);
} else if (node.type === 'Element' && node.name === 'title' && parentIsHead(parent)) { // TODO do this in parse? } 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(); 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); node.metadata = contextualise(node.expression, contextDependencies, indexes, false);
} }

@ -45,8 +45,8 @@ export default class Component extends Node {
this.var = block.getUniqueName( this.var = block.getUniqueName(
( (
(this.name === ':Self' || this.name === 'svelte:self') ? this.generator.name : this.name === 'svelte:self' ? this.generator.name :
(this.name === ':Component' || this.name === 'svelte:component') ? 'switch_instance' : this.name === 'svelte:component' ? 'switch_instance' :
this.name this.name
).toLowerCase() ).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_value = block.getUniqueName('switch_value');
const switch_props = block.getUniqueName('switch_props'); 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);`); block.builders.destroy.addLine(`if (${name}) ${name}.destroy(false);`);
} else { } else {
const expression = (this.name === ':Self' || this.name === 'svelte:self') const expression = this.name === 'svelte:self'
? generator.name ? generator.name
: `%components-${this.name}`; : `%components-${this.name}`;

@ -87,11 +87,11 @@ export default function visitComponent(
.concat(bindingProps) .concat(bindingProps)
.join(', ')} }`; .join(', ')} }`;
const isDynamicComponent = node.name === ':Component' || node.name === 'svelte:component'; const isDynamicComponent = node.name === 'svelte:component';
if (isDynamicComponent) block.contextualise(node.expression); if (isDynamicComponent) block.contextualise(node.expression);
const expression = ( const expression = (
(node.name === ':Self' || node.name === 'svelte:self') ? generator.name : node.name === 'svelte:self' ? generator.name :
isDynamicComponent ? `((${node.metadata.snippet}) || __missingComponent)` : isDynamicComponent ? `((${node.metadata.snippet}) || __missingComponent)` :
`%components-${node.name}` `%components-${node.name}`
); );

@ -86,7 +86,7 @@ export default function tag(parser: Parser) {
if (metaTags.has(name)) { if (metaTags.has(name)) {
const slug = metaTags.get(name).toLowerCase(); const slug = metaTags.get(name).toLowerCase();
if (isClosingTag) { if (isClosingTag) {
if ((name === ':Window' || name === 'svelte:window') && parser.current().children.length) { if (name === 'svelte:window' && parser.current().children.length) {
parser.error({ parser.error({
code: `invalid-window-content`, code: `invalid-window-content`,
message: `<${name}> cannot have children` 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(); const uniqueNames = new Set();
let attribute; let attribute;

@ -31,8 +31,6 @@ export default function validateHtml(validator: Validator, html: Node) {
else if (node.type === 'Element') { else if (node.type === 'Element') {
const isComponent = const isComponent =
node.name === ':Self' ||
node.name === ':Component' ||
node.name === 'svelte:self' || node.name === 'svelte:self' ||
node.name === 'svelte:component' || node.name === 'svelte:component' ||
validator.components.has(node.name); validator.components.has(node.name);

@ -297,7 +297,7 @@ function checkSlotAttribute(validator: Validator, node: Node, attribute: Node, s
const parent = stack[i]; const parent = stack[i];
if (parent.type === 'Element') { if (parent.type === 'Element') {
// if we're inside a component or a custom element, gravy // 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; if (/-/.test(parent.name)) return;
} }

Loading…
Cancel
Save