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

fix(js): remove deprecated babel transform #19671

Merged
merged 1 commit into from
Oct 18, 2023
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
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