Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support static class blocks when _not_ using an explicit babel config file. #503

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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