Skip to content

Commit 796af04

Browse files
committed
handle shorthand properties in expressions (fixes #296)
1 parent dc4e929 commit 796af04

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/generators/Generator.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class Generator {
4646
const { contextDependencies, contexts, indexes } = this.current;
4747

4848
walk( expression, {
49-
enter ( node, parent ) {
49+
enter ( node, parent, key ) {
5050
if ( isReference( node, parent ) ) {
5151
const { name } = flattenReference( node );
5252

@@ -69,6 +69,14 @@ export default class Generator {
6969
}
7070

7171
else {
72+
// handle shorthand properties
73+
if ( parent.type === 'Property' && parent.shorthand ) {
74+
if ( key === 'key' ) {
75+
code.appendLeft( node.start, `${name}: ` );
76+
return;
77+
}
78+
}
79+
7280
if ( globalWhitelist[ name ] ) {
7381
code.prependRight( node.start, `( '${name}' in root ? root.` );
7482
code.appendLeft( node.object.end, ` : ${name} )` );
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default {
2+
html: `<button>click me</button>`,
3+
4+
data: {
5+
foo: 42
6+
},
7+
8+
test ( assert, component, target, window ) {
9+
const event = new window.MouseEvent( 'click' );
10+
const button = target.querySelector( 'button' );
11+
12+
let count = 0;
13+
let number = null;
14+
15+
component.on( 'foo', obj => {
16+
count++;
17+
number = obj.foo;
18+
});
19+
20+
button.dispatchEvent( event );
21+
22+
assert.equal( count, 1 );
23+
assert.equal( number, 42 );
24+
25+
component.teardown();
26+
}
27+
};
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button on:click='fire("foo", { foo })'>click me</button>

0 commit comments

Comments
 (0)