Socket
Socket
Sign inDemoInstall

babel-plugin-debug-macros

Package Overview
Dependencies
53
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0-beta.5 to 0.2.0-beta.6

2

fixtures/debug-flag/expectation6.js
if (true) {
if (true /* DEBUG */) {
console.log('woot');
}

@@ -1,3 +0,5 @@

if (true) {
if (true
/* DEBUG */
) {
console.log('woot');
}
if (true) {
if (true /* DEBUG */) {
doStuff();

@@ -5,0 +5,0 @@ }

@@ -1,2 +0,4 @@

if (true) {
if (true
/* DEBUG */
) {
doStuff();

@@ -3,0 +5,0 @@ }

let testing;
if (false) {
if (false /* TESTING */) {
testing = 'WOOT';

@@ -9,4 +9,4 @@ }

let debug;
if (true) {
if (true /* DEBUG */) {
debug = 'DEBUG';
}
let testing;
if (false) {
if (false
/* TESTING */
) {
testing = 'WOOT';

@@ -9,4 +11,6 @@ }

if (true) {
if (true
/* DEBUG */
) {
debug = 'DEBUG';
}
let a;
if (false) {
if (false /* FEATURE_A */) {
a = () => console.log('hello');
} else if (true) {
} else if (true /* FEATURE_B */) {
a = () => console.log('bye');
}
if (!false) {
if (!false /* FEATURE_A */) {
console.log('stuff');
}
a = false ? 'hello' : 'bye';
a = false /* FEATURE_A */ ? 'hello' : 'bye';
if (false && window.foo && window.bar) {
if (false /* FEATURE_A */ && window.foo && window.bar) {
console.log('wheeee');
}
let a;
if (false) {
if (false
/* FEATURE_A */
) {
a = () => console.log('hello');
} else if (true) {
} else if (true
/* FEATURE_B */
) {
a = () => console.log('bye');
}
if (!false) {
if (!false
/* FEATURE_A */
) {
console.log('stuff');
}
a = false ? 'hello' : 'bye';
a = false
/* FEATURE_A */
? 'hello' : 'bye';
if (false && window.foo && window.bar) {
if (false
/* FEATURE_A */
&& window.foo && window.bar) {
console.log('wheeee');
}
import { FEATURE_B } from '@ember/features';
if (true) {
if (true /* FEATURE_A */) {
console.log('woot');

@@ -5,0 +5,0 @@ }

import { FEATURE_B } from '@ember/features';
if (true) {
if (true
/* FEATURE_A */
) {
console.log('woot');

@@ -5,0 +7,0 @@ }

@@ -15,3 +15,3 @@ {

"name": "babel-plugin-debug-macros",
"version": "0.2.0-beta.5",
"version": "0.2.0-beta.6",
"description": "Debug macros and feature flag stripping",

@@ -18,0 +18,0 @@ "main": "src/index.js",

@@ -7,4 +7,9 @@ # Babel Debug Macros And Feature Flags

The plugin takes 5 types options: `envFlags`, `features`, `debugTools`, `externalizeHelpers` and `svelte`. The `importSpecifier` is used as a hint to this plugin as to where macros are being imported and completely configurable by the host. Like Babel you can supply your own helpers using the `externalizeHelpers` options.
The plugin takes 4 types options: `flags`, `svelte`, `debugTools`, and
`externalizeHelpers`. The `importSpecifier` is used as a hint to this plugin as
to where macros are being imported and completely configurable by the host.
Like Babel you can supply your own helpers using the `externalizeHelpers`
options.
```js

@@ -15,8 +20,4 @@ {

// @required
envFlags: {
source: '@ember/env-flags',
flags: { DEBUG: true }
},
// @required
debugTools: {
isDebug: true,
source: 'debug-tools',

@@ -26,12 +27,21 @@ // @optional

},
flags: [
{ source: '@ember/env-flags', flags: { DEBUG: true } },
{
name: 'ember-source',
source: '@ember/features',
flags: {
FEATURE_A: false,
FEATURE_B: true,
DEPRECATED_CONTROLLERS: "2.12.0"
}
}
],
// @optional
features: {
name: 'ember-source',
source: '@ember/features',
flags: { FEATURE_A: false, FEATURE_B: true, DEPRECATED_CONTROLLERS: "2.12.0" }
},
// @optional
svelte: {
'ember-source': "2.15.0"
},
// @optional

@@ -72,3 +82,3 @@ externalizeHelpers: {

```javascript
if (true) {
if (true /* DEBUG */) {
console.log('Hello from debug');

@@ -78,3 +88,3 @@ }

let woot;
if (false) {
if (false /* FEATURE_A */) {
woot = () => 'woot';

@@ -149,3 +159,5 @@ } else if (true) {

When you externalize helpers you must provide runtime implementations for the above macros. An expansion will still occur, however we will emit references to those runtime helpers.
When you externalize helpers you must provide runtime implementations for the
above macros. An expansion will still occur, however we will emit references to
those runtime helpers.

@@ -182,15 +194,21 @@ A global expansion looks like the following:

Svelte allows for consumers to opt into stripping deprecated code from your dependecies. By adding a package name and minimum version that contains no deprecations, that code will be compiled away.
Svelte allows for consumers to opt into stripping deprecated code from your
dependecies. By adding a package name and minimum version that contains no
deprecations, that code will be compiled away.
For example, consider you are on `ember-source@2.10.0` and you have no deprecations. All deprecated code in `ember-source` that is `<=2.10.0` will be removed.
For example, consider you are on `ember-source@2.10.0` and you have no
deprecations. All deprecated code in `ember-source` that is `<=2.10.0` will be
removed.
```
...
svelte: {
"ember-source": "2.10.0"
}
...
```
Now if you bump to `ember-source@2.11.0` you may encounter new deprecations. The workflow would then be to clear out all deprecations and then bump the version in the `svelte` options.
Now if you bump to `ember-source@2.11.0` you may encounter new deprecations.
The workflow would then be to clear out all deprecations and then bump the
version in the `svelte` options.

@@ -202,5 +220,1 @@ ```

```
# Hygenic
As you may notice that we inject `DEBUG` into the code when we expand the macro. We guarantee that the binding is unique when injected and follow the local binding name if it is imported directly.

@@ -8,7 +8,66 @@ 'use strict';

function macros(babel) {
let t = babel.types;
let options;
function buildIdentifier(value, name) {
let replacement = t.booleanLiteral(value);
// when we only support babel@7 we should change this
// to `path.addComment` or `t.addComment`
let comment = {
type: 'CommentBlock',
value: ` ${name} `,
leading: false,
trailing: true,
};
replacement.trailingComments = [comment];
return replacement;
}
return {
name: 'babel-feature-flags-and-debug-macros',
visitor: {
ImportSpecifier(path) {
let importPath = path.parent.source.value;
let flagsForImport = options.flags[importPath];
if (flagsForImport) {
let flagName = path.node.imported.name;
let localBindingName = path.node.local.name;
if (!(flagName in flagsForImport)) {
throw new Error(
`Imported ${flagName} from ${importPath} which is not a supported flag.`
);
}
let flagValue = flagsForImport[flagName];
if (flagValue === null) {
return;
}
let binding = path.scope.getBinding(localBindingName);
binding.referencePaths.forEach(p => {
p.replaceWith(buildIdentifier(flagValue, flagName));
});
path.remove();
path.scope.removeOwnBinding(localBindingName);
}
},
ImportDeclaration: {
exit(path) {
let importPath = path.node.source.value;
let flagsForImport = options.flags[importPath];
// remove flag source imports when no specifiers are left
if (flagsForImport && path.get('specifiers').length === 0) {
path.remove();
}
},
},
Program: {

@@ -26,3 +85,2 @@ enter(path, state) {

let debugToolsImport = options.debugTools.debugToolsImport;
let envFlagsImport = options.envFlags.envFlagsImport;

@@ -32,5 +90,2 @@ if (debugToolsImport && debugToolsImport === importPath) {

}
if (envFlagsImport && envFlagsImport === importPath) {
this.macroBuilder.collectEnvFlagSpecifiers(item.get('specifiers'));
}
}

@@ -37,0 +92,0 @@ });

@@ -9,2 +9,3 @@ 'use strict';

this.assertPredicateIndex = options.assertPredicateIndex;
this.isDebug = options.isDebug;
this.expressions = [];

@@ -174,5 +175,5 @@ }

*/
expandMacros(debugFlag) {
expandMacros() {
let t = this.t;
let flag = t.booleanLiteral(debugFlag);
let flag = t.booleanLiteral(this.isDebug);
for (let i = 0; i < this.expressions.length; i++) {

@@ -179,0 +180,0 @@ let expression = this.expressions[i];

@@ -5,3 +5,2 @@ 'use strict';

const DEBUG = 'DEBUG';
const SUPPORTED_MACROS = ['assert', 'deprecate', 'warn', 'log'];

@@ -13,12 +12,3 @@

this.localDebugBindings = [];
this.envFlagBindings = [];
this.hasEnvFlags = false;
this.envFlagsSource = options.envFlags.envFlagsImport;
this.importedDebugTools = false;
this.envFlags = options.envFlags.flags;
this.featureSources = options.featureSources;
this.featuresMap = options.featuresMap;
this.svelteMap = options.svelteMap;
this.svelteVersions = options.svelte;
this.featureFlags = options.features || [];
this.debugHelpers = options.externalizeHelpers || {};

@@ -29,2 +19,3 @@ this.builder = new Builder(babel.types, {

assertPredicateIndex: options.debugTools.assertPredicateIndex,
isDebug: options.debugTools.isDebug,
});

@@ -38,98 +29,7 @@ }

expand(path) {
let debugBinding = path.scope.getBinding(DEBUG);
this.builder.expandMacros();
this._inlineFeatureFlags(path);
this._inlineSvelteFlags(path);
this._inlineEnvFlags(path);
this.builder.expandMacros(this.envFlags.DEBUG);
if (this._hasDebugModule(debugBinding)) {
debugBinding.path.parentPath.remove();
}
this._cleanImports(path);
}
_inlineFeatureFlags(path) {
let featuresMap = this.featuresMap;
if (this.envFlags.DEBUG) {
return;
}
Object.keys(featuresMap).forEach(source => {
Object.keys(featuresMap[source]).forEach(flag => {
let flagValue = featuresMap[source][flag];
let binding = path.scope.getBinding(flag);
if (binding && flagValue !== null) {
binding.referencePaths.forEach(referencePath => {
referencePath.replaceWith(this.builder.t.booleanLiteral(flagValue));
});
if (binding.path.parentPath.isImportDeclaration()) {
binding.path.remove();
}
}
});
});
}
_inlineEnvFlags(path) {
let envFlags = this.envFlags;
Object.keys(envFlags).forEach(flag => {
let binding = path.scope.getBinding(flag);
if (
binding &&
binding.path.isImportSpecifier() &&
binding.path.parent.source.value === this.envFlagsSource
) {
binding.referencePaths.forEach(p =>
p.replaceWith(this.builder.t.booleanLiteral(envFlags[flag]))
);
}
});
}
_inlineSvelteFlags(path) {
let svelteMap = this.svelteMap;
let t = this.babel.types;
function buildIdentifier(value, name) {
let replacement = t.booleanLiteral(value);
// when we only support babel@7 we should change this
// to `path.addComment` or `t.addComment`
let comment = {
type: 'CommentBlock',
value: ` ${name} `,
leading: false,
trailing: true,
};
replacement.trailingComments = [comment];
return replacement;
}
let sources = Object.keys(svelteMap);
sources.forEach(source => {
let flagsForSource = svelteMap[source];
for (let flag in flagsForSource) {
let flagValue = flagsForSource[flag];
let binding = path.scope.getBinding(flag);
if (binding !== undefined) {
binding.referencePaths.forEach(p => {
let replacement = buildIdentifier(flagValue, flag);
p.replaceWith(replacement);
});
binding.path.remove();
}
}
});
}
/**

@@ -139,11 +39,9 @@ * Collects the import bindings for the debug tools.

collectDebugToolsSpecifiers(specifiers) {
this.importedDebugTools = true;
this._collectImportBindings(specifiers, this.localDebugBindings);
specifiers.forEach(specifier => {
if (specifier.node.imported && SUPPORTED_MACROS.indexOf(specifier.node.imported.name) > -1) {
this.localDebugBindings.push(specifier.get('local'));
}
});
}
collectEnvFlagSpecifiers(specifiers) {
this.hasEnvFlags = true;
this._collectImportBindings(specifiers, this.envFlagBindings);
}
/**

@@ -164,51 +62,3 @@ * Builds the expressions that the CallExpression will expand into.

_collectImportBindings(specifiers, buffer) {
specifiers.forEach(specifier => {
if (specifier.node.imported && SUPPORTED_MACROS.indexOf(specifier.node.imported.name) > -1) {
buffer.push(specifier.get('local'));
}
});
}
_hasDebugModule(debugBinding) {
let fromModule = debugBinding && debugBinding.kind === 'module';
let moduleName = fromModule && debugBinding.path.parent.source.value;
return moduleName === this.envFlagsSource;
}
_detectForeignFeatureFlag(specifiers, source) {
specifiers.forEach(specifier => {
if (!specifier.imported) {
return;
}
let isKnownFeature = specifier.imported.name in this.featuresMap[source];
if (!isKnownFeature) {
throw new Error(
`Imported ${specifier.imported.name} from ${source} which is not a supported flag.`
);
}
});
}
_cleanImports(path) {
let body = path.get('body');
for (let i = 0; i < body.length; i++) {
let decl = body[i];
if (this.builder.t.isImportDeclaration(decl)) {
let source = decl.node.source.value;
if (this.featureSources.indexOf(source) > -1) {
if (decl.node.specifiers.length > 0) {
this._detectForeignFeatureFlag(decl.node.specifiers, source);
} else {
decl.remove();
break;
}
}
}
}
_cleanImports() {
if (!this.debugHelpers.module) {

@@ -215,0 +65,0 @@ if (this.localDebugBindings.length > 0) {

@@ -5,82 +5,122 @@ 'use strict';

function normalizeOptions(options) {
let features = options.features || [];
let debugTools = options.debugTools;
let envFlags = options.envFlags;
let externalizeHelpers = options.externalizeHelpers;
function parseDebugTools(options) {
let debugTools = options.debugTools || {};
if (!debugTools) {
throw new Error('You must specify `debugTools.source`');
}
let isDebug = debugTools.isDebug;
let debugToolsImport = debugTools.source;
let assertPredicateIndex = debugTools.assertPredicateIndex;
if (options.envFlags && isDebug === undefined) {
isDebug = options.envFlags.flags.DEBUG;
}
if (isDebug === undefined) {
throw new Error('You must specify `debugTools.isDebug`');
}
return {
isDebug,
debugToolsImport,
assertPredicateIndex,
};
}
function evaluateFlagValue(options, name, flagName, flagValue) {
let svelte = options.svelte;
let featureSources = [];
let featuresMap = {};
let svelteMap = {};
let hasSvelteBuild = false;
if (typeof flagValue === 'string') {
if (svelte && svelte[name]) {
return gt(flagValue, svelte[name]);
} else {
return null;
}
} else if (typeof flagValue === 'boolean' || flagValue === null) {
return flagValue;
} else {
throw new Error(`Invalid value specified (${flagValue}) for ${flagName} by ${name}`);
}
}
if (!Array.isArray(features)) {
features = [features];
function parseFlags(options) {
let flagsProvided = options.flags || [];
let combinedFlags = {};
flagsProvided.forEach(flagsDefinition => {
let source = flagsDefinition.source;
let flagsForSource = (combinedFlags[source] = combinedFlags[source] || {});
for (let flagName in flagsDefinition.flags) {
let flagValue = flagsDefinition.flags[flagName];
flagsForSource[flagName] = evaluateFlagValue(
options,
flagsDefinition.name,
flagName,
flagValue
);
}
});
let legacyEnvFlags = options.envFlags;
if (legacyEnvFlags) {
let source = legacyEnvFlags.source;
combinedFlags[source] = combinedFlags[source] || {};
for (let flagName in legacyEnvFlags.flags) {
let flagValue = legacyEnvFlags.flags[flagName];
combinedFlags[source][flagName] = evaluateFlagValue(options, null, flagName, flagValue);
}
}
features = features.map(feature => {
let featuresSource = feature.source;
featureSources.push(featuresSource);
let name = feature.name;
let legacyFeatures = options.features;
if (legacyFeatures) {
if (!Array.isArray(legacyFeatures)) {
legacyFeatures = [legacyFeatures];
}
let flags = {};
featuresMap[featuresSource] = {};
svelteMap[featuresSource] = {};
legacyFeatures.forEach(flagsDefinition => {
let source = flagsDefinition.source;
let flagsForSource = (combinedFlags[source] = combinedFlags[source] || {});
Object.keys(feature.flags).forEach(flagName => {
let value = feature.flags[flagName];
for (let flagName in flagsDefinition.flags) {
let flagValue = flagsDefinition.flags[flagName];
if (svelte !== undefined && typeof value === 'string' && svelte[name]) {
hasSvelteBuild = true;
flags[flagName] = svelteMap[featuresSource][flagName] = gt(value, svelte[name]);
} else if (typeof value === 'boolean' || value === null) {
flags[flagName] = featuresMap[featuresSource][flagName] = value;
} else {
flags[flagName] = featuresMap[featuresSource][flagName] = true;
flagsForSource[flagName] = evaluateFlagValue(
options,
flagsDefinition.name,
flagName,
flagValue
);
}
});
}
return {
name,
source: feature.source,
flags,
};
});
if (!debugTools) {
throw new Error('You must specify `debugTools.source`');
if (legacyFeatures || legacyEnvFlags) {
// eslint-disable-next-line no-console
console.warn(
'babel-plugin-debug-macros configuration API has changed, please update your configuration'
);
}
let debugToolsImport = debugTools.source;
let assertPredicateIndex = debugTools.assertPredicateIndex;
return combinedFlags;
}
let envFlagsImport;
let _envFlags = {};
function normalizeOptions(options) {
let features = options.features || [];
let externalizeHelpers = options.externalizeHelpers;
let svelte = options.svelte;
if (envFlags) {
envFlagsImport = envFlags.source;
if (envFlags.flags) {
_envFlags = envFlags.flags;
}
} else {
throw new Error('You must specify envFlags.flags.DEBUG at minimum.');
if (!Array.isArray(features)) {
features = [features];
}
return {
featureSources,
externalizeHelpers,
features,
featuresMap,
svelteMap,
hasSvelteBuild,
flags: parseFlags(options),
svelte,
envFlags: {
envFlagsImport,
flags: _envFlags,
},
debugTools: {
debugToolsImport,
assertPredicateIndex,
},
debugTools: parseDebugTools(options),
};

@@ -87,0 +127,0 @@ }

@@ -5,2 +5,3 @@ 'use strict';

const fs = require('fs');
const CONSOLE = Object.assign({}, console);

@@ -12,2 +13,6 @@ function createTests(options) {

afterEach(function() {
Object.assign(console, CONSOLE);
});
describe('Feature Flags', function() {

@@ -20,14 +25,10 @@ const h = transformTestHelper({

{
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: false,
flags: [
{
source: '@ember/env-flags',
flags: {
DEBUG: false,
},
},
},
debugTools: {
source: '@ember/debug-tools',
},
features: [
{
name: 'ember-source',
source: '@ember/features',

@@ -40,2 +41,6 @@ flags: {

],
debugTools: {
isDebug: false,
source: '@ember/debug-tools',
},
},

@@ -61,11 +66,7 @@ ],

debugTools: {
isDebug: true,
source: '@ember/debug-tools',
assertPredicateIndex: 0,
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
},
},
flags: [{ source: '@ember/env-flags', flags: { DEBUG: true } }],
},

@@ -98,11 +99,7 @@ ],

debugTools: {
isDebug: true,
source: '@ember/debug-tools',
assertPredicateIndex: 0,
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
},
},
flags: [{ source: '@ember/env-flags', flags: { DEBUG: true } }],
},

@@ -162,10 +159,6 @@ ],

debugTools: {
isDebug: true,
source: '@ember/debug-tools',
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
},
},
flags: [{ source: '@ember/env-flags', flags: { DEBUG: true } }],
},

@@ -179,3 +172,7 @@ ],

describe('ember-cli-babel default configuration', function() {
describe('ember-cli-babel default configuration (legacy config API)', function() {
beforeEach(function() {
console.warn = () => {}; // eslint-disable-line
});
let h = transformTestHelper({

@@ -191,2 +188,3 @@ presets,

debugTools: {
isDebug: true,
source: '@ember/debug',

@@ -209,3 +207,3 @@ assertPredicateIndex: 1,

describe('Retain Module External Test Helpers', function() {
describe('ember-cli-babel default configuration', function() {
let h = transformTestHelper({

@@ -218,13 +216,10 @@ presets,

externalizeHelpers: {
module: true,
global: 'Ember',
},
debugTools: {
source: '@ember/debug-tools',
isDebug: true,
source: '@ember/debug',
assertPredicateIndex: 1,
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
},
},
flags: [{ source: '@glimmer/env', flags: { DEBUG: true } }],
},

@@ -235,6 +230,6 @@ ],

h.generateTest('retain-module-external-helpers');
h.generateTest('ember-cli-babel-config');
});
describe('Development Svelte Builds', function() {
describe('Retain Module External Test Helpers', function() {
let h = transformTestHelper({

@@ -246,35 +241,10 @@ presets,

{
externalizeHelpers: {
module: true,
},
debugTools: {
isDebug: true,
source: '@ember/debug-tools',
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
},
},
svelte: {
'ember-source': '2.15.0',
},
features: [
{
name: 'my-app',
source: 'my-app/features',
flags: {
FEATURE_A: false,
FEATURE_B: true,
},
},
// Note this going to have to be concated in by each lib
{
name: 'ember-source',
source: '@ember/features',
flags: {
DEPRECATED_PARTIALS: '2.14.0',
DEPRECATED_CONTROLLERS: '2.16.0',
},
},
],
flags: [{ source: '@ember/env-flags', flags: { DEBUG: true } }],
},

@@ -285,6 +255,6 @@ ],

h.generateTest('development-svelte-builds');
h.generateTest('retain-module-external-helpers');
});
describe('Production Svelte Builds', function() {
describe('Svelte Builds', function() {
let h = transformTestHelper({

@@ -297,16 +267,7 @@ presets,

debugTools: {
isDebug: true,
source: '@ember/debug-tools',
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: false,
},
},
svelte: {
'ember-source': '2.15.0',
},
features: [
flags: [
{ source: '@ember/env-flags', flags: { DEBUG: true } },
{

@@ -330,2 +291,6 @@ name: 'my-app',

],
svelte: {
'ember-source': '2.15.0',
},
},

@@ -336,3 +301,3 @@ ],

h.generateTest('production-svelte-builds');
h.generateTest('development-svelte-builds');
});

@@ -347,13 +312,7 @@

{
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
TESTING: false,
},
},
debugTools: {
isDebug: true,
source: '@ember/debug-tools',
},
features: [],
flags: [{ source: '@ember/env-flags', flags: { DEBUG: true, TESTING: false } }],
},

@@ -376,10 +335,6 @@ ],

debugTools: {
isDebug: true,
source: '@ember/debug-tools',
},
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
},
},
flags: [{ source: '@ember/env-flags', flags: { DEBUG: true } }],
},

@@ -401,19 +356,16 @@ ],

{
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: false,
},
},
debugTools: {
isDebug: false,
source: '@ember/debug-tools',
},
features: {
name: 'ember-source',
source: '@ember/features',
flags: {
FEATURE_A: true,
FEATURE_B: null,
flags: [
{ source: '@ember/env-flags', flags: { DEBUG: false } },
{
source: '@ember/features',
flags: {
FEATURE_A: true,
FEATURE_B: null,
},
},
},
],
},

@@ -434,19 +386,16 @@ ],

{
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: false,
},
},
debugTools: {
isDebug: false,
source: '@ember/debug-tools',
},
features: {
name: 'ember-source',
source: '@ember/features',
flags: {
FEATURE_A: true,
FEATURE_B: null,
flags: [
{ source: '@ember/env-flags', flags: { DEBUG: false } },
{
source: '@ember/features',
flags: {
FEATURE_A: true,
FEATURE_B: null,
},
},
},
],
},

@@ -467,19 +416,17 @@ ],

{
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: true,
flags: [
{ source: '@ember/env-flags', flags: { DEBUG: true } },
{
name: 'ember-source',
source: '@ember/features',
flags: {
FOO_BAR: false,
WIDGET_WOO: false,
},
},
},
],
debugTools: {
isDebug: true,
source: '@ember/debug-tools',
},
features: {
name: 'ember-source',
source: '@ember/features',
flags: {
FOO_BAR: false,
WIDGET_WOO: false,
},
},
},

@@ -486,0 +433,0 @@ ],

@@ -6,55 +6,120 @@ 'use strict';

describe('normalizeOptions', function() {
it('sets flag to false when svelte version matches the flag version', function() {
let originalConsole = Object.assign({}, console);
afterEach(function() {
Object.assign(console, originalConsole);
});
it('converts "old style" options into the newer style (with deprecation)', function() {
let warnings = [];
console.warn = warning => warnings.push(warning); // eslint-disable-line
let actual = normalizeOptions({
envFlags: {
source: '@ember/env-flags',
flags: {
DEBUG: false,
},
},
debugTools: {
source: 'whatever',
source: '@ember/debug-tools',
},
envFlags: {
features: {
name: 'ember-source',
source: '@ember/features',
flags: {
DEBUG: true,
FEATURE_A: true,
FEATURE_B: null,
},
},
svelte: { foo: '1.2.0' },
features: [{ name: 'foo', source: 'foo/features', flags: { ABC: '1.2.0' } }],
});
let expected = {
debugTools: { assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
envFlags: { envFlagsImport: undefined, flags: { DEBUG: true } },
debugTools: {
isDebug: false,
assertPredicateIndex: undefined,
debugToolsImport: '@ember/debug-tools',
},
flags: {
'@ember/env-flags': {
DEBUG: false,
},
'@ember/features': {
FEATURE_A: true,
FEATURE_B: null,
},
},
externalizeHelpers: undefined,
featureSources: ['foo/features'],
features: [{ flags: { ABC: false }, name: 'foo', source: 'foo/features' }],
featuresMap: { 'foo/features': {} },
hasSvelteBuild: true,
svelte: { foo: '1.2.0' },
svelteMap: { 'foo/features': { ABC: false } },
};
expect(actual).toEqual(expected);
expect(warnings).toEqual([
'babel-plugin-debug-macros configuration API has changed, please update your configuration',
]);
});
it('sets flag to false when svelte version is higher than flag version', function() {
it('sets flag to false when svelte version matches the flag version', function() {
let actual = normalizeOptions({
debugTools: {
source: 'whatever',
isDebug: true,
},
envFlags: {
flags: {
flags: [
{ name: 'ember-source', source: '@glimmer/env', flags: { DEBUG: true } },
{
name: 'ember-source',
source: '@ember/deprecated-features',
flags: { PARTIALS: '1.2.0' },
},
{
name: 'ember-source',
source: '@ember/canary-features',
flags: { TRACKED: null, GETTERS: true },
},
],
svelte: { 'ember-source': '1.2.0' },
});
let expected = {
debugTools: { isDebug: true, assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
flags: {
'@glimmer/env': {
DEBUG: true,
},
'@ember/deprecated-features': {
PARTIALS: false,
},
'@ember/canary-features': {
TRACKED: null,
GETTERS: true,
},
},
externalizeHelpers: undefined,
svelte: { 'ember-source': '1.2.0' },
};
expect(actual).toEqual(expected);
});
it('sets flag to false when svelte version is higher than flag version', function() {
let actual = normalizeOptions({
debugTools: {
source: 'whatever',
isDebug: true,
},
svelte: { foo: '1.2.0' },
features: [{ name: 'foo', source: 'foo/features', flags: { ABC: '1.1.0' } }],
flags: [
{ name: 'foo', source: 'foo/features', flags: { ABC: '1.1.0' } },
{ source: 'whatever', flags: { DEBUG: true } },
],
});
let expected = {
debugTools: { assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
envFlags: { envFlagsImport: undefined, flags: { DEBUG: true } },
debugTools: { isDebug: true, assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
flags: {
'foo/features': { ABC: false },
whatever: { DEBUG: true },
},
externalizeHelpers: undefined,
featureSources: ['foo/features'],
features: [{ flags: { ABC: false }, name: 'foo', source: 'foo/features' }],
featuresMap: { 'foo/features': {} },
hasSvelteBuild: true,
svelte: { foo: '1.2.0' },
svelteMap: { 'foo/features': { ABC: false } },
};

@@ -69,22 +134,19 @@

source: 'whatever',
isDebug: true,
},
envFlags: {
flags: {
DEBUG: true,
},
},
svelte: { foo: '1.0.0' },
features: [{ name: 'foo', source: 'foo/features', flags: { ABC: '1.1.0' } }],
flags: [
{ name: 'foo', source: 'foo/features', flags: { ABC: '1.1.0' } },
{ source: 'whatever', flags: { DEBUG: true } },
],
});
let expected = {
debugTools: { assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
envFlags: { envFlagsImport: undefined, flags: { DEBUG: true } },
debugTools: { isDebug: true, assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
flags: {
'foo/features': { ABC: true },
whatever: { DEBUG: true },
},
externalizeHelpers: undefined,
featureSources: ['foo/features'],
features: [{ flags: { ABC: true }, name: 'foo', source: 'foo/features' }],
featuresMap: { 'foo/features': {} },
hasSvelteBuild: true,
svelte: { foo: '1.0.0' },
svelteMap: { 'foo/features': { ABC: true } },
};

@@ -99,22 +161,19 @@

source: 'whatever',
isDebug: true,
},
envFlags: {
flags: {
DEBUG: true,
},
},
svelte: { foo: '1.2.0' },
features: [{ name: 'foo', source: 'foo/features', flags: { ABC: '1.1.0-beta.1' } }],
flags: [
{ name: 'foo', source: 'foo/features', flags: { ABC: '1.1.0-beta.1' } },
{ source: 'whatever', flags: { DEBUG: true } },
],
});
let expected = {
debugTools: { assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
envFlags: { envFlagsImport: undefined, flags: { DEBUG: true } },
debugTools: { isDebug: true, assertPredicateIndex: undefined, debugToolsImport: 'whatever' },
flags: {
'foo/features': { ABC: false },
whatever: { DEBUG: true },
},
externalizeHelpers: undefined,
featureSources: ['foo/features'],
features: [{ flags: { ABC: false }, name: 'foo', source: 'foo/features' }],
featuresMap: { 'foo/features': {} },
hasSvelteBuild: true,
svelte: { foo: '1.2.0' },
svelteMap: { 'foo/features': { ABC: false } },
};

@@ -121,0 +180,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc