Skip to content

Commit

Permalink
ensure async helpers are inlined in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Aug 21, 2019
1 parent c74c82b commit 4bf158f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ module.exports = {
let appOptions = this.app && this.app.options;
let babelOptions = (parentOptions || appOptions || {}).babel;

// We want to enable async/generator helpers if we are developing locally,
// but not for any other project.
let isEmberSource = this.project.name() === 'ember-source';

let options = {
'ember-cli-babel': {
disableDebugTooling: true,
Expand All @@ -80,7 +84,7 @@ module.exports = {
babel: Object.assign({}, babelOptions, {
loose: true,
plugins: [
injectBabelHelpers,
injectBabelHelpers(isEmberSource),
buildDebugMacroPlugin(!isProduction),
[
require.resolve('@babel/plugin-transform-block-scoping'),
Expand Down
37 changes: 23 additions & 14 deletions lib/transforms/inject-babel-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

const { addNamed } = require('@babel/helper-module-imports');

function injectBabelHelpers() {
return {
pre(file) {
file.set('helperGenerator', function(name) {
if (name === 'extends') {
return addNamed(file.path, 'assign', '@ember/polyfills');
}
return addNamed(file.path, name, 'ember-babel');
});
},
function injectBabelHelpers(isEmberSource = false) {
function injectBabelHelpersPlugin() {
return {
pre(file) {
file.set('helperGenerator', function(name) {
if (name === 'extends') {
return addNamed(file.path, 'assign', '@ember/polyfills');
} else if (isEmberSource && name === 'asyncToGenerator') {
// Returning a falsy value will cause the helper to be inlined,
// which is fine for local tests
return false;
}

return addNamed(file.path, name, 'ember-babel');
});
},
};
}

injectBabelHelpersPlugin.baseDir = function() {
return 'babel-core';
};
}

injectBabelHelpers.baseDir = function() {
return 'babel-core';
};
return injectBabelHelpersPlugin;
}

module.exports = injectBabelHelpers;

0 comments on commit 4bf158f

Please sign in to comment.