From 8f854b4b49dde4f6f189870fc18b9a754bcd8715 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 8 Sep 2018 22:34:58 -0400 Subject: [PATCH] rename Component to InlineComponent --- src/compile/nodes/Binding.ts | 2 +- src/compile/nodes/Element.ts | 8 ++++---- src/compile/nodes/{Component.ts => InlineComponent.ts} | 4 ++-- src/compile/nodes/Text.ts | 4 ++-- src/compile/nodes/shared/mapChildren.ts | 4 ++-- src/parse/state/tag.ts | 4 ++-- src/validate/html/index.ts | 2 +- src/validate/html/validateElement.ts | 6 +++--- test/parser/samples/binding-shorthand/output.json | 2 +- test/parser/samples/component-dynamic/output.json | 2 +- test/parser/samples/self-reference/output.json | 2 +- 11 files changed, 20 insertions(+), 20 deletions(-) rename src/compile/nodes/{Component.ts => InlineComponent.ts} (99%) diff --git a/src/compile/nodes/Binding.ts b/src/compile/nodes/Binding.ts index 168c3b44b5..45db895f7e 100644 --- a/src/compile/nodes/Binding.ts +++ b/src/compile/nodes/Binding.ts @@ -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; diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index a3040b81c2..d693fc04d7 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -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]; diff --git a/src/compile/nodes/Component.ts b/src/compile/nodes/InlineComponent.ts similarity index 99% rename from src/compile/nodes/Component.ts rename to src/compile/nodes/InlineComponent.ts index 526af029c8..dc5e87fd10 100644 --- a/src/compile/nodes/Component.ts +++ b/src/compile/nodes/InlineComponent.ts @@ -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[]; diff --git a/src/compile/nodes/Text.ts b/src/compile/nodes/Text.ts index bba5b2848b..ab502bf640 100644 --- a/src/compile/nodes/Text.ts +++ b/src/compile/nodes/Text.ts @@ -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); } diff --git a/src/compile/nodes/shared/mapChildren.ts b/src/compile/nodes/shared/mapChildren.ts index 9cd238644c..ee36d31626 100644 --- a/src/compile/nodes/shared/mapChildren.ts +++ b/src/compile/nodes/shared/mapChildren.ts @@ -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; diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 4a0d050144..bc112d4bbc 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -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'; diff --git a/src/validate/html/index.ts b/src/validate/html/index.ts index eabe9d8872..056b920cad 100644 --- a/src/validate/html/index.ts +++ b/src/validate/html/index.ts @@ -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, diff --git a/src/validate/html/validateElement.ts b/src/validate/html/validateElement.ts index 3d2d96f380..c01109f2f2 100644 --- a/src/validate/html/validateElement.ts +++ b/src/validate/html/validateElement.ts @@ -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') { diff --git a/test/parser/samples/binding-shorthand/output.json b/test/parser/samples/binding-shorthand/output.json index 4c92fb9e20..b0465e0a3e 100644 --- a/test/parser/samples/binding-shorthand/output.json +++ b/test/parser/samples/binding-shorthand/output.json @@ -8,7 +8,7 @@ { "start": 0, "end": 18, - "type": "Component", + "type": "InlineComponent", "name": "Widget", "attributes": [ { diff --git a/test/parser/samples/component-dynamic/output.json b/test/parser/samples/component-dynamic/output.json index 67e8f1e4ca..6c3fa442ce 100644 --- a/test/parser/samples/component-dynamic/output.json +++ b/test/parser/samples/component-dynamic/output.json @@ -8,7 +8,7 @@ { "start": 0, "end": 62, - "type": "Component", + "type": "InlineComponent", "name": "svelte:component", "attributes": [], "children": [], diff --git a/test/parser/samples/self-reference/output.json b/test/parser/samples/self-reference/output.json index c7e29c6f59..370f5f7bed 100644 --- a/test/parser/samples/self-reference/output.json +++ b/test/parser/samples/self-reference/output.json @@ -32,7 +32,7 @@ { "start": 17, "end": 51, - "type": "Component", + "type": "InlineComponent", "name": "svelte:self", "attributes": [ {