start moving more transformers to packages and finish import of plugins from babel-plugins
This commit is contained in:
22
packages/babel-plugin-node-env-inline/src/index.js
Normal file
22
packages/babel-plugin-node-env-inline/src/index.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export default function ({ types: t }) {
|
||||
return {
|
||||
metadata: {
|
||||
group: "builtin-pre"
|
||||
},
|
||||
|
||||
visitor: {
|
||||
MemberExpression() {
|
||||
if (this.matchesPattern("process.env.NODE_ENV")) {
|
||||
this.replaceWith(t.valueToNode(process.env.NODE_ENV));
|
||||
|
||||
if (this.parentPath.isBinaryExpression()) {
|
||||
var evaluated = this.parentPath.evaluate();
|
||||
if (evaluated.confident) {
|
||||
this.parentPath.replaceWith(t.valueToNode(evaluated.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user