Merge pull request #2999 from hzoo/inline-env

Fix transform-inline-environment-variables - fixes #2991
This commit is contained in:
Henry Zhu 2015-11-11 20:20:36 -05:00
commit 52dd3e8006
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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]));
} }
} }
} }