babel-plugin-inline-replace-variables
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "babel-plugin-inline-replace-variables", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "babel plugin to inline replace variables", | ||
@@ -23,4 +23,3 @@ "main": "lib/index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -27,0 +26,0 @@ "babel-core": "^6.8.0", |
# babel-plugin-inline-replace-variables | ||
[![Build Status](https://travis-ci.org/wssgcg1213/babel-plugin-inline-replace-variables.svg?branch=master)](https://travis-ci.org/wssgcg1213/babel-plugin-inline-replace-variables) | ||
It replace an Identifier to a literial (LVal), if you want to transfrom a identifier to another identifier, you can see: [babel-plugin-replace-identifiers](https://github.com/wssgcg1213/babel-plugin-replace-identifiers) | ||
## Usage | ||
@@ -13,5 +15,5 @@ | ||
plugins: [ | ||
['inline-replace-varibles', { | ||
__SERVER__: true, | ||
__VERSION__: "v1.2.3" | ||
['inline-replace-variables', { | ||
"__SERVER__": true, | ||
"__VERSION__": "v1.2.3" | ||
}] | ||
@@ -18,0 +20,0 @@ ] |
@@ -7,8 +7,17 @@ /** | ||
export default ({types}) => ({ | ||
export default ({types: t}) => ({ | ||
visitor: { | ||
Identifier (path, state) { | ||
path.node.name = JSON.stringify(state.opts[path.node.name]) || path.node.name | ||
const replacement = state.opts[path.node.name] | ||
if (replacement !== undefined) { | ||
const type = typeof replacement | ||
if (type === 'boolean') { | ||
path.replaceWith(t.booleanLiteral(replacement)) | ||
} else { // treat as string | ||
const str = String(replacement) | ||
path.replaceWith(t.stringLiteral(str)) | ||
} | ||
} | ||
} | ||
} | ||
}); |
@@ -27,3 +27,3 @@ /** | ||
if (true) { | ||
console.log('this is server, version: %s', "v1.2.3"); | ||
console.log('this is server, version: %s', 'v1.2.3'); | ||
} else { | ||
@@ -30,0 +30,0 @@ alert('this is browser'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4100
72
56