-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsquareBrackets.js
More file actions
28 lines (27 loc) · 833 Bytes
/
squareBrackets.js
File metadata and controls
28 lines (27 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const estraverse = require('estraverse')
module.exports = parsed => {
return estraverse.replace(parsed, {
enter: node => {
if (
node.type === 'MemberExpression' &&
node.computed &&
node.property.type === 'Literal' &&
typeof node.property.value === 'string' &&
!(/^\d/.test(node.property.value)) &&
!node.property.value.includes('.') &&
!node.property.value.includes('-') &&
!node.property.value.includes(' ') &&
!node.property.value.includes('[') &&
!node.property.value.includes(']') &&
!node.property.value.includes('@') &&
!node.property.value.includes('*')
) {
node.computed = false
node.property = {
type: 'Identifier',
name: node.property.value
}
}
}
})
}