From ac8c8c5f0e65fd99330b0316d73c17b17d52cb1c Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:53:58 -0400 Subject: [PATCH 1/4] Support adding static class blocks plugin when no babel config is present --- lib/babel-options-util.js | 23 +++++++++++++++++++++++ node-tests/get-babel-options-test.js | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/babel-options-util.js b/lib/babel-options-util.js index 320b55af..5bfefcfd 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, such as @ember-decorators/babel-transforms. Ember supports the stage 1 decorator spec and transforms, so if you were using stage 2, you'll need to ensure that your decorators are compatible, or convert them to stage 1.` + ); + } + } 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..8b333dff 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 () { From 13dfa538b3cd52ef5d2cb4f171a2b3f3b524e60e Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:54:19 -0400 Subject: [PATCH 2/4] Update test --- node-tests/get-babel-options-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node-tests/get-babel-options-test.js b/node-tests/get-babel-options-test.js index 8b333dff..6cd9be1c 100644 --- a/node-tests/get-babel-options-test.js +++ b/node-tests/get-babel-options-test.js @@ -172,7 +172,7 @@ describe("get-babel-options", function () { this.addon.project ); - expect(plugins.length).to.equal(5, "class fields and decorators added"); + expect(plugins.length).to.equal(6, "class fields and decorators added"); expect(plugins[4]).to.equal( "@babel/plugin-transform-typescript", "typescript is now last" From 7f18a2d0b2b40a430661c5b7c33f0300e1ea755b Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:55:03 -0400 Subject: [PATCH 3/4] update test --- node-tests/get-babel-options-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node-tests/get-babel-options-test.js b/node-tests/get-babel-options-test.js index 6cd9be1c..4dfeac70 100644 --- a/node-tests/get-babel-options-test.js +++ b/node-tests/get-babel-options-test.js @@ -173,7 +173,7 @@ describe("get-babel-options", function () { ); expect(plugins.length).to.equal(6, "class fields and decorators added"); - expect(plugins[4]).to.equal( + expect(plugins[5]).to.equal( "@babel/plugin-transform-typescript", "typescript is now last" ); From 0ddf28033e77dcafa3bc5f77ad3dce20ed09cb83 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:24:01 -0400 Subject: [PATCH 4/4] Remove extraneous copypasta message --- lib/babel-options-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/babel-options-util.js b/lib/babel-options-util.js index 5bfefcfd..ee26306b 100644 --- a/lib/babel-options-util.js +++ b/lib/babel-options-util.js @@ -316,7 +316,7 @@ function _addDecoratorPlugins(plugins, options, config, 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, such as @ember-decorators/babel-transforms. Ember supports the stage 1 decorator spec and transforms, so if you were using stage 2, you'll need to ensure that your decorators are compatible, or convert them to stage 1.` + )} 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 {