diff --git a/crates/node_binding/napi-binding.d.ts b/crates/node_binding/napi-binding.d.ts index ca660dc6a7c9..b35caf602e6c 100644 --- a/crates/node_binding/napi-binding.d.ts +++ b/crates/node_binding/napi-binding.d.ts @@ -2130,7 +2130,6 @@ export interface RawEvalDevToolModulePluginOptions { } export interface RawExperiments { - topLevelAwait: boolean incremental?: false | { [key: string]: boolean } useInputFileSystem?: false | Array css?: boolean diff --git a/crates/rspack/src/builder/mod.rs b/crates/rspack/src/builder/mod.rs index e7c129816d73..76f8ef155f3f 100644 --- a/crates/rspack/src/builder/mod.rs +++ b/crates/rspack/src/builder/mod.rs @@ -3645,8 +3645,6 @@ impl OptimizationOptionsBuilder { pub struct ExperimentsBuilder { /// Incremental passes. incremental: Option, - /// Whether to enable top level await. - top_level_await: Option, /// Whether to enable output module. output_module: Option, /// Whether to enable future defaults. @@ -3662,7 +3660,6 @@ impl From for ExperimentsBuilder { fn from(value: Experiments) -> Self { ExperimentsBuilder { incremental: Some(value.incremental), - top_level_await: Some(value.top_level_await), output_module: None, future_defaults: None, css: Some(value.css), @@ -3675,7 +3672,6 @@ impl From<&mut ExperimentsBuilder> for ExperimentsBuilder { fn from(value: &mut ExperimentsBuilder) -> Self { ExperimentsBuilder { incremental: value.incremental.take(), - top_level_await: value.top_level_await.take(), output_module: value.output_module.take(), future_defaults: value.future_defaults.take(), css: value.css.take(), @@ -3691,12 +3687,6 @@ impl ExperimentsBuilder { self } - /// Set whether to enable top level await. - pub fn top_level_await(&mut self, top_level_await: bool) -> &mut Self { - self.top_level_await = Some(top_level_await); - self - } - /// Set whether to enable future defaults. pub fn future_defaults(&mut self, future_defaults: bool) -> &mut Self { self.future_defaults = Some(future_defaults); @@ -3735,8 +3725,6 @@ impl ExperimentsBuilder { passes, } }); - let top_level_await = d!(self.top_level_await, true); - // Builder specific let future_defaults = w!(self.future_defaults, false); w!(self.css, *future_defaults); @@ -3745,7 +3733,6 @@ impl ExperimentsBuilder { Ok(Experiments { incremental, - top_level_await, css: d!(self.css, false), lazy_barrel: true, defer_import: false, diff --git a/crates/rspack/tests/snapshots/defaults__default_options.snap b/crates/rspack/tests/snapshots/defaults__default_options.snap index 2a0e90280300..fb72c40de8c0 100644 --- a/crates/rspack/tests/snapshots/defaults__default_options.snap +++ b/crates/rspack/tests/snapshots/defaults__default_options.snap @@ -1514,7 +1514,6 @@ CompilerOptions { MAKE | EMIT_ASSETS, ), }, - top_level_await: true, css: false, lazy_barrel: true, defer_import: false, diff --git a/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs b/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs index a275e5516dbb..95f2f383adea 100644 --- a/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs +++ b/crates/rspack_binding_api/src/raw_options/raw_experiments/mod.rs @@ -10,7 +10,6 @@ use super::WithFalse; #[derive(Debug)] #[napi(object, object_to_js = false)] pub struct RawExperiments { - pub top_level_await: bool, #[napi(ts_type = "false | { [key: string]: boolean }")] pub incremental: Option>, #[napi(ts_type = "false | Array")] @@ -30,7 +29,6 @@ impl From for Experiments { }, None => IncrementalOptions::empty_passes(), }, - top_level_await: value.top_level_await, css: value.css.unwrap_or(false), lazy_barrel: value.lazy_barrel, defer_import: value.defer_import, diff --git a/crates/rspack_core/src/options/experiments/mod.rs b/crates/rspack_core/src/options/experiments/mod.rs index 55b59caf34f4..04034605091f 100644 --- a/crates/rspack_core/src/options/experiments/mod.rs +++ b/crates/rspack_core/src/options/experiments/mod.rs @@ -6,7 +6,6 @@ use crate::incremental::IncrementalOptions; #[derive(Debug)] pub struct Experiments { pub incremental: IncrementalOptions, - pub top_level_await: bool, pub css: bool, pub lazy_barrel: bool, pub defer_import: bool, diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/esm_detection_parser_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/esm_detection_parser_plugin.rs index 7a2f1c09ff92..e41ff28f1120 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/esm_detection_parser_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/esm_detection_parser_plugin.rs @@ -27,10 +27,8 @@ impl JavascriptParser<'_> { ); } - fn handle_top_level_await(&mut self, allow_top_level: bool, span: Span) { - if !allow_top_level { - self.throw_top_level_await_error("The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)".into(), span); - } else if self.is_esm { + fn handle_top_level_await(&mut self, span: Span) { + if self.is_esm { self.build_meta.has_top_level_await = true; } else { self.throw_top_level_await_error( @@ -41,15 +39,8 @@ impl JavascriptParser<'_> { } } -pub struct ESMDetectionParserPlugin { - top_level_await: bool, -} - -impl ESMDetectionParserPlugin { - pub fn new(top_level_await: bool) -> Self { - Self { top_level_await } - } -} +#[derive(Default)] +pub struct ESMDetectionParserPlugin; // nonHarmonyIdentifiers fn is_non_esm_identifier(name: &str) -> bool { @@ -87,7 +78,7 @@ impl JavascriptParserPlugin for ESMDetectionParserPlugin { let lo = expr.span_lo(); let hi = lo.add(BytePos(AWAIT_LEN)); let span = Span::new(lo, hi); - parser.handle_top_level_await(self.top_level_await, span); + parser.handle_top_level_await(span); } fn top_level_for_of_await_stmt( @@ -99,7 +90,7 @@ impl JavascriptParserPlugin for ESMDetectionParserPlugin { let lo = stmt.span_lo().add(BytePos(offset)); let hi = lo.add(BytePos(AWAIT_LEN)); let span = Span::new(lo, hi); - parser.handle_top_level_await(self.top_level_await, span); + parser.handle_top_level_await(span); } fn evaluate_typeof<'a>( diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs index 7aa76df3e48a..0de0c51f856e 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs @@ -412,9 +412,7 @@ impl<'parser> JavascriptParser<'parser> { if module_type.is_js_auto() || module_type.is_js_esm() { plugins.push(Box::new(parser_plugin::ESMTopLevelThisParserPlugin)); - plugins.push(Box::new(parser_plugin::ESMDetectionParserPlugin::new( - compiler_options.experiments.top_level_await, - ))); + plugins.push(Box::new(parser_plugin::ESMDetectionParserPlugin::default())); plugins.push(Box::new( parser_plugin::ImportMetaContextDependencyParserPlugin, )); diff --git a/packages/rspack-test-tools/src/case/normal.ts b/packages/rspack-test-tools/src/case/normal.ts index 4960a11262d9..fc173b1a7210 100644 --- a/packages/rspack-test-tools/src/case/normal.ts +++ b/packages/rspack-test-tools/src/case/normal.ts @@ -230,7 +230,6 @@ function defaultOptions( experiments: { css: false, asyncWebAssembly: true, - topLevelAwait: true, // CHANGE: rspack does not support `backCompat` yet. // backCompat: false, // CHANGE: Rspack enables `css` by default. diff --git a/packages/rspack/etc/core.api.md b/packages/rspack/etc/core.api.md index c91f31e36eb7..3d79a2c8e863 100644 --- a/packages/rspack/etc/core.api.md +++ b/packages/rspack/etc/core.api.md @@ -2439,7 +2439,6 @@ interface ExecuteModuleContext { export type Experiments = { asyncWebAssembly?: boolean; outputModule?: boolean; - topLevelAwait?: boolean; css?: boolean; layers?: boolean; incremental?: IncrementalPresets | Incremental; @@ -2525,8 +2524,6 @@ export interface ExperimentsNormalized { // (undocumented) outputModule?: boolean; // (undocumented) - topLevelAwait?: boolean; - // (undocumented) typeReexportsPresence?: boolean; // (undocumented) useInputFileSystem?: false | RegExp[]; diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 44f0be119fef..3c0fe4803f72 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -213,7 +213,6 @@ const applyExperimentsDefaults = (experiments: ExperimentsNormalized) => { D(experiments, 'futureDefaults', false); D(experiments, 'asyncWebAssembly', experiments.futureDefaults); D(experiments, 'css', experiments.futureDefaults ? true : undefined); - D(experiments, 'topLevelAwait', true); D(experiments, 'deferImport', false); D(experiments, 'buildHttp', undefined); diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 28aca58eeaf8..452d83a32d6d 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -379,11 +379,6 @@ export const getNormalizedRspackOptions = ( '`experiments.layers` config is deprecated and will be removed in Rspack v2.0. Feature layers will always be enabled. Remove this option from your Rspack configuration.', ); } - if (experiments.topLevelAwait === false) { - deprecate( - '`experiments.topLevelAwait` config is deprecated and will be removed in Rspack v2.0. Top-level await will always be enabled. Remove this option from your Rspack configuration.', - ); - } if (experiments.lazyBarrel) { deprecate( '`experiments.lazyBarrel` config is deprecated and will be removed in Rspack v2.0. Lazy barrel is already stable and enabled by default. Remove this option from your Rspack configuration.', @@ -673,7 +668,6 @@ export type CacheNormalized = export interface ExperimentsNormalized { asyncWebAssembly?: boolean; outputModule?: boolean; - topLevelAwait?: boolean; css?: boolean; /** * @deprecated This option is deprecated, layers is enabled since v1.6.0 diff --git a/packages/rspack/src/config/types.ts b/packages/rspack/src/config/types.ts index a392932730b3..26a2edc0b25e 100644 --- a/packages/rspack/src/config/types.ts +++ b/packages/rspack/src/config/types.ts @@ -2763,12 +2763,6 @@ export type Experiments = { * @default false */ outputModule?: boolean; - /** - * Enable top-level await. - * @deprecated This option is deprecated, top-level await is enabled by default. - * @default true - */ - topLevelAwait?: boolean; /** * Enable CSS support. * diff --git a/tests/rspack-test/Defaults.test.js b/tests/rspack-test/Defaults.test.js index 5749b2d59e4e..76ebb067203d 100644 --- a/tests/rspack-test/Defaults.test.js +++ b/tests/rspack-test/Defaults.test.js @@ -90,7 +90,6 @@ function assertWebpackConfig(config) { trimObjectPaths(webpackBaseConfig, ignoredPaths); filterObjectPaths(webpackBaseConfig, rspackSupportedConfig); // PATCH DIFF - delete rspackBaseConfig.experiments.topLevelAwait; delete rspackBaseConfig.optimization.inlineExports; expect(rspackBaseConfig).toEqual(webpackBaseConfig); } diff --git a/tests/rspack-test/configCases/container-1-5/error-handling/rspack.config.js b/tests/rspack-test/configCases/container-1-5/error-handling/rspack.config.js index 8632b4e9812c..d74b577b36ae 100644 --- a/tests/rspack-test/configCases/container-1-5/error-handling/rspack.config.js +++ b/tests/rspack-test/configCases/container-1-5/error-handling/rspack.config.js @@ -21,7 +21,5 @@ module.exports = { } }) ], - experiments: { - topLevelAwait: true - } + }; diff --git a/tests/rspack-test/configCases/container/error-handling/rspack.config.js b/tests/rspack-test/configCases/container/error-handling/rspack.config.js index c3b679ecd199..c74bfb7791e8 100644 --- a/tests/rspack-test/configCases/container/error-handling/rspack.config.js +++ b/tests/rspack-test/configCases/container/error-handling/rspack.config.js @@ -21,7 +21,5 @@ module.exports = { } }) ], - experiments: { - topLevelAwait: true - } + }; diff --git a/tests/rspack-test/configCases/graph/issue-11770/rspack.config.js b/tests/rspack-test/configCases/graph/issue-11770/rspack.config.js index 126c44b052cb..19ff91886d30 100644 --- a/tests/rspack-test/configCases/graph/issue-11770/rspack.config.js +++ b/tests/rspack-test/configCases/graph/issue-11770/rspack.config.js @@ -39,7 +39,5 @@ module.exports = { } ] }, - experiments: { - topLevelAwait: true - } + }; diff --git a/tests/rspack-test/configCases/issues/issue-14974/rspack.config.js b/tests/rspack-test/configCases/issues/issue-14974/rspack.config.js index 6ff908e4e584..0f250edb6b8d 100644 --- a/tests/rspack-test/configCases/issues/issue-14974/rspack.config.js +++ b/tests/rspack-test/configCases/issues/issue-14974/rspack.config.js @@ -3,7 +3,6 @@ const { HotModuleReplacementPlugin } = require("@rspack/core"); /** @type {import("@rspack/core").Configuration} */ module.exports = { devtool: false, - experiments: { topLevelAwait: true }, optimization: { usedExports: false, sideEffects: false }, plugins: [new HotModuleReplacementPlugin()] }; diff --git a/tests/rspack-test/defaultsCases/default/base.js b/tests/rspack-test/defaultsCases/default/base.js index 13551f565e4c..c86c0f3c433d 100644 --- a/tests/rspack-test/defaultsCases/default/base.js +++ b/tests/rspack-test/defaultsCases/default/base.js @@ -46,7 +46,6 @@ module.exports = { inlineConst: true, inlineEnum: false, lazyBarrel: true, - topLevelAwait: true, typeReexportsPresence: false, useInputFileSystem: false, }, diff --git a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/index.js b/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/index.js deleted file mode 100644 index 7bc4f85957c9..000000000000 --- a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const a = await Promise.resolve("aaa"); - -for await (const _ of [Promise.resolve("bbbb")]) { } - -export default a; diff --git a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/raw-error.err b/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/raw-error.err deleted file mode 100644 index f40336bfaffe..000000000000 --- a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/raw-error.err +++ /dev/null @@ -1,12 +0,0 @@ -Array [ - Object { - code: ModuleParseError, - moduleIdentifier: /diagnosticsCases/module-parse-failed/tla_disable_error/index.js, - moduleName: ./index.js, - }, - Object { - code: ModuleParseError, - moduleIdentifier: /diagnosticsCases/module-parse-failed/tla_disable_error/index.js, - moduleName: ./index.js, - }, -] \ No newline at end of file diff --git a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/raw-warning.err b/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/raw-warning.err deleted file mode 100644 index 0c89d332f1fe..000000000000 --- a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/raw-warning.err +++ /dev/null @@ -1 +0,0 @@ -Array [] \ No newline at end of file diff --git a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/rspack.config.js b/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/rspack.config.js deleted file mode 100644 index 5c50daa34e0a..000000000000 --- a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/rspack.config.js +++ /dev/null @@ -1,6 +0,0 @@ -/** @type {import("@rspack/core").Configuration} */ -module.exports = { - experiments: { - topLevelAwait: false - } -}; diff --git a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/stats.err b/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/stats.err deleted file mode 100644 index 8b42d3b76c85..000000000000 --- a/tests/rspack-test/diagnosticsCases/module-parse-failed/tla_disable_error/stats.err +++ /dev/null @@ -1,27 +0,0 @@ -ERROR in ./index.js - × Module parse failed: - ╰─▶ × JavaScript parse error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it) - ╭─[3:4] - 1 │ const a = await Promise.resolve("aaa"); - 2 │ - 3 │ for await (const _ of [Promise.resolve("bbbb")]) { } - · ───── - 4 │ - 5 │ export default a; - ╰──── - - help: - You may need an appropriate loader to handle this file type. - -ERROR in ./index.js - × Module parse failed: - ╰─▶ × JavaScript parse error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it) - ╭─[1:10] - 1 │ const a = await Promise.resolve("aaa"); - · ───── - 2 │ - 3 │ for await (const _ of [Promise.resolve("bbbb")]) { } - ╰──── - - help: - You may need an appropriate loader to handle this file type. \ No newline at end of file diff --git a/tests/rspack-test/exampleCases/top-level-await/rspack.config.js b/tests/rspack-test/exampleCases/top-level-await/rspack.config.js index 9fcd2f30468c..dfa719e96e01 100644 --- a/tests/rspack-test/exampleCases/top-level-await/rspack.config.js +++ b/tests/rspack-test/exampleCases/top-level-await/rspack.config.js @@ -2,7 +2,5 @@ module.exports = { optimization: { chunkIds: "deterministic" // To keep filename consistent between different modes (for example building only) }, - experiments: { - topLevelAwait: true - } + }; diff --git a/tests/rspack-test/exampleCases/wasm-complex/rspack.config.js b/tests/rspack-test/exampleCases/wasm-complex/rspack.config.js index 13de5cdac2fd..bc69b32c95ab 100644 --- a/tests/rspack-test/exampleCases/wasm-complex/rspack.config.js +++ b/tests/rspack-test/exampleCases/wasm-complex/rspack.config.js @@ -17,6 +17,5 @@ module.exports = { }, experiments: { asyncWebAssembly: true, - topLevelAwait: true } }; diff --git a/tests/rspack-test/serialCases/async-library/0-create-library/rspack.config.js b/tests/rspack-test/serialCases/async-library/0-create-library/rspack.config.js index 0f5270b08817..20299b7f7c65 100644 --- a/tests/rspack-test/serialCases/async-library/0-create-library/rspack.config.js +++ b/tests/rspack-test/serialCases/async-library/0-create-library/rspack.config.js @@ -12,7 +12,6 @@ module.exports = { minimize: true }, experiments: { - topLevelAwait: true, outputModule: true } }; diff --git a/tests/rspack-test/serialCases/async-library/1-use-library/rspack.config.js b/tests/rspack-test/serialCases/async-library/1-use-library/rspack.config.js index 1d8496ba49e6..bd6fd9b6e213 100644 --- a/tests/rspack-test/serialCases/async-library/1-use-library/rspack.config.js +++ b/tests/rspack-test/serialCases/async-library/1-use-library/rspack.config.js @@ -12,7 +12,6 @@ module.exports = (env, { testPath }) => ({ } }, experiments: { - topLevelAwait: true, outputModule: true } }); diff --git a/website/docs/en/config/deprecated-options.mdx b/website/docs/en/config/deprecated-options.mdx index 921a4bcaa104..d5186c6dfa96 100644 --- a/website/docs/en/config/deprecated-options.mdx +++ b/website/docs/en/config/deprecated-options.mdx @@ -35,39 +35,6 @@ This configuration has been deprecated. Use top-level [`collectTypeScriptInfo`]( ::: -## experiments.topLevelAwait - -- **Type:** `boolean` -- **Default:** `true` - -Enables support for [Top-level await](https://github.com/tc39/proposal-top-level-await). Top-level await can only be used in modules with [ModuleType](/config/module-rules#rulestype) set to `javascript/esm`. - -Enabled by default. Can be disabled with this configuration: - -```js title="rspack.config.mjs" -export default { - experiments: { - topLevelAwait: false, - }, -}; -``` - -:::warning -This option has been deprecated and will be removed in Rspack v2.0. - -Top-level await will always be enabled in the future. Remove this option from your Rspack configuration. -::: - -## experiments.lazyCompilation - - - -Used to enable lazy compilation. - -:::warning -This configuration has been deprecated. Use [lazyCompilation](/config/lazy-compilation) instead. -::: - ## experiments.layers diff --git a/website/docs/zh/config/deprecated-options.mdx b/website/docs/zh/config/deprecated-options.mdx index 6a10d7995b1b..f079281c3496 100644 --- a/website/docs/zh/config/deprecated-options.mdx +++ b/website/docs/zh/config/deprecated-options.mdx @@ -35,39 +35,6 @@ import { ApiMeta } from '../../../components/ApiMeta'; ::: -## experiments.topLevelAwait - -- **类型:** `boolean` -- **默认值:** `true` - -开启打包 [Top-level await](https://github.com/tc39/proposal-top-level-await) 的支持,`Top-level await` 仅能在 [ModuleType](/config/module-rules#rulestype) 为 `javascript/esm` 的模块中使用。 - -默认开启,可通过该配置关闭: - -```js title="rspack.config.mjs" -export default { - experiments: { - topLevelAwait: false, - }, -}; -``` - -:::warning -该配置项已经废弃,将在 Rspack v2.0 中被移除。 - -未来 `Top-level await` 特性将会始终开启,请从 Rspack 配置中移除此选项。 -::: - -## experiments.lazyCompilation - - - -用于开启懒编译。 - -:::warning -该配置项已经废弃,请使用 [lazyCompilation](/config/lazy-compilation) 替代此项。 -::: - ## experiments.layers