From 4e523f5ccdfafba08fd838126e628a0623d0ad81 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 1 Jun 2017 10:00:00 -0400 Subject: [PATCH] Provide annotation to broccoli-babel-transpiler. --- index.js | 13 +++++++++++-- node-tests/addon-test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b571a68b..80ded340 100644 --- a/index.js +++ b/index.js @@ -121,7 +121,7 @@ module.exports = { return (this.parent && this.parent.options) || (this.app && this.app.options) || {}; }, - _getAddonProvidedConfig: function(addonOptions) { + _parentName() { let parentName; if (this.parent) { @@ -132,6 +132,10 @@ module.exports = { } } + return parentName; + }, + + _getAddonProvidedConfig(addonOptions) { let babelOptions = clone(addonOptions.babel || {}); // used only to support using ember-cli-babel@6 at the @@ -170,7 +174,12 @@ module.exports = { let addonProvidedConfig = this._getAddonProvidedConfig(config); let shouldCompileModules = this._shouldCompileModules(config); - let options = {}; + let providedAnnotation = config['ember-cli-babel'] && config['ember-cli-babel'].annotation; + + let options = { + annotation: providedAnnotation || `Babel: ${this._parentName()}` + }; + let userPlugins = addonProvidedConfig.plugins; let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins; diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index eff7f1b1..ba42f833 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -505,6 +505,33 @@ describe('ember-cli-babel', function() { expect(result.babelrc).to.be.false; }); + it('provides an annotation including parent name - addon', function() { + this.addon.parent = { + name: 'derpy-herpy' + }; + let result = this.addon.buildBabelOptions(); + expect(result.annotation).to.include('derpy-herpy'); + }); + + it('provides an annotation including parent name - project', function() { + this.addon.parent = { + name() { return 'derpy-herpy'; } + }; + let result = this.addon.buildBabelOptions(); + expect(result.annotation).to.include('derpy-herpy'); + }); + + it('uses provided annotation if specified', function() { + let options = { + 'ember-cli-babel': { + annotation: 'Hello World!' + } + }; + + let result = this.addon.buildBabelOptions(options); + expect(result.annotation).to.equal('Hello World!'); + }); + it('does not include all provided options', function() { let babelOptions = { blah: true }; let options = {