babel-plugin-feature-flags
Advanced tools
Comparing version 0.1.2 to 0.2.0
17
index.js
@@ -13,4 +13,13 @@ module.exports = function(options) { | ||
var value = options.features[feature]; | ||
if (value !== true && value !== false && value !== 'skip') { | ||
throw new Error("Each feature in options.features must have a value of `true`, `false` or `skip`."); | ||
if (typeof value === 'string') { | ||
if (value === 'enabled') { | ||
options.features[feature] = true; | ||
} else if (value === 'disabled') { | ||
options.features[feature] = false; | ||
} else if (value === 'dynamic') { | ||
options.features[feature] = null; | ||
} else { | ||
throw new Error("An unknown feature state '" + value + "' was detected for '" + feature + "'. Valid values are 'enabled', 'disabled' and 'dynamic'"); | ||
} | ||
} | ||
@@ -32,5 +41,3 @@ }); | ||
if (value === 'skip') { | ||
// Do nothing | ||
} else if (value === !invert) { | ||
if (value === !invert) { | ||
var consequent = ifStatement.node.consequent; | ||
@@ -37,0 +44,0 @@ ifStatement.replaceWithMultiple(consequent.body); |
{ | ||
"name": "babel-plugin-feature-flags", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A babel transform for managing feature flags", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,5 +27,5 @@ var assert = require('assert'); | ||
features: { | ||
enabled: true, | ||
disabled: false, | ||
skipped: 'skip' | ||
enabled: 'enabled', | ||
disabled: 'disabled', | ||
dynamic: 'dynamic' | ||
} | ||
@@ -36,19 +36,19 @@ } | ||
testFixture('if/disabled', options); | ||
testFixture('if/skipped', options); | ||
testFixture('if/dynamic', options); | ||
testFixture('else/enabled', options); | ||
testFixture('else/disabled', options); | ||
testFixture('else/skipped', options); | ||
testFixture('else/dynamic', options); | ||
testFixture('not-if/enabled', options); | ||
testFixture('not-if/disabled', options); | ||
testFixture('not-if/skipped', options); | ||
testFixture('not-if/dynamic', options); | ||
testFixture('nested/enabled-enabled', options); | ||
testFixture('nested/enabled-disabled', options); | ||
testFixture('nested/enabled-skipped', options); | ||
testFixture('nested/enabled-dynamic', options); | ||
testFixture('nested/disabled-enabled', options); | ||
testFixture('nested/disabled-disabled', options); | ||
testFixture('nested/disabled-skipped', options); | ||
testFixture('nested/skipped-enabled', options); | ||
testFixture('nested/skipped-disabled', options); | ||
testFixture('nested/skipped-skipped', options); | ||
testFixture('nested/disabled-dynamic', options); | ||
testFixture('nested/dynamic-enabled', options); | ||
testFixture('nested/dynamic-disabled', options); | ||
testFixture('nested/dynamic-dynamic', options); | ||
testFixture('preserves-other-imports', options); | ||
}); |
11674
332