rename Component to InlineComponent

pull/1721/head
Rich Harris 7 years ago
parent 27f7df4db8
commit 8f854b4b49

@ -16,7 +16,7 @@ const readOnlyMediaAttributes = new Set([
]);
// TODO a lot of this element-specific stuff should live in Element —
// Binding should ideally be agnostic between Element and Component
// Binding should ideally be agnostic between Element and InlineComponent
export default class Binding extends Node {
name: string;

@ -284,11 +284,11 @@ export default class Element extends Node {
}
const slot = this.getStaticAttributeValue('slot');
if (slot && this.hasAncestor('Component')) {
if (slot && this.hasAncestor('InlineComponent')) {
this.cannotUseInnerHTML();
this.slotted = true;
// TODO validate slots — no nesting, no dynamic names...
const component = this.findNearest(/^Component/);
const component = this.findNearest(/^InlineComponent/);
component._slots.add(slot);
}
@ -318,7 +318,7 @@ export default class Element extends Node {
const slot = this.attributes.find((attribute: Node) => attribute.name === 'slot');
const prop = slot && quotePropIfNecessary(slot.chunks[0].data);
const initialMountNode = this.slotted ?
`${this.findNearest(/^Component/).var}._slotted${prop}` : // TODO this looks bonkers
`${this.findNearest(/^InlineComponent/).var}._slotted${prop}` : // TODO this looks bonkers
parentNode;
block.addVariable(node);
@ -977,7 +977,7 @@ export default class Element extends Node {
let textareaContents; // awkward special case
const slot = this.getStaticAttributeValue('slot');
if (slot && this.hasAncestor('Component')) {
if (slot && this.hasAncestor('InlineComponent')) {
const slot = this.attributes.find((attribute: Node) => attribute.name === 'slot');
const slotName = slot.chunks[0].data;
const appendTarget = compiler.target.appendTargets[compiler.target.appendTargets.length - 1];

@ -15,8 +15,8 @@ import Expression from './shared/Expression';
import { AppendTarget } from '../../interfaces';
import addToSet from '../../utils/addToSet';
export default class Component extends Node {
type: 'Component';
export default class InlineComponent extends Node {
type: 'InlineComponent';
name: string;
expression: Expression;
attributes: Attribute[];

@ -17,11 +17,11 @@ const elementsWithoutText = new Set([
function shouldSkip(node: Text) {
if (/\S/.test(node.data)) return false;
const parentElement = node.findNearest(/(?:Element|Component|Head)/);
const parentElement = node.findNearest(/(?:Element|InlineComponent|Head)/);
if (!parentElement) return false;
if (parentElement.type === 'Head') return true;
if (parentElement.type === 'Component') return parentElement.children.length === 1 && node === parentElement.children[0];
if (parentElement.type === 'InlineComponent') return parentElement.children.length === 1 && node === parentElement.children[0];
return parentElement.namespace || elementsWithoutText.has(parentElement.name);
}

@ -1,10 +1,10 @@
import AwaitBlock from '../AwaitBlock';
import Comment from '../Comment';
import Component from '../Component';
import EachBlock from '../EachBlock';
import Element from '../Element';
import Head from '../Head';
import IfBlock from '../IfBlock';
import InlineComponent from '../InlineComponent';
import MustacheTag from '../MustacheTag';
import RawMustacheTag from '../RawMustacheTag';
import DebugTag from '../DebugTag';
@ -18,11 +18,11 @@ function getConstructor(type): typeof Node {
switch (type) {
case 'AwaitBlock': return AwaitBlock;
case 'Comment': return Comment;
case 'Component': return Component;
case 'EachBlock': return EachBlock;
case 'Element': return Element;
case 'Head': return Head;
case 'IfBlock': return IfBlock;
case 'InlineComponent': return InlineComponent;
case 'MustacheTag': return MustacheTag;
case 'RawMustacheTag': return RawMustacheTag;
case 'DebugTag': return DebugTag;

@ -65,7 +65,7 @@ function parentIsHead(stack) {
while (i--) {
const { type } = stack[i];
if (type === 'Head') return true;
if (type === 'Element' || type === 'Component') return false;
if (type === 'Element' || type === 'InlineComponent') return false;
}
return false;
}
@ -123,7 +123,7 @@ export default function tag(parser: Parser) {
const type = metaTags.has(name)
? metaTags.get(name)
: (/[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component') ? 'Component'
: (/[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component') ? 'InlineComponent'
: name === 'title' && parentIsHead(parser.stack) ? 'Title'
: name === 'slot' && !parser.customElement ? 'Slot' : 'Element';

@ -36,7 +36,7 @@ export default function validateHtml(validator: Validator, html: Node) {
validateSlot(validator, node);
}
else if (node.type === 'Component' || node.name === 'svelte:self' || node.name === 'svelte:component') {
else if (node.type === 'InlineComponent' || node.name === 'svelte:self' || node.name === 'svelte:component') {
validateComponent(
validator,
node,

@ -85,11 +85,11 @@ export default function validateElement(
if (attribute.type === 'Ref') {
if (!isValidIdentifier(attribute.name)) {
const suggestion = attribute.name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&');
validator.error(attribute, {
code: `invalid-reference-name`,
message: `Reference name '${attribute.name}' is invalid — must be a valid identifier such as ${suggestion}`
});
});
} else {
if (!refs.has(attribute.name)) refs.set(attribute.name, []);
refs.get(attribute.name).push(node);
@ -350,7 +350,7 @@ function checkSlotAttribute(validator: Validator, node: Node, attribute: Node, s
while (i--) {
const parent = stack[i];
if (parent.type === 'Component') {
if (parent.type === 'InlineComponent') {
// if we're inside a component or a custom element, gravy
if (parent.name === 'svelte:self' || parent.name === 'svelte:component' || validator.components.has(parent.name)) return;
} else if (parent.type === 'Element') {

@ -8,7 +8,7 @@
{
"start": 0,
"end": 18,
"type": "Component",
"type": "InlineComponent",
"name": "Widget",
"attributes": [
{

@ -8,7 +8,7 @@
{
"start": 0,
"end": 62,
"type": "Component",
"type": "InlineComponent",
"name": "svelte:component",
"attributes": [],
"children": [],

@ -32,7 +32,7 @@
{
"start": 17,
"end": 51,
"type": "Component",
"type": "InlineComponent",
"name": "svelte:self",
"attributes": [
{

Loading…
Cancel
Save