Skip to content

Commit 30f94f8

Browse files
authored
Fix getComputedProperties by allowing object spread inside CP (#465)
1 parent 409fe31 commit 30f94f8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Diff for: lib/utils/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ module.exports = {
344344
} else if (cp.value.type === 'ObjectExpression') {
345345
value = cp.value.properties
346346
.filter(p =>
347+
p.type === 'Property' &&
347348
p.key.type === 'Identifier' &&
348349
p.key.name === 'get' &&
349350
p.value.type === 'FunctionExpression'

Diff for: tests/lib/rules/no-async-in-computed-properties.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ ruleTester.run('no-async-in-computed-properties', rule, {
5151
return bar
5252
}
5353
},
54-
foo2: {
54+
bar: {
5555
set () {
5656
new Promise((resolve, reject) => {})
5757
}
58+
},
59+
baz: {
60+
...mapGetters({ get: 'getBaz' }),
61+
...mapActions({ set: 'setBaz' })
5862
}
5963
}
6064
}

Diff for: tests/lib/utils/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,28 @@ describe('getComputedProperties', () => {
120120

121121
assert.ok(computedProperties[0].value)
122122
})
123+
124+
it('should not collide with object spread operator inside CP', () => {
125+
node = parse(`const test = {
126+
name: 'test',
127+
computed: {
128+
foo: {
129+
...mapGetters({ get: 'getFoo' }),
130+
...mapActions({ set: 'setFoo' })
131+
}
132+
}
133+
}`)
134+
135+
const computedProperties = utils.getComputedProperties(node)
136+
137+
assert.equal(
138+
computedProperties.length,
139+
1,
140+
'it detects all computed properties'
141+
)
142+
143+
assert.notOk(computedProperties[0].value)
144+
})
123145
})
124146

125147
describe('getStaticPropertyName', () => {

0 commit comments

Comments
 (0)