move some babel-plugins into the main repo

This commit is contained in:
Sebastian McKenzie
2015-09-01 06:58:53 +01:00
parent f33c96c276
commit 9f9d9cd84b
61 changed files with 1779 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
node_modules
*.log
src

View File

@@ -0,0 +1,35 @@
# babel-plugin-inline-environment-variables
Inline environment variables
## Installation
```sh
$ npm install babel-plugin-inline-environment-variables
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["inline-environment-variables"]
}
```
### Via CLI
```sh
$ babel --plugins inline-environment-variables script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["inline-environment-variables"]
});
```

View File

@@ -0,0 +1,11 @@
{
"name": "babel-plugin-inline-environment-variables",
"version": "1.0.1",
"description": "Inline environment variables",
"repository": "babel-plugins/babel-plugin-inline-environment-variables",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin"
]
}

View File

@@ -0,0 +1,18 @@
export default function ({ Plugin, types: t }) {
return new Plugin("inline-environment-variables", {
metadata: {
group: "builtin-pre"
},
visitor: {
MemberExpression(node) {
if (this.get("object").matchesPattern("process.env")) {
var key = this.toComputedKey();
if (t.isLiteral(key)) {
return t.valueToNode(process.env[key.value]);
}
}
}
}
});
}