diff --git a/src/generators/dom/visitors/Component.ts b/src/generators/dom/visitors/Component.ts index 7f9cd16610..f3487b5a5c 100644 --- a/src/generators/dom/visitors/Component.ts +++ b/src/generators/dom/visitors/Component.ts @@ -205,20 +205,20 @@ export default function visitComponent( } } - const isSwitch = node.name === ':Component'; + const isDynamicComponent = node.name === ':Component'; - const switch_vars = isSwitch && { + const switch_vars = isDynamicComponent && { value: block.getUniqueName('switch_value'), props: block.getUniqueName('switch_props') }; const expression = ( node.name === ':Self' ? generator.name : - isSwitch ? switch_vars.value : + isDynamicComponent ? switch_vars.value : `%components-${node.name}` ); - if (isSwitch) { + if (isDynamicComponent) { block.contextualise(node.expression); const { dependencies, snippet } = node.metadata; diff --git a/src/generators/server-side-rendering/visitors/Component.ts b/src/generators/server-side-rendering/visitors/Component.ts index 0c800e1c8b..d6f44abb23 100644 --- a/src/generators/server-side-rendering/visitors/Component.ts +++ b/src/generators/server-side-rendering/visitors/Component.ts @@ -71,12 +71,12 @@ export default function visitComponent( ) .join(', '); - const isSwitch = node.name === ':Component'; - if (isSwitch) block.contextualise(node.expression); + const isDynamicComponent = node.name === ':Component'; + if (isDynamicComponent) block.contextualise(node.expression); const expression = ( node.name === ':Self' ? generator.name : - isSwitch ? `((${node.metadata.snippet}) || __missingComponent)` : + isDynamicComponent ? `((${node.metadata.snippet}) || __missingComponent)` : `%components-${node.name}` ); diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index d946656a90..90d9f5cd2c 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -15,7 +15,7 @@ import { Node } from '../../interfaces'; const validTagName = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; const SELF = ':Self'; -const SWITCH = ':Component'; +const COMPONENT = ':Component'; const metaTags = { ':Window': true @@ -166,7 +166,7 @@ export default function tag(parser: Parser) { } } - if (name === SWITCH) { + if (name === COMPONENT) { parser.eat('{', true); element.expression = readExpression(parser); parser.allowWhitespace(); @@ -248,7 +248,7 @@ function readTagName(parser: Parser) { return SELF; } - if (parser.eat(SWITCH)) return SWITCH; + if (parser.eat(COMPONENT)) return COMPONENT; const name = parser.readUntil(/(\s|\/|>)/); diff --git a/test/parser/samples/component-dynamic/input.html b/test/parser/samples/component-dynamic/input.html index 1c4e872902..0d5be48552 100644 --- a/test/parser/samples/component-dynamic/input.html +++ b/test/parser/samples/component-dynamic/input.html @@ -1 +1 @@ -<:Switch {foo ? Foo : Bar}> \ No newline at end of file +<:Component {foo ? Foo : Bar}> \ No newline at end of file diff --git a/test/parser/samples/component-dynamic/output.json b/test/parser/samples/component-dynamic/output.json index 22b32bb932..614c28c0a9 100644 --- a/test/parser/samples/component-dynamic/output.json +++ b/test/parser/samples/component-dynamic/output.json @@ -1,37 +1,37 @@ { - "hash": 755548012, + "hash": 410218696, "html": { "start": 0, - "end": 37, + "end": 43, "type": "Fragment", "children": [ { "start": 0, - "end": 37, + "end": 43, "type": "Element", - "name": ":Switch", + "name": ":Component", "attributes": [], "children": [], "expression": { "type": "ConditionalExpression", - "start": 10, - "end": 25, + "start": 13, + "end": 28, "test": { "type": "Identifier", - "start": 10, - "end": 13, + "start": 13, + "end": 16, "name": "foo" }, "consequent": { "type": "Identifier", - "start": 16, - "end": 19, + "start": 19, + "end": 22, "name": "Foo" }, "alternate": { "type": "Identifier", - "start": 22, - "end": 25, + "start": 25, + "end": 28, "name": "Bar" } } diff --git a/test/runtime/samples/dynamic-component-bindings/main.html b/test/runtime/samples/dynamic-component-bindings/main.html index 179677a19a..cb260da71f 100644 --- a/test/runtime/samples/dynamic-component-bindings/main.html +++ b/test/runtime/samples/dynamic-component-bindings/main.html @@ -1,4 +1,4 @@ -<:Switch { x ? Foo : Bar } bind:y bind:z/> +<:Component { x ? Foo : Bar } bind:y bind:z/>