Merge pull request #2999 from hzoo/inline-env
Fix transform-inline-environment-variables - fixes #2991
This commit is contained in:
commit
52dd3e8006
@ -2,6 +2,21 @@
|
|||||||
|
|
||||||
Inline environment variables
|
Inline environment variables
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
### In
|
||||||
|
|
||||||
|
```js
|
||||||
|
// assuming process.env.NODE_ENV is actually "development"
|
||||||
|
process.env.NODE_ENV;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Out
|
||||||
|
|
||||||
|
```js
|
||||||
|
"development";
|
||||||
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export default function ({ types: t }) {
|
|||||||
if (path.get("object").matchesPattern("process.env")) {
|
if (path.get("object").matchesPattern("process.env")) {
|
||||||
let key = path.toComputedKey();
|
let key = path.toComputedKey();
|
||||||
if (t.isStringLiteral(key)) {
|
if (t.isStringLiteral(key)) {
|
||||||
return t.valueToNode(process.env[key.value]);
|
path.replace(t.valueToNode(process.env[key.value]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user