Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-inline-replace-variables

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-inline-replace-variables - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

package.json
{
"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",

8

readme.md
# 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');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc