Skip to content

Commit 20deabd

Browse files
committed
Add getComputedProperties logic
1 parent 34fb5da commit 20deabd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/rules/no-side-effects-in-computed-properties.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,42 @@
66

77
const utils = require('../utils')
88

9+
function getComputedProperties (componentProperties) {
10+
const computedPropertiesNode = componentProperties
11+
.filter(p =>
12+
p.key.type === 'Identifier' &&
13+
p.key.name === 'computed' &&
14+
p.value.type === 'ObjectExpression'
15+
)[0]
16+
17+
if (!computedPropertiesNode) { return [] }
18+
19+
const computedProperties = computedPropertiesNode.value.properties
20+
21+
return computedProperties.map(cp => {
22+
const key = cp.key.name
23+
let value
24+
25+
if (cp.value.type === 'FunctionExpression') {
26+
value = cp.value.body.body
27+
} else if (cp.value.type === 'ObjectExpression') {
28+
value = cp.value.properties
29+
.filter(p =>
30+
p.key.type === 'Identifier' &&
31+
p.key.name === 'get' &&
32+
p.value.type === 'FunctionExpression'
33+
)
34+
.map(p => p.value.body.body)[0]
35+
}
36+
37+
return { key, value }
38+
})
39+
}
40+
941
function create (context) {
1042
return utils.executeOnVueComponent(context, (properties) => {
43+
const computedProperties = getComputedProperties(properties)
44+
// to be continued...
1145
})
1246
}
1347

0 commit comments

Comments
 (0)