From cc8a80b9c61425aabfa01eb7395d2c1d53354770 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 24 Jun 2024 11:48:06 +0800 Subject: [PATCH] feat!: decorators version defaults to `2022-03` --- e2e/cases/babel/decorator/rsbuild.config.ts | 9 ++ .../tests/__snapshots__/plugin.test.ts.snap | 72 ++++------ packages/core/src/config.ts | 2 +- .../tests/__snapshots__/builder.test.ts.snap | 10 +- .../tests/__snapshots__/default.test.ts.snap | 40 +++--- .../__snapshots__/environments.test.ts.snap | 12 +- .../core/tests/__snapshots__/swc.test.ts.snap | 130 +++++++----------- .../tests/__snapshots__/index.test.ts.snap | 14 +- .../tests/__snapshots__/index.test.ts.snap | 10 +- .../tests/__snapshots__/index.test.ts.snap | 10 +- .../tests/__snapshots__/index.test.ts.snap | 9 +- .../tests/__snapshots__/index.test.ts.snap | 3 +- .../tests/__snapshots__/index.test.ts.snap | 15 +- .../tests/__snapshots__/index.test.ts.snap | 45 +++--- .../tests/__snapshots__/index.test.ts.snap | 9 +- .../tests/__snapshots__/index.test.ts.snap | 6 +- website/docs/en/config/source/decorators.mdx | 30 ++-- website/docs/zh/config/source/decorators.mdx | 30 ++-- 18 files changed, 204 insertions(+), 252 deletions(-) create mode 100644 e2e/cases/babel/decorator/rsbuild.config.ts diff --git a/e2e/cases/babel/decorator/rsbuild.config.ts b/e2e/cases/babel/decorator/rsbuild.config.ts new file mode 100644 index 0000000000..5314d6d12a --- /dev/null +++ b/e2e/cases/babel/decorator/rsbuild.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from '@rsbuild/core'; + +export default defineConfig({ + source: { + decorators: { + version: 'legacy', + }, + }, +}); diff --git a/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap b/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap index 9b3b19a71a..3fbd1480d0 100644 --- a/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap +++ b/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap @@ -313,13 +313,12 @@ exports[`plugin-swc > should apply source.include and source.exclude correctly 1 }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -373,13 +372,12 @@ exports[`plugin-swc > should apply source.include and source.exclude correctly 1 }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -444,13 +442,12 @@ exports[`plugin-swc > should disable react refresh when dev.hmr is false 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": false, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -504,13 +501,12 @@ exports[`plugin-swc > should disable react refresh when dev.hmr is false 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": false, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -571,13 +567,12 @@ exports[`plugin-swc > should disable react refresh when target is not web 1`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": false, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -628,13 +623,12 @@ exports[`plugin-swc > should disable react refresh when target is not web 1`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": false, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -698,13 +692,12 @@ exports[`plugin-swc > should disable react refresh when target is not web 2`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -758,13 +751,12 @@ exports[`plugin-swc > should disable react refresh when target is not web 2`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -828,13 +820,12 @@ exports[`plugin-swc > should disable react refresh when target is not web 3`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": false, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -888,13 +879,12 @@ exports[`plugin-swc > should disable react refresh when target is not web 3`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": false, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -1011,8 +1001,8 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", @@ -1063,8 +1053,8 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", @@ -1123,8 +1113,8 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", @@ -1219,13 +1209,12 @@ exports[`plugin-swc > should set swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, @@ -1279,13 +1268,12 @@ exports[`plugin-swc > should set swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "refresh": true, "runtime": "classic", }, - "useDefineForClassFields": false, }, }, }, diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index fe8b5f3e0d..8a15f938c8 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -79,7 +79,7 @@ const getDefaultSourceConfig = (): NormalizedSourceConfig => ({ aliasStrategy: 'prefer-tsconfig', preEntry: [], decorators: { - version: 'legacy', + version: '2022-03', }, }); diff --git a/packages/core/tests/__snapshots__/builder.test.ts.snap b/packages/core/tests/__snapshots__/builder.test.ts.snap index 9073888177..cccfef9e4d 100644 --- a/packages/core/tests/__snapshots__/builder.test.ts.snap +++ b/packages/core/tests/__snapshots__/builder.test.ts.snap @@ -131,9 +131,8 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -178,9 +177,8 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, diff --git a/packages/core/tests/__snapshots__/default.test.ts.snap b/packages/core/tests/__snapshots__/default.test.ts.snap index 0d518989b0..6e85fb89eb 100644 --- a/packages/core/tests/__snapshots__/default.test.ts.snap +++ b/packages/core/tests/__snapshots__/default.test.ts.snap @@ -131,9 +131,8 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -178,9 +177,8 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -578,9 +576,8 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -625,9 +622,8 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1052,9 +1048,8 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1090,9 +1085,8 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1416,9 +1410,8 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1463,9 +1456,8 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, diff --git a/packages/core/tests/__snapshots__/environments.test.ts.snap b/packages/core/tests/__snapshots__/environments.test.ts.snap index 0f0f77e994..d6d5546d12 100644 --- a/packages/core/tests/__snapshots__/environments.test.ts.snap +++ b/packages/core/tests/__snapshots__/environments.test.ts.snap @@ -102,7 +102,7 @@ exports[`environment config > should normalize environment config correctly 1`] }, "aliasStrategy": "prefer-tsconfig", "decorators": { - "version": "legacy", + "version": "2022-03", }, "define": {}, "entry": { @@ -224,7 +224,7 @@ exports[`environment config > should print environment config when inspect confi }, "aliasStrategy": "prefer-tsconfig", "decorators": { - "version": "legacy", + "version": "2022-03", }, "define": {}, "entry": { @@ -342,7 +342,7 @@ exports[`environment config > should print environment config when inspect confi }, "aliasStrategy": "prefer-tsconfig", "decorators": { - "version": "legacy", + "version": "2022-03", }, "define": {}, "entry": { @@ -465,7 +465,7 @@ exports[`environment config > should support modify environment config by api.mo }, "aliasStrategy": "prefer-tsconfig", "decorators": { - "version": "legacy", + "version": "2022-03", }, "define": {}, "entry": { @@ -584,7 +584,7 @@ exports[`environment config > should support modify environment config by api.mo }, "aliasStrategy": "prefer-tsconfig", "decorators": { - "version": "legacy", + "version": "2022-03", }, "define": {}, "entry": { @@ -703,7 +703,7 @@ exports[`environment config > should support modify environment config by api.mo }, "aliasStrategy": "prefer-tsconfig", "decorators": { - "version": "legacy", + "version": "2022-03", }, "define": {}, "entry": {}, diff --git a/packages/core/tests/__snapshots__/swc.test.ts.snap b/packages/core/tests/__snapshots__/swc.test.ts.snap index 519a1adfa9..7b75e4ecfb 100644 --- a/packages/core/tests/__snapshots__/swc.test.ts.snap +++ b/packages/core/tests/__snapshots__/swc.test.ts.snap @@ -53,9 +53,8 @@ exports[`plugin-swc > should add antd pluginImport 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -100,9 +99,8 @@ exports[`plugin-swc > should add antd pluginImport 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -170,9 +168,8 @@ exports[`plugin-swc > should add browserslist 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -214,9 +211,8 @@ exports[`plugin-swc > should add browserslist 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -288,9 +284,8 @@ exports[`plugin-swc > should add pluginImport 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -342,9 +337,8 @@ exports[`plugin-swc > should add pluginImport 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -474,9 +468,8 @@ exports[`plugin-swc > should allow to use \`tools.swc\` to configure swc-loader }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -521,9 +514,8 @@ exports[`plugin-swc > should allow to use \`tools.swc\` to configure swc-loader }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -582,9 +574,8 @@ exports[`plugin-swc > should apply environment config correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -636,9 +627,8 @@ exports[`plugin-swc > should apply environment config correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -693,9 +683,8 @@ exports[`plugin-swc > should apply environment config correctly 2`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -738,9 +727,8 @@ exports[`plugin-swc > should apply environment config correctly 2`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -810,9 +798,8 @@ exports[`plugin-swc > should disable all pluginImport 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -857,9 +844,8 @@ exports[`plugin-swc > should disable all pluginImport 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -919,9 +905,8 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -957,9 +942,8 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1024,9 +1008,8 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1066,9 +1049,8 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1140,9 +1122,8 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1186,9 +1167,8 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1260,9 +1240,8 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1307,9 +1286,8 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1381,9 +1359,8 @@ exports[`plugin-swc > should has correct core-js 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1427,9 +1404,8 @@ exports[`plugin-swc > should has correct core-js 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1490,9 +1466,8 @@ exports[`plugin-swc > should has correct core-js 2`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -1528,9 +1503,8 @@ exports[`plugin-swc > should has correct core-js 2`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, diff --git a/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap b/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap index bf636024ba..dc368561c3 100644 --- a/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap @@ -49,9 +49,8 @@ exports[`plugins/babel > babel-loader should works with builtin:swc-loader 1`] = }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -66,10 +65,9 @@ exports[`plugins/babel > babel-loader should works with builtin:swc-loader 1`] = [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", ], "presets": [ [ @@ -269,10 +267,9 @@ exports[`plugins/babel > should set babel-loader 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", ], "presets": [ [ @@ -315,10 +312,9 @@ exports[`plugins/babel > should set babel-loader when config is add 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "babel-plugin-import", { diff --git a/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap b/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap index f9ac99b682..d279d06745 100644 --- a/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap @@ -28,9 +28,8 @@ exports[`plugin-mdx > should allow to configure mdx loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, @@ -73,9 +72,8 @@ exports[`plugin-mdx > should register mdx loader correctly 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, }, diff --git a/packages/plugin-react/tests/__snapshots__/index.test.ts.snap b/packages/plugin-react/tests/__snapshots__/index.test.ts.snap index 4df26566e6..a24e93c1c8 100644 --- a/packages/plugin-react/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-react/tests/__snapshots__/index.test.ts.snap @@ -148,14 +148,13 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -200,14 +199,13 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, diff --git a/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap b/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap index e60f0e3cfa..365674c202 100644 --- a/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap @@ -17,10 +17,9 @@ exports[`plugin-solid > should allow to configure solid preset options 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "/node_modules//solid-refresh/dist/babel.cjs", ], @@ -75,10 +74,9 @@ exports[`plugin-solid > should apply solid preset correctly 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "/node_modules//solid-refresh/dist/babel.cjs", ], @@ -130,10 +128,9 @@ exports[`plugin-solid > should apply solid preset correctly in rspack mode 1`] = [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "/node_modules//solid-refresh/dist/babel.cjs", ], diff --git a/packages/plugin-source-build/tests/__snapshots__/index.test.ts.snap b/packages/plugin-source-build/tests/__snapshots__/index.test.ts.snap index 4741957431..cf97ed5330 100644 --- a/packages/plugin-source-build/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-source-build/tests/__snapshots__/index.test.ts.snap @@ -27,10 +27,9 @@ exports[`plugin-source-build > should allow to set resolve priority 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", ], "presets": [ [ diff --git a/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap b/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap index 9fd10941f0..5f2889b4a5 100644 --- a/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap @@ -45,9 +45,8 @@ exports[`plugins/styled-components > should apply styledComponents option to swc }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -98,9 +97,8 @@ exports[`plugins/styled-components > should enable ssr option when target contai }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { @@ -162,9 +160,8 @@ exports[`plugins/styled-components > should enable ssr option when target contai }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, + "decoratorVersion": "2022-03", + "legacyDecorator": false, }, }, "rspackExperiments": { diff --git a/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap b/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap index d5f50950f0..86be1b6b6f 100644 --- a/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap @@ -42,14 +42,13 @@ exports[`svgr > 'configure SVGR options' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -135,14 +134,13 @@ exports[`svgr > 'exportType default / mixedImport false' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -200,14 +198,13 @@ exports[`svgr > 'exportType default / mixedImport false' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -292,14 +289,13 @@ exports[`svgr > 'exportType default / mixedImport true' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -357,14 +353,13 @@ exports[`svgr > 'exportType default / mixedImport true' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -449,14 +444,13 @@ exports[`svgr > 'exportType named / mixedImport false' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -514,14 +508,13 @@ exports[`svgr > 'exportType named / mixedImport false' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -606,14 +599,13 @@ exports[`svgr > 'exportType named / mixedImport true' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, @@ -671,14 +663,13 @@ exports[`svgr > 'exportType named / mixedImport true' 1`] = ` }, "preserveAllComments": true, "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, + "decoratorVersion": "2022-03", + "legacyDecorator": false, "react": { "development": false, "refresh": true, "runtime": "automatic", }, - "useDefineForClassFields": false, }, }, }, diff --git a/packages/plugin-vue-jsx/tests/__snapshots__/index.test.ts.snap b/packages/plugin-vue-jsx/tests/__snapshots__/index.test.ts.snap index db37728161..23d8e9be05 100644 --- a/packages/plugin-vue-jsx/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-vue-jsx/tests/__snapshots__/index.test.ts.snap @@ -17,10 +17,9 @@ exports[`plugin-vue-jsx > should allow to configure jsx babel plugin options 1`] [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "/node_modules//@vue/babel-plugin-jsx/dist/index.js", { @@ -69,10 +68,9 @@ exports[`plugin-vue-jsx > should apply jsx babel plugin correctly 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "/node_modules//@vue/babel-plugin-jsx/dist/index.js", {}, @@ -119,10 +117,9 @@ exports[`plugin-vue-jsx > should apply jsx babel plugin correctly in rspack mode [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", [ "/node_modules//@vue/babel-plugin-jsx/dist/index.js", {}, diff --git a/packages/plugin-vue2-jsx/tests/__snapshots__/index.test.ts.snap b/packages/plugin-vue2-jsx/tests/__snapshots__/index.test.ts.snap index 9e7d8a4669..d5a0d8bc58 100644 --- a/packages/plugin-vue2-jsx/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-vue2-jsx/tests/__snapshots__/index.test.ts.snap @@ -17,10 +17,9 @@ exports[`plugin-vue2-jsx > should allow to configure jsx babel plugin options 1` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", ], "presets": [ [ @@ -66,10 +65,9 @@ exports[`plugin-vue2-jsx > should apply jsx babel plugin correctly 1`] = ` [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", { - "version": "legacy", + "version": "2022-03", }, ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", ], "presets": [ [ diff --git a/website/docs/en/config/source/decorators.mdx b/website/docs/en/config/source/decorators.mdx index 9c18395b9a..bde217930e 100644 --- a/website/docs/en/config/source/decorators.mdx +++ b/website/docs/en/config/source/decorators.mdx @@ -13,19 +13,10 @@ Used to configure the decorators syntax. ## decorators.version - **Type:** `'legacy' | '2022-03'` -- **Default:** `'legacy'` +- **Default:** `'2022-03'` Specify the decorator syntax version to be used. -### legacy - -Rsbuild uses legacy syntax by default (Stage 1 proposal), equivalent to TypeScript's `experimentalDecorators: true`. - -Reference documentation: - -- [A Complete Guide to TypeScript Decorators](https://mirone.me/a-complete-guide-to-typescript-decorator/) -- [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) - ### 2022-03 `2022-03` corresponds to the Stage 3 decorator proposal, equivalent to the decorator syntax supported by TypeScript 5.0 by default. @@ -44,3 +35,22 @@ Reference documentation: - [JavaScript meta programming with the 2022-03 decorators API](https://2ality.com/2022/10/javascript-decorators.html) - [TypeScript 5.0 Decorators](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#decorators) + +### legacy + +Equivalent to TypeScript's `experimentalDecorators: true`. + +```ts title="rsbuild.config.ts" +export default { + source: { + decorators: { + version: 'legacy', + }, + }, +}; +``` + +Reference documentation: + +- [A Complete Guide to TypeScript Decorators](https://mirone.me/a-complete-guide-to-typescript-decorator/) +- [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) diff --git a/website/docs/zh/config/source/decorators.mdx b/website/docs/zh/config/source/decorators.mdx index cdddcd53e9..724985ed66 100644 --- a/website/docs/zh/config/source/decorators.mdx +++ b/website/docs/zh/config/source/decorators.mdx @@ -13,19 +13,10 @@ type Decorators = { ## decorators.version - **类型:** `'legacy' | '2022-03'` -- **默认值:** `'legacy'` +- **默认值:** `'2022-03'` 指定需要使用的装饰器语法版本。 -### legacy - -Rsbuild 默认使用 `legacy` 语法(Stage 1 提案),等价于 TypeScript 的 `experimentalDecorators: true`。 - -参考文档: - -- [A Complete Guide to TypeScript Decorators](https://mirone.me/a-complete-guide-to-typescript-decorator/) -- [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) - ### 2022-03 `2022-03` 对应装饰器 Stage 3 提案,等价于 TypeScript 5.0 默认支持的装饰器语法。 @@ -44,3 +35,22 @@ export default { - [JavaScript meta programming with the 2022-03 decorators API](https://2ality.com/2022/10/javascript-decorators.html) - [TypeScript 5.0 Decorators](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#decorators) + +### legacy + +等价于 TypeScript 的 `experimentalDecorators: true`。 + +```ts title="rsbuild.config.ts" +export default { + source: { + decorators: { + version: 'legacy', + }, + }, +}; +``` + +参考文档: + +- [A Complete Guide to TypeScript Decorators](https://mirone.me/a-complete-guide-to-typescript-decorator/) +- [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)