-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (26 loc) · 959 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
module.exports = ({ types: t }) => {
return {
visitor: {
//插件执行逻辑
Identifier(path) {
const parentIsIf = t.isIfStatement(path.parentPath)
const isDebug = path.node.name === "TEST"
if (isDebug && parentIsIf) {
//转换成String
const stringNode = t.stringLiteral("TEST")
path.replaceWith(stringNode)
}
},
StringLiteral(path) {
const parentIsIf = t.isIfStatement(path.parentPath)
const isDebug = path.node.value === "TEST"
if (isDebug && parentIsIf) {
if (process.env.NODE_ENV === "production") {
// 调用方法remove删除path
path.parentPath.remove()
}
}
}
}
}
}