From 6b176ca7703b81e030fa14b23b5fcf836ab1fc75 Mon Sep 17 00:00:00 2001 From: zhylmzr Date: Tue, 9 Jul 2024 07:53:20 +0800 Subject: [PATCH] fix(plugin-solid): remove `@babel/preset-typescript` for resolve the babel warning (#2842) --- packages/plugin-solid/src/index.ts | 12 +++-- .../tests/__snapshots__/index.test.ts.snap | 48 +++++++------------ 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/packages/plugin-solid/src/index.ts b/packages/plugin-solid/src/index.ts index 775d60b313..05fd9afca3 100644 --- a/packages/plugin-solid/src/index.ts +++ b/packages/plugin-solid/src/index.ts @@ -25,11 +25,13 @@ export function pluginSolid(options: PluginSolidOptions = {}): RsbuildPlugin { chain, CHAIN_ID, modifier: (babelOptions) => { - babelOptions.presets ??= []; - babelOptions.presets.push([ - require.resolve('babel-preset-solid'), - options.solidPresetOptions || {}, - ]); + babelOptions.presets = [ + [ + require.resolve('babel-preset-solid'), + options.solidPresetOptions || {}, + ], + ]; + babelOptions.parserOpts = { plugins: ['jsx', 'typescript'] }; const usingHMR = !isProd && environmentConfig.dev.hmr && target === 'web'; diff --git a/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap b/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap index 365674c202..346f413393 100644 --- a/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap @@ -13,6 +13,12 @@ exports[`plugin-solid > should allow to configure solid preset options 1`] = ` "babelrc": false, "compact": false, "configFile": false, + "parserOpts": { + "plugins": [ + "jsx", + "typescript", + ], + }, "plugins": [ [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", @@ -25,16 +31,6 @@ exports[`plugin-solid > should allow to configure solid preset options 1`] = ` ], ], "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, - }, - ], [ "/node_modules//babel-preset-solid/index.js", { @@ -70,6 +66,12 @@ exports[`plugin-solid > should apply solid preset correctly 1`] = ` "babelrc": false, "compact": false, "configFile": false, + "parserOpts": { + "plugins": [ + "jsx", + "typescript", + ], + }, "plugins": [ [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", @@ -82,16 +84,6 @@ exports[`plugin-solid > should apply solid preset correctly 1`] = ` ], ], "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, - }, - ], [ "/node_modules//babel-preset-solid/index.js", {}, @@ -124,6 +116,12 @@ exports[`plugin-solid > should apply solid preset correctly in rspack mode 1`] = "babelrc": false, "compact": false, "configFile": false, + "parserOpts": { + "plugins": [ + "jsx", + "typescript", + ], + }, "plugins": [ [ "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", @@ -136,16 +134,6 @@ exports[`plugin-solid > should apply solid preset correctly in rspack mode 1`] = ], ], "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, - }, - ], [ "/node_modules//babel-preset-solid/index.js", {},