babel-plugin-inline-replace-variables
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -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'); | ||
}`); | ||
}); | ||
}); |
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
11338
310