Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

babel-plugin-debug-macros

ember-cli1.6mMIT1.0.2TypeScript support: included

Debug macros and feature flag stripping

babel, plugin

readme

Babel Debug Macros And Feature Flags

This provides debug macros and feature flagging.

Setup

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.

{
  plugins: [
    ['babel-plugin-debug-macros', {
      // @optional
      debugTools: {
        isDebug: true,
        source: 'debug-tools',
        // @optional
        assertPredicateIndex: 0
      },

      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
      svelte: {
        'ember-source': "2.15.0"
      },

      // @optional
      externalizeHelpers: {
        module: true,
        // global: '__my_global_ns__'
      }
    }]
  ]
}

Flags and features are inlined into the consuming module so that something like UglifyJS will DCE them when they are unreachable.

Simple environment and feature flags

import { DEBUG } from '@ember/env-flags';
import { FEATURE_A, FEATURE_B } from '@ember/features';

if (DEBUG) {
  console.log('Hello from debug');
}

let woot;
if (FEATURE_A) {
  woot = () => 'woot';
} else if (FEATURE_B) {
  woot = () => 'toow';
}

woot();

Transforms to:

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

let woot;
if (false /* FEATURE_A */) {
  woot = () => 'woot';
} else if (true) {
  woot = () => 'toow';
}

woot();

warn macro expansion

import { warn } from 'debug-tools';

warn('this is a warning');

Expands into:

(true && console.warn('this is a warning'));

assert macro expansion

The assert macro can expand in a more intelligent way with the correct configuration. When babel-plugin-debug-macros is provided with the assertPredicateIndex the predicate is injected in front of the assertion in order to avoid costly assertion message generation when not needed.

import { assert } from 'debug-tools';

assert((() => {
  return 1 === 1;
})(), 'You bad!');

With the debugTools: { assertPredicateIndex: 0 } configuration the following expansion is done:

(true && !((() => { return 1 === 1;})()) && console.assert(false, 'this is a warning'));

When assertPredicateIndex is not specified, the following expansion is done:

(true && console.assert((() => { return 1 === 1;})(), 'this is a warning'));

deprecate macro expansion

import { deprecate } from 'debug-tools';

let foo = 2;

deprecate('This is deprecated.', foo % 2);

Expands into:

let foo = 2;

(true && !(foo % 2) && console.warn('This is deprecated.'));

Externalized 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.

A global expansion looks like the following:

import { warn } from 'debug-tools';

warn('this is a warning');

Expands into:

(true && Ember.warn('this is a warning'));

While externalizing the helpers to a module looks like the following:

import { warn } from 'debug-tools';

warn('this is a warning');

Expands into:

(true && warn('this is a warning'));

Svelte

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.0and you have no deprecations. All deprecated code inember-sourcethat is<=2.10.0` will be removed.


svelte: {
  "ember-source": "2.10.0"
}

Now if you bump to `ember-source@2.11.0you may encounter new deprecations. The workflow would then be to clear out all deprecations and then bump the version in thesvelte` options.

svelte: {
  "ember-source": "2.11.0"
}

changelog

Changelog

Release (2024-07-11)

babel-plugin-debug-macros 1.0.2 (patch)

:house: Internal

Committers: 1

Release (2024-07-11)

babel-plugin-debug-macros 1.0.1 (patch)

:memo: Documentation

  • babel-plugin-debug-macros

:house: Internal

  • babel-plugin-debug-macros

Committers: 2

v1.0.0 (2024-04-27)

:boom: Breaking Change

  • #94 Drop deprecated config format (@ef4)
  • #91 Drop support Node < 16 and babel < 7 (@ef4)

:rocket: Enhancement

  • #96 Add a mode that converts to @embroider/macros (@ef4)
  • #95 Don't expose typescript's esm/cjs interop from the entrypoint (@ef4)

:house: Internal

Committers: 2

v1.0.0-alpha.2 (2024-04-17)

:rocket: Enhancement

  • #96 Add a mode that converts to @embroider/macros (@ef4)

Committers: 1

  • Edward Faulkner (@ef4)

v1.0.0-alpha.1 (2024-04-11)

:bug: Bug Fix

  • #95 Don't expose typescript's esm/cjs interop from the entrypoint (@ef4)

Committers: 1

  • Edward Faulkner (@ef4)

v1.0.0-alpha.0 (2024-04-11)

:boom: Breaking Change

  • #94 Drop deprecated config format (@ef4)
  • #91 Drop support Node < 16 and babel < 7 (@ef4)

:house: Internal

Committers: 2

v0.3.4 (2021-01-27)

:rocket: Enhancement

  • #83 Remove validation check for deprecation until (@pzuraq)

:bug: Bug Fix

:house: Internal

Committers: 3

v0.3.3 (2019-08-26)

:bug: Bug Fix

  • #80 Fix bug when key attribute is a literal for debug macros (deprecate, assert, warn) (@martony38)

Committers: 1

Changelog

v0.3.2 (2019-06-20)

:bug: Bug Fix

  • #79 [BUGFIX] if our ancestor import declaration is removed short-circuit … (@stefanpenner)

Committers: 1

v0.3.1 (2019-04-11)

:rocket: Enhancement

Committers: 1

v0.3.0 (2019-01-29)

:boom: Breaking Change

:rocket: Enhancement

:memo: Documentation

Committers: 2

v0.2.0 (2018-10-03)

:bug: Bug Fix

Committers: 2

v0.2.0-beta.6 (2018-05-23)

:boom: Breaking Change

Committers: 1

v0.2.0-beta.5 (2018-05-22)

:bug: Bug Fix

  • #66 Fix same version matching for svelte flags. (@rwjblue)

Committers: 1

v0.2.0-beta.4 (2018-05-22)

:bug: Bug Fix

Committers: 1

v0.2.0-beta.3 (2018-05-22)

:rocket: Enhancement

  • #64 Remove error throwing for svelte guarded features. (@rwjblue)

:bug: Bug Fix

  • #63 Cleanup / fix some svelte related functionality. (@rwjblue)
  • #62 Fix for beta versions with svelte. (@rwjblue)

:house: Internal

Committers: 1

v0.2.0-beta.2 (2018-04-19)

:bug: Bug Fix

  • #60 Ensure Plugin.baseDir() functions properly. (@rwjblue)

:house: Internal

  • #59 Remove extra nesting in directory structure. (@rwjblue)

Committers: 1

v0.2.0-beta.1 (2018-04-19)

:rocket: Enhancement

:house: Internal

Committers: 3