diff --git a/lib/babel-options-util.js b/lib/babel-options-util.js index 320b55af..ee26306b 100644 --- a/lib/babel-options-util.js +++ b/lib/babel-options-util.js @@ -311,6 +311,29 @@ function _buildClassFeaturePluginConstraints(constraints, config, parent, projec function _addDecoratorPlugins(plugins, options, config, parent, project) { const { hasPlugin, addPlugin } = require("ember-cli-babel-plugin-helpers"); + if (hasPlugin(plugins, "@babel/plugin-transform-class-static-block")) { + if (parent === project) { + project.ui.writeWarnLine( + `${_parentName( + parent + )} has added the static class block plugin to its build, but ember-cli-babel provides these by default now! You can remove the transforms, or the addon that provided them.` + ); + } + } else { + addPlugin( + plugins, + [require.resolve("@babel/plugin-transform-class-static-block"), { legacy: true }], + _buildClassFeaturePluginConstraints( + { + before: ["@babel/plugin-proposal-decorators"], + }, + config, + parent, + project + ) + ); + } + if (hasPlugin(plugins, "@babel/plugin-proposal-decorators")) { if (parent === project) { project.ui.writeWarnLine( diff --git a/node-tests/get-babel-options-test.js b/node-tests/get-babel-options-test.js index c4ed96a7..4dfeac70 100644 --- a/node-tests/get-babel-options-test.js +++ b/node-tests/get-babel-options-test.js @@ -71,7 +71,7 @@ describe("get-babel-options", function () { expect( _addDecoratorPlugins([], {}, {}, this.addon.parent, this.addon.project) .length - ).to.equal(4, "plugins added correctly"); + ).to.equal(5, "plugins added correctly"); }); it("should include only fields if it detects decorators plugin", function () { @@ -91,7 +91,7 @@ describe("get-babel-options", function () { this.addon.parent, this.addon.project ).length - ).to.equal(4, "plugins were not added"); + ).to.equal(5, "plugins were not added"); }); it("should include only decorators if it detects class fields plugin", function () { @@ -111,7 +111,7 @@ describe("get-babel-options", function () { this.addon.parent, this.addon.project ).length - ).to.equal(2, "plugins were not added"); + ).to.equal(3, "plugins were not added"); }); it("should use babel options loose mode for class properties", function () { @@ -157,7 +157,7 @@ describe("get-babel-options", function () { "@babel/plugin-transform-typescript", "typescript still first" ); - expect(plugins.length).to.equal(5, "class fields and decorators added"); + expect(plugins.length).to.equal(6, "class fields and decorators added"); }); it("should include class fields and decorators before typescript if not handling typescript", function () { @@ -172,8 +172,8 @@ describe("get-babel-options", function () { this.addon.project ); - expect(plugins.length).to.equal(5, "class fields and decorators added"); - expect(plugins[4]).to.equal( + expect(plugins.length).to.equal(6, "class fields and decorators added"); + expect(plugins[5]).to.equal( "@babel/plugin-transform-typescript", "typescript is now last" );