forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove-check.js
52 lines (47 loc) · 1.12 KB
/
remove-check.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var through2 = require('through2')
var falafel = require('falafel')
function isCheckCall (node) {
if (node.type === 'Identifier' && node.name === 'check') {
return true
}
return (
node.type === 'MemberExpression' &&
node.object.type === 'Identifier' &&
node.object.name === 'check')
}
function isCheckRequire (node) {
return node.id.name === 'check'
}
module.exports = function () {
var data = ''
return through2(write, end)
function write (chunk, enc, done) {
data += chunk
done()
}
function end (done) {
try {
var result = falafel(data, function (node) {
switch (node.type) {
case 'CallExpression':
if (isCheckCall(node.callee)) {
node.update('')
return
}
break
case 'VariableDeclaration':
if (node.declarations.length === 1 &&
isCheckRequire(node.declarations[0])) {
node.update('')
return
}
break
}
})
this.push(result.toString())
} catch (e) {
this.push(data)
}
done()
}
}