throw error in dev mode for missing bound properties (#249)

pull/322/head
Rich Harris 8 years ago
parent a8d19839cd
commit 0e1d4c4bc7

@ -319,7 +319,7 @@ export default function dom ( parsed, source, options, names ) {
if ( options.dev ) {
Object.keys( generator.expectedProperties ).forEach( prop => {
stateBlock.addLine(
`if ( !( '${prop}' in this._state ) ) throw new Error( "Component was created without expected data property 'foo'" );`
`if ( !( '${prop}' in this._state ) ) throw new Error( "Component was created without expected data property '${prop}'" );`
);
});
}

@ -63,7 +63,7 @@ export default function createBinding ( generator, node, attribute, current, loc
do {
if ( fragment.expression && fragment.context === prop ) {
if ( !isReference( fragment.expression ) ) {
if ( !isReference( fragment.expression ) ) {
// TODO this should happen in prior validation step
throw new Error( `${prop} is read-only, it cannot be bound` );
}
@ -72,6 +72,8 @@ export default function createBinding ( generator, node, attribute, current, loc
}
} while ( fragment = fragment.parent );
generator.expectedProperties[ prop ] = true;
const listName = current.listNames[ parts[0] ];
const indexName = current.indexNames[ parts[0] ];
@ -84,14 +86,18 @@ export default function createBinding ( generator, node, attribute, current, loc
component._set({ ${prop}: component.get( '${prop}' ) });
`;
} else if ( deep ) {
setter = deindent`
var ${parts[0]} = component.get( '${parts[0]}' );
${parts[0]}.${parts.slice( 1 ).join( '.' )} = ${value};
component._set({ ${parts[0]}: ${parts[0]} });
`;
} else {
setter = `component._set({ ${attribute.value}: ${value} });`;
if ( deep ) {
setter = deindent`
var ${parts[0]} = component.get( '${parts[0]}' );
${parts[0]}.${parts.slice( 1 ).join( '.' )} = ${value};
component._set({ ${parts[0]}: ${parts[0]} });
`;
} else {
setter = `component._set({ ${attribute.value}: ${value} });`;
}
generator.expectedProperties[ parts[0] ] = true;
}
// special case

@ -0,0 +1,7 @@
export default {
dev: true,
error ( assert, err ) {
assert.equal( err.message, `Component was created without expected data property 'value'` );
}
};
Loading…
Cancel
Save