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 - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

6

index.js

@@ -30,4 +30,4 @@ /**

let replacementDescriptor = state.opts[path.node.name]
if (!replacementDescriptor) {
return
if (replacementDescriptor === undefined || replacementDescriptor === null) {
replacementDescriptor = t.identifier(String(replacementDescriptor))
}

@@ -46,3 +46,3 @@

}
} else if (type === 'object'
} else if (type === 'object'
&& replacementDescriptor.type === 'node'

@@ -49,0 +49,0 @@ && typeof replacementDescriptor.replacement === 'string') {

{
"name": "babel-plugin-inline-replace-variables",
"version": "1.3.0",
"version": "1.3.1",
"description": "babel plugin to inline replace variables",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -37,3 +37,30 @@ /**

describe('simple', () => {
describe(`transform`, () => {
it(`__SERVER__ should be replaced to false`, () => {
babel.transform(`
if (__SERVER__) {
console.log('this is server, version: %s', __VERSION__)
} else {
alert('this is browser')
}
`, {
plugins: [[plugin, {
__SERVER__: false,
__VERSION__: "v1.2.3"
}]]
}).code
.should.be.equal(`
if (false) {
console.log('this is server, version: %s', 'v1.2.3');
} else {
alert('this is browser');
}`)
});
});
});
describe('member expression', () => {

@@ -179,2 +206,59 @@ describe(`transform`, () => {

describe('support false value replacement', () => {
it('__DEV__ should be replaced by false', () => {
babel.transform(`
if (__DEV__) {
console.log('this is dev');
} else {
console.log('this is prod');
}
`, {
plugins: [[plugin, {
__DEV__: false
}]]
}).code.should.be.equal(`
if (false) {
console.log('this is dev');
} else {
console.log('this is prod');
}`);
});
it('__DEV__ should be replaced by undefined', () => {
babel.transform(`
if (__DEV__) {
console.log('this is dev');
} else {
console.log('this is prod');
}
`, {
plugins: [[plugin, {
__DEV__: undefined
}]]
}).code.should.be.equal(`
if (undefined) {
console.log('this is dev');
} else {
console.log('this is prod');
}`);
});
it('__DEV__ should be replaced by null', () => {
babel.transform(`
if (__DEV__) {
console.log('this is dev');
} else {
console.log('this is prod');
}
`, {
plugins: [[plugin, {
__DEV__: null
}]]
}).code.should.be.equal(`
if (null) {
console.log('this is dev');
} else {
console.log('this is prod');
}`);
});
});
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