Skip to content

Commit

Permalink
fix(js): remove deprecated babel transform (#19671)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored Oct 18, 2023
1 parent 5dd7639 commit 472dbc3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/js/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
// require.resolve is used for these packages
"source-map-support",
"@babel/core",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-decorators",
"@babel/plugin-transform-runtime",
"@babel/preset-env",
Expand Down
20 changes: 13 additions & 7 deletions packages/js/babel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname } from 'path';
import { logger } from '@nx/devkit';

/*
* Babel preset to provide TypeScript support and module/nomodule for Nx.
Expand All @@ -10,6 +11,9 @@ export interface NxWebBabelPresetOptions {
decoratorsBeforeExport?: boolean;
legacy?: boolean;
};
loose?: boolean;
/** @deprecated Use `loose` option instead of `classProperties.loose`
*/
classProperties?: {
loose?: boolean;
};
Expand All @@ -30,9 +34,15 @@ module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) {
(caller) => caller?.emitDecoratorMetadata ?? true
);

// Determine settings for `@babel/plugin-proposal-class-properties`,
// Determine settings for `@babel//babel-plugin-transform-class-properties`,
// so that we can sync the `loose` option with `@babel/preset-env`.
const classProperties = options.classProperties ?? { loose: true };
// TODO(v18): Remove classProperties since it's no longer needed, now that the class props transform is in preset-env.
const loose = options.classProperties?.loose ?? options.loose ?? true;
if (options.classProperties) {
logger.warn(
`Use =\`loose\` option instead of \`classProperties.loose\`. The \`classProperties\` option will be removed in Nx 18`
);
}

return {
presets: [
Expand All @@ -55,7 +65,7 @@ module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) {
// Exclude transforms that make all code slower
exclude: ['transform-typeof-symbol'],
// This must match the setting for `@babel/plugin-proposal-class-properties`
loose: classProperties.loose,
loose,
},
],
[
Expand Down Expand Up @@ -89,10 +99,6 @@ module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) {
require.resolve('@babel/plugin-proposal-decorators'),
options.decorators ?? { legacy: true },
],
[
require.resolve('@babel/plugin-proposal-class-properties'),
classProperties,
],
].filter(Boolean),
overrides: [
// Convert `const enum` to `enum`. The former cannot be supported by babel
Expand Down
1 change: 0 additions & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"executors": "./executors.json",
"dependencies": {
"@babel/core": "^7.22.9",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.22.7",
"@babel/plugin-transform-runtime": "^7.22.9",
"@babel/preset-env": "^7.22.9",
Expand Down
3 changes: 3 additions & 0 deletions packages/react/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ interface NxReactBabelOptions {
decoratorsBeforeExport?: boolean;
legacy?: boolean;
};
loose?: boolean;
/** @deprecated Use `loose` option instead of `classProperties.loose`
*/
classProperties?: {
loose?: boolean;
};
Expand Down

0 comments on commit 472dbc3

Please sign in to comment.