Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember.warn transpilation error #184

Closed
simonihmig opened this issue Oct 19, 2017 · 2 comments
Closed

Ember.warn transpilation error #184

simonihmig opened this issue Oct 19, 2017 · 2 comments

Comments

@simonihmig
Copy link
Contributor

When Ember.warn is imported with the new module API, something weird happens during transpilation. Not sure if it's related to some babel plugin, and if so which, so created the issue here for now...

Here is a reproduction repo: https://github.com/simonihmig/ember-warn-transpilation.
It contains two examples of Ember.warn usage, one with the new imports, and one (warn2) with globals: https://github.com/simonihmig/ember-warn-transpilation/tree/master/app/utils

These files transpile as follows:

define('ember-warn-transpilation/utils/warn', ['exports'], function (exports) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = warn;
  function warn() {
    (true && Ember.emberWarn(...arguments));
  }
});
define('ember-warn-transpilation/utils/warn2', ['exports'], function (exports) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = warn2;
  var emberWarn = Ember.warn;
  function warn2() {
    emberWarn.apply(undefined, arguments);
  }
});

The interesting part is this: (true && Ember.emberWarn(...arguments));:

  • The spread operator is not transpiled
  • Ember.emberWarn is not a thing
  • true && ???

Because of the spread usage, the whole app breaks with a syntax error in older browsers (IE11).
The globals based module transpiles correctly though...

@pzuraq
Copy link
Collaborator

pzuraq commented Oct 19, 2017

Under the hood, the new debug macros are being transformed by this babel plugin: https://github.com/chadhietala/babel-plugin-debug-macros

The plugin strips all of the debug helpers at build time in production builds, so its behavior is different than other modules which are compiled. Based on this, and a quick glance at the tests for that transform, I'm not sure it took renaming imports into account. It is also probably breaking transpilation of spread. To be fair, chances are wrapper functions like the ones in the linked issue aren't necessary, so I wouldn't say this is a super high priority bug, but it should probably be fixed at some point

@simonihmig
Copy link
Contributor Author

@pzuraq thanks for pointing out that babel plugin. I was thinking it had to do with debug stripping, but was not aware of the actual plugin...

Seems this is actually a duplicate of ember-cli/babel-plugin-debug-macros#47, so closing this here now!

I'm not sure it took renaming imports into account

Does not happen only with renamed imports, see the linked issue above!

siva-sundar pushed a commit to siva-sundar/ember-cli-babel that referenced this issue Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants