/
index.js
31 lines (27 loc) · 897 Bytes
/
index.js
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
29
30
31
'use strict'
const falafel = require('falafel')
const babylon = require('babylon')
module.exports = removeReactPropTypes
const isPropTypesExpression = (node) =>
node.type === 'MemberExpression' && node.property.type === 'Identifier' &&
node.property.name === 'propTypes'
function removeReactPropTypes (src) {
return falafel(src, {
parser: babylon,
allowImportExportEverywhere: true,
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
sourceType: 'module',
plugins: [ '*', 'jsx', 'flow' ]
}, (node) => {
if (node.type === 'AssignmentExpression' && isPropTypesExpression(node.left)) {
// Remove entirely if it's a separate statement
if (node.parent.type === 'ExpressionStatement') {
node.parent.update('')
} else {
// Else replace it with undefined
node.update(`void 0`)
}
}
}).toString()
}