Skip to content

Commit 3e93b7b

Browse files
authored
Merge pull request #503 from NullVoxPopuli/support-non-explicit-babel-config-for-static-fields
Support static class blocks when _not_ using an explicit babel config file.
2 parents c9bef8f + 0ddf280 commit 3e93b7b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/babel-options-util.js

+23
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ function _buildClassFeaturePluginConstraints(constraints, config, parent, projec
311311
function _addDecoratorPlugins(plugins, options, config, parent, project) {
312312
const { hasPlugin, addPlugin } = require("ember-cli-babel-plugin-helpers");
313313

314+
if (hasPlugin(plugins, "@babel/plugin-transform-class-static-block")) {
315+
if (parent === project) {
316+
project.ui.writeWarnLine(
317+
`${_parentName(
318+
parent
319+
)} 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.`
320+
);
321+
}
322+
} else {
323+
addPlugin(
324+
plugins,
325+
[require.resolve("@babel/plugin-transform-class-static-block"), { legacy: true }],
326+
_buildClassFeaturePluginConstraints(
327+
{
328+
before: ["@babel/plugin-proposal-decorators"],
329+
},
330+
config,
331+
parent,
332+
project
333+
)
334+
);
335+
}
336+
314337
if (hasPlugin(plugins, "@babel/plugin-proposal-decorators")) {
315338
if (parent === project) {
316339
project.ui.writeWarnLine(

node-tests/get-babel-options-test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe("get-babel-options", function () {
7171
expect(
7272
_addDecoratorPlugins([], {}, {}, this.addon.parent, this.addon.project)
7373
.length
74-
).to.equal(4, "plugins added correctly");
74+
).to.equal(5, "plugins added correctly");
7575
});
7676

7777
it("should include only fields if it detects decorators plugin", function () {
@@ -91,7 +91,7 @@ describe("get-babel-options", function () {
9191
this.addon.parent,
9292
this.addon.project
9393
).length
94-
).to.equal(4, "plugins were not added");
94+
).to.equal(5, "plugins were not added");
9595
});
9696

9797
it("should include only decorators if it detects class fields plugin", function () {
@@ -111,7 +111,7 @@ describe("get-babel-options", function () {
111111
this.addon.parent,
112112
this.addon.project
113113
).length
114-
).to.equal(2, "plugins were not added");
114+
).to.equal(3, "plugins were not added");
115115
});
116116

117117
it("should use babel options loose mode for class properties", function () {
@@ -157,7 +157,7 @@ describe("get-babel-options", function () {
157157
"@babel/plugin-transform-typescript",
158158
"typescript still first"
159159
);
160-
expect(plugins.length).to.equal(5, "class fields and decorators added");
160+
expect(plugins.length).to.equal(6, "class fields and decorators added");
161161
});
162162

163163
it("should include class fields and decorators before typescript if not handling typescript", function () {
@@ -172,8 +172,8 @@ describe("get-babel-options", function () {
172172
this.addon.project
173173
);
174174

175-
expect(plugins.length).to.equal(5, "class fields and decorators added");
176-
expect(plugins[4]).to.equal(
175+
expect(plugins.length).to.equal(6, "class fields and decorators added");
176+
expect(plugins[5]).to.equal(
177177
"@babel/plugin-transform-typescript",
178178
"typescript is now last"
179179
);

0 commit comments

Comments
 (0)