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.variables = new Map();
this.getUniqueName = this.generator.getUniqueNameMaker( options.params ); this.getUniqueName = this.generator.getUniqueNameMaker( options.params );
this.intros = [];
this.outros = [];
// unique names // unique names
this.component = this.getUniqueName( 'component' ); this.component = this.getUniqueName( 'component' );
this.target = this.getUniqueName( 'target' ); this.target = this.getUniqueName( 'target' );

@ -5,12 +5,12 @@ export default function visitTransition ( generator, block, state, node, attribu
block.addVariable( name ); 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 ) { if ( attribute.intro ) {
generator.hasIntroTransitions = true; 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.builders.create.addBlock( deindent`
${block.component}._renderHooks.push({ ${block.component}._renderHooks.push({
fn: function () { fn: function () {
@ -22,9 +22,9 @@ export default function visitTransition ( generator, block, state, node, attribu
` ); ` );
} }
( attribute.intro ? block.intros : block.outros ).push({ if ( attribute.outro ) {
node: state.name, generator.hasOutroTransitions = true;
transition: attribute.name,
params: block.contextualise( attribute.expression ).snippet throw new Error( 'TODO' );
}); }
} }

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

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