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

babel plugin to inline replace variables

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
484
decreased by-63.11%
Maintainers
2
Weekly downloads
 
Created
Source

babel-plugin-inline-replace-variables

Build Status

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

Usage

npm i babel-plugin-inline-replace-variables --save-dev

configure in .babelrc(should transfer to json format) or any babel queries:

{
  plugins: [
    ['inline-replace-variables', {
      "__SERVER__": true,
      "__VERSION__": "v1.2.3"
    }]
  ]
}
EFFECT:
if (__SERVER__) {
  console.log('this is server, version: %s', __VERSION__)
} else {
  alert('this is browser')
}

will be transformed to

if (true) {
  console.log('this is server, version: %s', "v1.2.3")
} else {
  alert('this is browser')
}

Support Replace With Expression:

{
  plugins: [
    ['inline-replace-variables', {
      "__TYPE__": {
        type: 'node',
        replacement: 'process.env.NODE_ENV'
      }
    }]
  ]
}
EFFECT
if (__TYPE__) {
  // code
}

to

if (process.env.NODE_ENV) {
  // code
}

Also support babel AST Node

const t = require('babel-types');
const nodeEnv = t.memberExpression(t.memberExpression(t.identifier('process'), t.identifier('env')), t.identifier('NODE_ENV'));

{
  plugins: [
    ['inline-replace-variables', {
      "__TYPE__": nodeEnv
    }]
  ]
}
EFFECT

The effect is the same above.

tip:

Version 1.0.1 fix the misspelling of 'varibles' to 'variables'

so babel-plugin-inline-replace-varibles is deprecated, you should instead it of babel-plugin-inline-replace-variables

Authors: https://github.com/wssgcg1213, https://github.com/rtsao

Keywords

FAQs

Package last updated on 01 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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