Git Product home page Git Product logo

babel-plugin-debug-macros's Introduction

ember-cli

Latest npm release GitHub Actions CI Test Coverage Code Climate

The Ember.js command line utility.

Features

  • Asset build pipeline using Broccoli.js
  • ES6 transpilation using Babel
  • Project structure conventions using ES6 module syntax
  • Development server including live-reload and API proxy
  • File/Project generator using blueprints
  • Unit, Integration and Acceptance test support using Testem
  • Powerful addon system for extensibility

Installation

npm install -g ember-cli

Usage

After installation the ember CLI tool will be available to you. It is the entrypoint for all the functionality mentioned above.

You can call ember <command> --help to find out more about all of the following commands or visit https://cli.emberjs.com/release/ to read the in-depth documentation.

Documentation

Please refer to the CLI guides for help using Ember CLI.

Contributing

Please see the contributing guidelines

Community

License

This project is licensed under the MIT License.

babel-plugin-debug-macros's People

Contributors

chadhietala avatar dmuneras avatar ef4 avatar elwayman02 avatar hjdivad avatar jrjohnson avatar krisselden avatar martony38 avatar mixonic avatar pzuraq avatar rwjblue avatar stefanpenner avatar t-sauer avatar turbo87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-plugin-debug-macros's Issues

Running ember-server, seeing an error

Started getting this error recently on my project, just when running ember s though others don't get it. Any ideas?

The Broccoli Plugin: [Funnel] failed with:
Error: ember-data/-debug/index.js: You must specify envFlags.flags.DEBUG at minimum.
  at normalizeOptions (<redacted>/node_modules/babel-plugin-debug-macros/dist/lib/utils/normalize-options.js:74:11)
  at PluginPass.enter (<redacted>/node_modules/babel-plugin-debug-macros/dist/index.js:33:60)

Emits deprecations for `window.Ember` usage after transpilation

Ember 3.27+ emits a deprecation when accessing window.Ember. At the moment, our transpilation output emits:

(true && Ember.warn('This is a warning'));
(true && !(foo) && Ember.assert('Hahahaha', foo));
(true && !(false) && Ember.assert('without predicate'));
(true && !(true) && Ember.deprecate('This thing is donzo', true, {

Instead, we should use the import that the original code used.

Replaces provided envFlags even if not imported.

Given the following config:

    [debugMacros, {
      envFlags: {
        source: '@glimmer/env-flags',
        flags: envFlags
      },
      debugTools: {
        source: '@glimmer/debug'
      },
      externalizeHelpers: {
        module: true
      }
    }],

And the following module contents (note no imports):

var DEBUG = 'hahaha';

if (DEBUG === 'hahaha') {
  // do things
}

The DEBUG assignment is removed, and the usage is changed to boolean:

if (false === 'hahaha') {
  // do things
}

Break This Up Into 3 Plugins

This is getting pretty unwieldy. Should be broken up into the following:

['debug-macros', {
   debug: boolean,
   source: string,
   externalizeHelpers: { module: true, global: string }
],
['feature-flags', { debug: boolean, flags: Object, source: string }]
['svelte', { flags: Object, debug: boolean, source: string }]

Likely need to check if there are other options that each plugin needs.

_createMacroExpression closes over code that other transforms may edit.

Take for instance the following

assert(`my assertion`, SOME_VAR);

This library will close over SOME_VAR when building out the transformation _createMacroExpression. Since the built transformations are not flushed until program exit, other transforms that edit or replace SOME_VAR will have no affect.

Investigate Svelte

Investigate creating a contract for consumers to explicitly strip deprecations within a specific semver range.

Strip import statement if all imports are removed.

Currently, given:

import { SOME_FLAG } from 'blah/features';

if (SOME_FLAG) {
  console.log('whatever');
}

With this config:

{
  plugins: [
    ['babel-debug-macros', {
      features: {
        name: 'blah',
        source: 'blah/features',
        flags: { SOME_FLAG: true }
      },
    }]
  ]
}

We remove the usage of SOME_FLAG, but leave the import statement. This forces us to also emit a blah/features module even if we never have runtime enableable features.

IMO, we should remove imports if they are no longer used...

Wrong transpilation when optional chaining is used in `assert()`

I have this code:

assert('Need profile data', this.args.window.profile?.data);

When optional chaining is not transpiled, things work fine. The line above is transformed to:

(true && !(this.args.window.profile?.data) && (0, _debug.assert)('Need profile data', this.args.window.profile?.data));

However some automated dependency updates including most Babel stuff changed behavior, in that optional chaining is now transpiled, I believe due to some bug in Chrome, see babel/babel#13145.

But now the transform yields this broken code:

var _this$args$window$pro;

(true && !(_this$args$window$pro.data) && (0, _debug.assert)('Need profile data', (_this$args$window$pro = this.args.window.profile) === null || _this$args$window$pro === void 0 ? void 0 : _this$args$window$pro.data));

Which throws with Cannot read properties of undefined (reading 'data') as at the time the !(_this$args$window$pro.data) expression is evaluated _this$args$window$pro is still undefined!

Handle `CallExpression` for debug macros.

Currently, we are handling only ExpressionStatement's for debug macro replacement. Unfortunately, the following do not get processed (since they do not include an ExpressionStatement):

function foo() {
  return assert(false, 'derp'); // ReturnStatement
}

let qux = () => assert(false, 'herp'); // ArrowFunctionExpression

This is the underlying issue in emberjs/ember-cli-babel#168.

Modify `deprecate` debug helper to handle single arg.

This should not throw (though Ember will issue a deprecation for not passing the options hash):

import { deprecate } from '@ember/debug';

deprecate('some message');

Currently the following (lovely) error is thrown:

TypeError: -private/system/store.js: Property expression of ParenthesizedExpression expected node to be of a type ["Expression"] but instead got null
    at Object.validate (/Users/rjackson/src/open-source/ember-data/node_modules/babel-types/lib/definitions/index.js:109:13)
    at validate (/Users/rjackson/src/open-source/ember-data/node_modules/babel-types/lib/index.js:505:9)
    at Object.builder (/Users/rjackson/src/open-source/ember-data/node_modules/babel-types/lib/index.js:466:7)
    at Builder.deprecate (/Users/rjackson/src/open-source/ember-data/node_modules/babel-plugin-debug-macros/dist/lib/utils/builder.js:187:92)
    at Macros.build (/Users/rjackson/src/open-source/ember-data/node_modules/babel-plugin-debug-macros/dist/lib/utils/macros.js:189:36)
    at PluginPass.ExpressionStatement (/Users/rjackson/src/open-source/ember-data/node_modules/babel-plugin-debug-macros/dist/index.js:67:27)
    at newFn (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/rjackson/src/open-source/ember-data/node_modules/babel-traverse/lib/path/context.js:105:12)

Modify `assert` output to avoid string allocations when no assertions.

We should basically do the same as we do for deprecate in this regard.

Today, this input:

import { deprecate, assert } from 'whatever';

deprecate('foo bar', somePredicate, { ... });
assert(somePredicate, 'message here');

Transpiles to:

(true && !(somePredicate) && console.warn('foo bar'));
(true && console.assert(somePredicate, 'message here'));

Note that the deprecate version avoids allocating the string if the predicate is truthy, but the assert version does not.

We currently have 4 or 5 assertions for every get / set (for example), and it would be nice to make assert a bit less expensive in debug builds of Ember...

Investigate DCE

Investigate if we can DCE early with path.execute in Babel.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.