fix tests, finish renaming stuff

pull/971/head
Rich Harris 8 years ago
parent e238c65a15
commit 0d42ff84db

@ -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'), value: block.getUniqueName('switch_value'),
props: block.getUniqueName('switch_props') props: block.getUniqueName('switch_props')
}; };
const expression = ( const expression = (
node.name === ':Self' ? generator.name : node.name === ':Self' ? generator.name :
isSwitch ? switch_vars.value : isDynamicComponent ? switch_vars.value :
`%components-${node.name}` `%components-${node.name}`
); );
if (isSwitch) { if (isDynamicComponent) {
block.contextualise(node.expression); block.contextualise(node.expression);
const { dependencies, snippet } = node.metadata; const { dependencies, snippet } = node.metadata;

@ -71,12 +71,12 @@ export default function visitComponent(
) )
.join(', '); .join(', ');
const isSwitch = node.name === ':Component'; const isDynamicComponent = node.name === ':Component';
if (isSwitch) block.contextualise(node.expression); if (isDynamicComponent) block.contextualise(node.expression);
const expression = ( const expression = (
node.name === ':Self' ? generator.name : node.name === ':Self' ? generator.name :
isSwitch ? `((${node.metadata.snippet}) || __missingComponent)` : isDynamicComponent ? `((${node.metadata.snippet}) || __missingComponent)` :
`%components-${node.name}` `%components-${node.name}`
); );

@ -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 = ':Component'; const COMPONENT = ':Component';
const metaTags = { const metaTags = {
':Window': true ':Window': true
@ -166,7 +166,7 @@ export default function tag(parser: Parser) {
} }
} }
if (name === SWITCH) { if (name === COMPONENT) {
parser.eat('{', true); parser.eat('{', true);
element.expression = readExpression(parser); element.expression = readExpression(parser);
parser.allowWhitespace(); parser.allowWhitespace();
@ -248,7 +248,7 @@ function readTagName(parser: Parser) {
return SELF; return SELF;
} }
if (parser.eat(SWITCH)) return SWITCH; if (parser.eat(COMPONENT)) return COMPONENT;
const name = parser.readUntil(/(\s|\/|>)/); const name = parser.readUntil(/(\s|\/|>)/);

@ -1 +1 @@
<:Switch {foo ? Foo : Bar}></:Switch> <:Component {foo ? Foo : Bar}></:Component>

@ -1,37 +1,37 @@
{ {
"hash": 755548012, "hash": 410218696,
"html": { "html": {
"start": 0, "start": 0,
"end": 37, "end": 43,
"type": "Fragment", "type": "Fragment",
"children": [ "children": [
{ {
"start": 0, "start": 0,
"end": 37, "end": 43,
"type": "Element", "type": "Element",
"name": ":Switch", "name": ":Component",
"attributes": [], "attributes": [],
"children": [], "children": [],
"expression": { "expression": {
"type": "ConditionalExpression", "type": "ConditionalExpression",
"start": 10, "start": 13,
"end": 25, "end": 28,
"test": { "test": {
"type": "Identifier", "type": "Identifier",
"start": 10, "start": 13,
"end": 13, "end": 16,
"name": "foo" "name": "foo"
}, },
"consequent": { "consequent": {
"type": "Identifier", "type": "Identifier",
"start": 16, "start": 19,
"end": 19, "end": 22,
"name": "Foo" "name": "Foo"
}, },
"alternate": { "alternate": {
"type": "Identifier", "type": "Identifier",
"start": 22, "start": 25,
"end": 25, "end": 28,
"name": "Bar" "name": "Bar"
} }
} }

@ -1,4 +1,4 @@
<:Switch { x ? Foo : Bar } bind:y bind:z/> <:Component { x ? Foo : Bar } bind:y bind:z/>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';

@ -1,4 +1,4 @@
<:Switch { x ? Foo : Bar } on:select='set({ selected: event.id })'/> <:Component { x ? Foo : Bar } on:select='set({ selected: event.id })'/>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';

@ -1,4 +1,4 @@
<:Switch { x ? Foo : Bar } x='{{x}}'> <:Component { x ? Foo : Bar } x='{{x}}'>
<p>element</p> <p>element</p>
{{tag}} {{tag}}
@ -20,7 +20,7 @@
<Baz/> <Baz/>
<div slot='other'>what goes up must come down</div> <div slot='other'>what goes up must come down</div>
</:Switch> </:Component>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';

@ -1,4 +1,4 @@
<:Switch { x ? Foo : Bar } x='{{x}}'/> <:Component { x ? Foo : Bar } x='{{x}}'/>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';

@ -1,4 +1,4 @@
<:Switch { x ? Foo : Bar } x='{{x}}'/> <:Component { x ? Foo : Bar } x='{{x}}'/>
<script> <script>
import Foo from './Foo.html'; import Foo from './Foo.html';

Loading…
Cancel
Save