rename :Switch -> :Component

pull/971/head
Rich Harris 7 years ago
parent e6ef5af6ba
commit e238c65a15

@ -764,7 +764,7 @@ export default class Generator {
this.skip(); this.skip();
} }
if (node.type === 'Element' && node.name === ':Switch') { if (node.type === 'Element' && node.name === ':Component') {
node.metadata = contextualise(node.expression, contextDependencies, indexes); node.metadata = contextualise(node.expression, contextDependencies, indexes);
} }
}, },

@ -437,7 +437,7 @@ const preprocessors = {
} }
const isComponent = const isComponent =
generator.components.has(node.name) || node.name === ':Self' || node.name === ':Switch'; generator.components.has(node.name) || node.name === ':Self' || node.name === ':Component';
if (isComponent) { if (isComponent) {
cannotUseInnerHTML(node); cannotUseInnerHTML(node);
@ -445,7 +445,7 @@ const preprocessors = {
node.var = block.getUniqueName( node.var = block.getUniqueName(
( (
node.name === ':Self' ? generator.name : node.name === ':Self' ? generator.name :
node.name === ':Switch' ? 'switch_instance' : node.name === ':Component' ? 'switch_instance' :
node.name node.name
).toLowerCase() ).toLowerCase()
); );

@ -205,7 +205,7 @@ export default function visitComponent(
} }
} }
const isSwitch = node.name === ':Switch'; const isSwitch = node.name === ':Component';
const switch_vars = isSwitch && { const switch_vars = isSwitch && {
value: block.getUniqueName('switch_value'), value: block.getUniqueName('switch_value'),
@ -563,7 +563,7 @@ function remount(generator: DomGenerator, node: Node, name: string) {
// TODO make this a method of the nodes // TODO make this a method of the nodes
if (node.type === 'Element') { if (node.type === 'Element') {
if (node.name === ':Self' || node.name === ':Switch' || generator.components.has(node.name)) { if (node.name === ':Self' || node.name === ':Component' || generator.components.has(node.name)) {
return `${node.var}._mount(${name}._slotted.default, null);`; return `${node.var}._mount(${name}._slotted.default, null);`;
} }

@ -43,7 +43,7 @@ export default function visitElement(
} }
} }
if (generator.components.has(node.name) || node.name === ':Self' || node.name === ':Switch') { if (generator.components.has(node.name) || node.name === ':Self' || node.name === ':Component') {
return visitComponent(generator, block, state, node, elementStack, componentStack); return visitComponent(generator, block, state, node, elementStack, componentStack);
} }

@ -71,7 +71,7 @@ export default function visitComponent(
) )
.join(', '); .join(', ');
const isSwitch = node.name === ':Switch'; const isSwitch = node.name === ':Component';
if (isSwitch) block.contextualise(node.expression); if (isSwitch) block.contextualise(node.expression);
const expression = ( const expression = (

@ -40,7 +40,7 @@ export default function visitElement(
return; return;
} }
if (generator.components.has(node.name) || node.name === ':Self' || node.name === ':Switch') { if (generator.components.has(node.name) || node.name === ':Self' || node.name === ':Component') {
visitComponent(generator, block, node); visitComponent(generator, block, node);
return; return;
} }

@ -4,7 +4,7 @@ import Generator from '../../Generator';
export default function isChildOfComponent(node: Node, generator: Generator) { export default function isChildOfComponent(node: Node, generator: Generator) {
while (node = node.parent) { while (node = node.parent) {
if (node.type !== 'Element') continue; if (node.type !== 'Element') continue;
if (node.name === ':Self' || node.name === ':Switch' || generator.components.has(node.name)) return true; // TODO extract this out into a helper if (node.name === ':Self' || node.name === ':Component' || generator.components.has(node.name)) return true; // TODO extract this out into a helper
if (/-/.test(node.name)) return false; if (/-/.test(node.name)) return false;
} }
} }

@ -15,7 +15,7 @@ import { Node } from '../../interfaces';
const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
const SELF = ':Self'; const SELF = ':Self';
const SWITCH = ':Switch'; const SWITCH = ':Component';
const metaTags = { const metaTags = {
':Window': true ':Window': true

@ -14,7 +14,7 @@ export default function validateElement(
elementStack: Node[] elementStack: Node[]
) { ) {
const isComponent = const isComponent =
node.name === ':Self' || node.name === ':Switch' || validator.components.has(node.name); node.name === ':Self' || node.name === ':Component' || validator.components.has(node.name);
if (!isComponent && /^[A-Z]/.test(node.name[0])) { if (!isComponent && /^[A-Z]/.test(node.name[0])) {
// TODO upgrade to validator.error in v2 // TODO upgrade to validator.error in v2
@ -230,7 +230,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 === ':Switch' || validator.components.has(parent.name)) return; if (parent.name === ':Self' || parent.name === ':Component' || validator.components.has(parent.name)) return;
if (/-/.test(parent.name)) return; if (/-/.test(parent.name)) return;
} }

Loading…
Cancel
Save