allow parameter-less transitions

pull/525/head
Rich-Harris 8 years ago
parent 6ed2a6c785
commit 53c5c32da3

@ -33,9 +33,6 @@ export default class Block {
this.variables = new Map();
this.getUniqueName = this.generator.getUniqueNameMaker( options.params );
this.intros = [];
this.outros = [];
// unique names
this.component = this.getUniqueName( 'component' );
this.target = this.getUniqueName( 'target' );

@ -5,12 +5,12 @@ export default function visitTransition ( generator, block, state, node, attribu
block.addVariable( name );
const snippet = attribute.expression ? block.contextualise( attribute.expression ).snippet : '{}';
const fn = `${generator.alias( 'template' )}.transitions.${attribute.name}`; // TODO add built-in transitions?
if ( attribute.intro ) {
generator.hasIntroTransitions = true;
const { snippet } = block.contextualise( attribute.expression );
const fn = `${generator.alias( 'template' )}.transitions.${attribute.name}`; // TODO add built-in transitions?
block.builders.create.addBlock( deindent`
${block.component}._renderHooks.push({
fn: function () {
@ -22,9 +22,9 @@ export default function visitTransition ( generator, block, state, node, attribu
` );
}
( attribute.intro ? block.intros : block.outros ).push({
node: state.name,
transition: attribute.name,
params: block.contextualise( attribute.expression ).snippet
});
if ( attribute.outro ) {
generator.hasOutroTransitions = true;
throw new Error( 'TODO' );
}
}

@ -131,18 +131,22 @@ export function readBindingDirective ( parser, start, name ) {
}
export function readTransitionDirective ( parser, start, name, type ) {
const quoteMark = (
parser.eat( `'` ) ? `'` :
parser.eat( `"` ) ? `"` :
null
);
let expression = null;
const expressionStart = parser.index;
if ( parser.eat( '=' ) ) {
const quoteMark = (
parser.eat( `'` ) ? `'` :
parser.eat( `"` ) ? `"` :
null
);
const expression = readExpression( parser, expressionStart, quoteMark );
const expressionStart = parser.index;
expression = readExpression( parser, expressionStart, quoteMark );
if ( expression.type !== 'ObjectExpression' ) {
parser.error( `Expected object expression`, expressionStart );
if ( expression.type !== 'ObjectExpression' ) {
parser.error( `Expected object expression`, expressionStart );
}
}
return {

@ -255,7 +255,6 @@ function readAttribute ( parser, uniqueNames ) {
const match = /^(in|out|transition):/.exec( name );
if ( match ) {
parser.eat( '=', true );
return readTransitionDirective( parser, start, name.slice( match[0].length ), match[1] );
}

@ -0,0 +1,37 @@
{
"hash": 1535528483,
"html": {
"start": 0,
"end": 27,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 27,
"type": "Element",
"name": "div",
"attributes": [
{
"start": 5,
"end": 12,
"type": "Transition",
"name": "fade",
"intro": true,
"outro": false,
"expression": null
}
],
"children": [
{
"start": 13,
"end": 21,
"type": "Text",
"data": "fades in"
}
]
}
]
},
"css": null,
"js": null
}
Loading…
Cancel
Save