Skip to content

Commit

Permalink
Merge pull request #19047 from arthirm/master
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Jul 20, 2020
2 parents a281134 + 805732f commit ac5be39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const resolve = require('resolve');
const concatBundle = require('./concat-bundle');
const buildDebugMacroPlugin = require('./build-debug-macro-plugin');
const buildStripClassCallcheckPlugin = require('./build-strip-class-callcheck-plugin');
const injectBabelHelpers = require('./transforms/inject-babel-helpers');
const injectBabelHelpers = require('./transforms/inject-babel-helpers').injectBabelHelpers;
const debugTree = require('broccoli-debug').buildDebugCallback('ember-source:addon');

const PRE_BUILT_TARGETS = [
Expand Down Expand Up @@ -138,6 +138,7 @@ module.exports = {
// 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 babelHelperPlugin = injectBabelHelpers(isEmberSource);

let options = {
'ember-cli-babel': {
Expand All @@ -147,7 +148,7 @@ module.exports = {
babel: Object.assign({}, babelOptions, {
loose: true,
plugins: [
injectBabelHelpers(isEmberSource),
babelHelperPlugin,
buildDebugMacroPlugin(!isProduction),
[
require.resolve('@babel/plugin-transform-block-scoping'),
Expand Down
50 changes: 30 additions & 20 deletions lib/transforms/inject-babel-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,39 @@
const { addNamed } = require('@babel/helper-module-imports');

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');
});
},
};
}
let helperplugin = injectBabelHelpersPlugin;
helperplugin._parallelBabel = {
requireFile: __filename,
buildUsing: 'injectBabelHelpersPlugin',
params: { isEmberSource },
};

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

return injectBabelHelpersPlugin;
return helperplugin;
}

function injectBabelHelpersPlugin(isEmberSource) {
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');
});
},
};
}

module.exports = injectBabelHelpers;
module.exports = {
injectBabelHelpers,
injectBabelHelpersPlugin,
};

0 comments on commit ac5be39

Please sign in to comment.