Skip to content
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
22 changes: 17 additions & 5 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 All @@ -307,7 +312,14 @@ function _buildClassFeaturePluginConstraints(constraints, config, parent, projec
return constraints;
}

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

if (hasPlugin(plugins, "@babel/plugin-proposal-decorators")) {
Expand Down Expand Up @@ -341,7 +353,7 @@ function _addDecoratorPlugins(plugins, options, config, parent, project) {
)} has added the class-properties 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.`
);
}
} else {
} else if (isClassPropertiesRequired) {
addPlugin(
plugins,
[
Expand Down
24 changes: 14 additions & 10 deletions lib/get-babel-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const {
_getPresetEnv,
} = require("./babel-options-util");

module.exports = function getBabelOptions(config, appInstance) {
let { parent, project } = appInstance;
module.exports = function getBabelOptions(config, cliBabelInstance) {
let { parent, project } = cliBabelInstance;
let addonProvidedConfig = _getAddonProvidedConfig(config);
let shouldIncludeHelpers = _shouldIncludeHelpers(config, appInstance);
let shouldIncludeHelpers = _shouldIncludeHelpers(config, cliBabelInstance);
let shouldHandleTypeScript = _shouldHandleTypeScript(config, parent, project);
let shouldIncludeDecoratorPlugins = _shouldIncludeDecoratorPlugins(config);

let emberCLIBabelConfig = config["ember-cli-babel"];
let emberCLIBabelConfig = config["ember-cli-babel"];
let shouldRunPresetEnv = true;

if (emberCLIBabelConfig) {
Expand All @@ -38,13 +38,16 @@ module.exports = function getBabelOptions(config, appInstance) {
}

if (shouldIncludeDecoratorPlugins) {
userPlugins = _addDecoratorPlugins(
userPlugins.slice(),
addonProvidedConfig.options,
userPlugins = _addDecoratorPlugins({
plugins: userPlugins.slice(),
options: addonProvidedConfig.options,
config,
parent,
project
);
project,
isClassPropertiesRequired: cliBabelInstance.isPluginRequired(
"proposal-class-properties"
),
});
}

options.plugins = []
Expand All @@ -56,7 +59,8 @@ module.exports = function getBabelOptions(config, appInstance) {
_getEmberDataPackagesPolyfill(config, parent),
_shouldCompileModules(config, project) && _getModulesPlugin(),
userPostTransformPlugins
).filter(Boolean);
)
.filter(Boolean);

options.presets = [
shouldRunPresetEnv && _getPresetEnv(addonProvidedConfig, project),
Expand Down
Loading