Skip to content

Commit

Permalink
Merge pull request #503 from NullVoxPopuli/support-non-explicit-babel…
Browse files Browse the repository at this point in the history
…-config-for-static-fields

Support static class blocks when _not_ using an explicit babel config file.
  • Loading branch information
ef4 authored Oct 10, 2023
2 parents c9bef8f + 0ddf280 commit 3e93b7b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
23 changes: 23 additions & 0 deletions lib/babel-options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions node-tests/get-babel-options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand All @@ -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"
);
Expand Down

0 comments on commit 3e93b7b

Please sign in to comment.