From 10827a49cd7fd0c9037f419013005a8196850ca7 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 15 Mar 2017 14:00:14 -0400 Subject: [PATCH] Bring back strip-class-call-check. --- ember-cli-build.js | 17 +++++++++-------- index.js | 15 +++++++++++++-- lib/babel-build.js | 6 +++++- lib/stripped-build-plugins.js | 8 +++++--- lib/stripped-build.js | 3 +-- package.json | 4 ++-- yarn.lock | 12 ++++++------ 7 files changed, 41 insertions(+), 24 deletions(-) diff --git a/ember-cli-build.js b/ember-cli-build.js index 27a719217d3..c14391b37a1 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -4,7 +4,7 @@ var merge = require('broccoli-merge-trees'); var Funnel = require('broccoli-funnel'); var globals = require('./lib/globals'); var yuidoc = require('./lib/yuidoc'); -//var stripClassCallCheck = require('babel5-plugin-strip-class-callcheck'); // no babel@6 version +var StripClassCallCheck = require('babel6-plugin-strip-class-callcheck'); var path = require('path'); // allow toggling of heimdall instrumentation @@ -20,13 +20,14 @@ for (var i = 0; i < args.length; i++) { module.exports = function(defaults) { var app = new EmberAddon(defaults, { - // TODO: fix classcallcheck removal with babel@6 - // babel: { - // plugins: [ - // // while ember-data strips itself, ember does not currently - // { transformer: stripClassCallCheck, position: 'after' } - // ] - // } + minifyJS: { enabled: false }, + // use babel6 options until we are using ember-cli@2.13 + babel6: { + postTransformPlugins: [ + // while ember-data strips itself, ember does not currently + [StripClassCallCheck] + ] + } }); if (INSTRUMENT_HEIMDALL) { diff --git a/index.js b/index.js index 080c3e8959c..1faf41ea43a 100644 --- a/index.js +++ b/index.js @@ -122,8 +122,19 @@ module.exports = { return; } - this.options.babel = this.options.babel || {}; - add(this.options.babel, 'plugins', require('./lib/stripped-build-plugins')(process.env.EMBER_ENV)); + let customPlugins = require('./lib/stripped-build-plugins')(process.env.EMBER_ENV); + + var babel = this.options.babel = this.options.babel || {}; + + babel.plugins = [].concat( + babel.plugins, + customPlugins.plugins + ).filter(Boolean); + + babel.postTransformPlugins = [].concat( + babel.postTransformPlugins, + customPlugins.postTransformPlugins + ).filter(Boolean); this._hasSetupBabelOptions = true; }, diff --git a/lib/babel-build.js b/lib/babel-build.js index 9fc0f74d038..b8b0aef6fb8 100644 --- a/lib/babel-build.js +++ b/lib/babel-build.js @@ -7,6 +7,7 @@ function babelOptions(libraryName, _options) { var options = { plugins: [], + postTransformPlugins: [], sourceMaps: false, moduleRoot: libraryName, moduleIds: true, @@ -35,7 +36,10 @@ function babelOptions(libraryName, _options) { 'transform-es2015-block-scoping', 'transform-es2015-constants', ['transform-es2015-classes', { loose: true }], - ]); + ], options.postTransformPlugins).filter(Boolean); + + // this is not a "real" babel option, so we delete it + delete options.postTransformPlugins; return options; } diff --git a/lib/stripped-build-plugins.js b/lib/stripped-build-plugins.js index 3d4009f23b6..065ceaa476a 100644 --- a/lib/stripped-build-plugins.js +++ b/lib/stripped-build-plugins.js @@ -3,7 +3,7 @@ var path = require('path'); var FilterImports = require('babel-plugin-filter-imports'); var FeatureFlags = require('babel-plugin-feature-flags'); var StripHeimdall = require('babel6-plugin-strip-heimdall'); -//var stripClassCallCheck = require('babel5-plugin-strip-class-callcheck'); // no babel@6 version +var StripClassCallCheck = require('babel6-plugin-strip-class-callcheck'); function uniqueAdd(obj, key, values) { var a = obj[key] = obj[key] || []; @@ -29,12 +29,13 @@ module.exports = function(environment) { // features[feature] = false; // } // } + + var postTransformPlugins = []; var plugins = [ [ FeatureFlags, { import: { module: 'ember-data/-private/features' }, features: features }] - // { transformer: stripClassCallCheck, position: 'after' } // no babel@6 version yet ]; if (process.env.INSTRUMENT_HEIMDALL === 'false') { @@ -45,6 +46,7 @@ module.exports = function(environment) { } if (environment === 'production') { + postTransformPlugins.push([StripClassCallCheck]); uniqueAdd(filteredImports, 'ember-data/-private/debug', [ 'assert', 'assertPolymorphicType', @@ -58,5 +60,5 @@ module.exports = function(environment) { } plugins.push([FilterImports, filteredImports]); - return plugins; + return { plugins, postTransformPlugins }; }; diff --git a/lib/stripped-build.js b/lib/stripped-build.js index 3eef7603efa..d59b2677a67 100644 --- a/lib/stripped-build.js +++ b/lib/stripped-build.js @@ -6,8 +6,7 @@ var babelBuild = require('./babel-build'); var strippedBuildPlugins = require('./stripped-build-plugins'); module.exports = function(packageName, tree, environmentBuildingFor) { - var options = {}; - options.plugins = strippedBuildPlugins(environmentBuildingFor); + var options = strippedBuildPlugins(environmentBuildingFor); return babelBuild(packageName, tree, options); }; diff --git a/package.json b/package.json index ad98950eb4c..dc49d114311 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,13 @@ "amd-name-resolver": "0.0.5", "babel-plugin-feature-flags": "^0.3.1", "babel-plugin-filter-imports": "^0.3.1", - "babel5-plugin-strip-class-callcheck": "^5.1.0", + "babel6-plugin-strip-class-callcheck": "^6.0.0", "babel6-plugin-strip-heimdall": "^6.0.1", "broccoli-babel-transpiler": "^6.0.0", "broccoli-file-creator": "^1.0.0", "broccoli-merge-trees": "^1.0.0", "chalk": "^1.1.1", - "ember-cli-babel": "^6.0.0-beta.3", + "ember-cli-babel": "^6.0.0-beta.5", "ember-cli-path-utils": "^1.0.0", "ember-cli-string-utils": "^1.0.0", "ember-cli-test-info": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index dc8dae9e1ab..65b71eac11c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -922,9 +922,9 @@ babel-types@^6.19.0, babel-types@^6.22.0, babel-types@^6.23.0: lodash "^4.2.0" to-fast-properties "^1.0.1" -babel5-plugin-strip-class-callcheck@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/babel5-plugin-strip-class-callcheck/-/babel5-plugin-strip-class-callcheck-5.1.0.tgz#77d4a40c8614d367b8a21a53908159806dba5f91" +babel6-plugin-strip-class-callcheck@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/babel6-plugin-strip-class-callcheck/-/babel6-plugin-strip-class-callcheck-6.0.0.tgz#de841c1abebbd39f78de0affb2c9a52ee228fddf" babel6-plugin-strip-heimdall@^6.0.1: version "6.0.1" @@ -2160,9 +2160,9 @@ ember-cli-babel@^5.0.0, ember-cli-babel@^5.1.10, ember-cli-babel@^5.1.3, ember-c ember-cli-version-checker "^1.0.2" resolve "^1.1.2" -ember-cli-babel@^6.0.0-beta.3: - version "6.0.0-beta.4" - resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.0.0-beta.4.tgz#28895e8afb60df22e23de6b29d2372da25d8ecc5" +ember-cli-babel@^6.0.0-beta.5: + version "6.0.0-beta.5" + resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.0.0-beta.5.tgz#7d67c7907592450768afbe5943f7d81fdb4a322f" dependencies: amd-name-resolver "0.0.6" babel-plugin-transform-es2015-modules-amd "^6.24.0"