Skip to content

Commit

Permalink
Attempt to solve it. (Not yet!)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed Dec 16, 2021
1 parent 702370c commit 34b3caa
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
66 changes: 48 additions & 18 deletions lib/babel-options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function _getPresetEnv(config, project) {
}

function _getModulesPlugin() {
const resolvePath = require("./relative-module-paths")
.resolveRelativeModulePath;
const resolvePath =
require("./relative-module-paths").resolveRelativeModulePath;

return [
[require.resolve("babel-plugin-module-resolver"), { resolvePath }],
Expand Down Expand Up @@ -296,7 +296,12 @@ function _getHelperVersion(project) {
return APP_BABEL_RUNTIME_VERSION.get(project);
}

function _buildClassFeaturePluginConstraints(constraints, config, parent, project) {
function _buildClassFeaturePluginConstraints(
constraints,
config,
parent,
project
) {
// With versions of ember-cli-typescript < 4.0, class feature plugins like
// @babel/plugin-proposal-class-properties were run before the TS transform.
if (!_shouldHandleTypeScript(config, parent, project)) {
Expand Down Expand Up @@ -342,21 +347,7 @@ function _addDecoratorPlugins(plugins, options, config, parent, project) {
);
}
} else {
addPlugin(
plugins,
[
require.resolve("@babel/plugin-proposal-class-properties"),
{ loose: options.loose || false },
],
_buildClassFeaturePluginConstraints(
{
after: ["@babel/plugin-proposal-decorators"],
},
config,
parent,
project
)
);
_addClassProperties(addPlugin, plugins, config, parent, project);
}

if (hasPlugin(plugins, "babel-plugin-filter-imports")) {
Expand All @@ -379,6 +370,45 @@ function _addDecoratorPlugins(plugins, options, config, parent, project) {
return plugins;
}

function _addClassProperties(addPlugin, plugins, config, parent, project) {
addPlugin(
plugins,
[require.resolve("@babel/plugin-proposal-class-properties")],
_buildClassFeaturePluginConstraints(
{
after: ["@babel/plugin-proposal-decorators"],
},
config,
parent,
project
)
);
addPlugin(
plugins,
[require.resolve("@babel/plugin-proposal-private-methods")],
_buildClassFeaturePluginConstraints(
{
after: ["@babel/plugin-proposal-decorators"],
},
config,
parent,
project
)
);
addPlugin(
plugins,
[require.resolve("@babel/plugin-proposal-private-property-in-object")],
_buildClassFeaturePluginConstraints(
{
after: ["@babel/plugin-proposal-decorators"],
},
config,
parent,
project
)
);
}

function _addTypeScriptPlugin(plugins, parent, project) {
const { hasPlugin, addPlugin } = require("ember-cli-babel-plugin-helpers");

Expand Down
8 changes: 4 additions & 4 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(2, "plugins added correctly");
).to.equal(4, "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(2, "plugins were not added");
).to.equal(4, "plugins were not added");
});

it("should include only decorators if it detects class fields plugin", 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(3, "class fields and decorators added");
expect(plugins.length).to.equal(5, "class fields and decorators added");
});

it("should include class fields and decorators before typescript if not handling typescript", function () {
Expand All @@ -172,7 +172,7 @@ describe("get-babel-options", function () {
this.addon.project
);

expect(plugins.length).to.equal(3, "class fields and decorators added");
expect(plugins.length).to.equal(5, "class fields and decorators added");
expect(plugins[2]).to.equal(
"@babel/plugin-transform-typescript",
"typescript is now last"
Expand Down

0 comments on commit 34b3caa

Please sign in to comment.