diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 3bae526122c..03b8da5f7ad 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -1138,7 +1138,6 @@ export interface RawResolveTsconfigOptions { export interface RawRspackFuture { newTreeshaking: boolean - disableTransformByDefault: boolean } export interface RawRuleSetCondition { diff --git a/crates/rspack/tests/fixtures/simple-with-query/b.js b/crates/rspack/tests/fixtures/simple-with-query/b.js deleted file mode 100644 index 84c67edefbd..00000000000 --- a/crates/rspack/tests/fixtures/simple-with-query/b.js +++ /dev/null @@ -1 +0,0 @@ -export const a = 3; diff --git a/crates/rspack/tests/fixtures/simple-with-query/b.jsx b/crates/rspack/tests/fixtures/simple-with-query/b.jsx deleted file mode 100644 index 84c67edefbd..00000000000 --- a/crates/rspack/tests/fixtures/simple-with-query/b.jsx +++ /dev/null @@ -1 +0,0 @@ -export const a = 3; diff --git a/crates/rspack/tests/fixtures/simple-with-query/index.js b/crates/rspack/tests/fixtures/simple-with-query/index.js deleted file mode 100644 index d87104e4377..00000000000 --- a/crates/rspack/tests/fixtures/simple-with-query/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import { a as b } from "./b.jsx"; -import { a } from "./b.js?x"; -a; -b; -console.log("hello, world"); diff --git a/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap b/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap deleted file mode 100644 index e81b0e9e81a..00000000000 --- a/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap +++ /dev/null @@ -1,40 +0,0 @@ ---- -source: crates/rspack_testing/src/run_fixture.rs ---- -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./b.js?x": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); - const a = 3; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _b_jsx__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./b.jsx */"./b.jsx"); -/* harmony import */var _b_js_x__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./b.js?x */"./b.js?x"); - - -_b_js_x__WEBPACK_IMPORTED_MODULE_1__.a; -_b_jsx__WEBPACK_IMPORTED_MODULE_0__.a; -console.log("hello, world"); -}), -"./b.jsx": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); - const a = 3; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/antd/index.ts b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/antd/index.js similarity index 100% rename from crates/rspack/tests/tree-shaking/cjs-export-computed-property/antd/index.ts rename to crates/rspack/tests/tree-shaking/cjs-export-computed-property/antd/index.js diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/index.ts b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/index.js similarity index 100% rename from crates/rspack/tests/tree-shaking/cjs-export-computed-property/index.ts rename to crates/rspack/tests/tree-shaking/cjs-export-computed-property/index.js diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/locale_zh.ts b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/locale_zh.js similarity index 100% rename from crates/rspack/tests/tree-shaking/cjs-export-computed-property/locale_zh.ts rename to crates/rspack/tests/tree-shaking/cjs-export-computed-property/locale_zh.js diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap index dff70ef8739..66830354334 100644 --- a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap @@ -3,38 +3,28 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./zh_locale.js": (function (__unused_webpack_module, exports) { -var __webpack_unused_export__; -"use strict"; -__webpack_unused_export__ = ({ - value: true -}); -exports["default"] = void 0; -/* eslint-disable no-template-curly-in-string */ var _default = {}; -exports["default"] = _default; -}), -"./antd/index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./antd/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { locales: function() { return locales; } }); -/* harmony import */var _locale_zh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../locale_zh */"./locale_zh.ts"); +/* harmony import */var _locale_zh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../locale_zh */"./locale_zh.js"); const locales = { zh_CN: _locale_zh__WEBPACK_IMPORTED_MODULE_0__["default"] }; }), -"./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./antd/index */"./antd/index.ts"); +/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./antd/index */"./antd/index.js"); _antd_index__WEBPACK_IMPORTED_MODULE_0__.locales.zh_CN; function test() {} }), -"./locale_zh.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./locale_zh.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -44,10 +34,20 @@ __webpack_require__.d(__webpack_exports__, { var __WEBPACK_DEFAULT_EXPORT__ = _zh_locale__WEBPACK_IMPORTED_MODULE_0__["default"]; }), +"./zh_locale.js": (function (__unused_webpack_module, exports) { +var __webpack_unused_export__; +"use strict"; +__webpack_unused_export__ = ({ + value: true +}); +exports["default"] = void 0; +/* eslint-disable no-template-curly-in-string */ var _default = {}; +exports["default"] = _default; +}), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.ts")); +var __webpack_exports__ = (__webpack_exec__("./index.js")); } ]); diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/output.snap b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/output.snap index 8f53dd416ef..c9566710442 100644 --- a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/output.snap @@ -3,40 +3,31 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./zh_locale.js": (function (__unused_webpack_module, exports) { -"use strict"; -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports["default"] = void 0; -/* eslint-disable no-template-curly-in-string */ var _default = {}; -exports["default"] = _default; -}), -"./antd/index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./antd/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { locales: function() { return locales; } }); -/* harmony import */var _locale_zh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../locale_zh */"./locale_zh.ts"); +/* harmony import */var _locale_zh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../locale_zh */"./locale_zh.js"); const locales = { zh_CN: _locale_zh__WEBPACK_IMPORTED_MODULE_0__["default"] }; }), -"./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { test: function() { return test; } }); -/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./antd/index */"./antd/index.ts"); +/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./antd/index */"./antd/index.js"); _antd_index__WEBPACK_IMPORTED_MODULE_0__.locales.zh_CN; function test() {} }), -"./locale_zh.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./locale_zh.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -46,10 +37,19 @@ __webpack_require__.d(__webpack_exports__, { var __WEBPACK_DEFAULT_EXPORT__ = _zh_locale__WEBPACK_IMPORTED_MODULE_0__["default"]; }), +"./zh_locale.js": (function (__unused_webpack_module, exports) { +"use strict"; +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports["default"] = void 0; +/* eslint-disable no-template-curly-in-string */ var _default = {}; +exports["default"] = _default; +}), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.ts")); +var __webpack_exports__ = (__webpack_exec__("./index.js")); } ]); diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff index a3710b30348..3af88994c77 100644 --- a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff @@ -1,8 +1,18 @@ --- expected +++ actual -@@ -4,10 +4,11 @@ - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +@@ -19,9 +19,6 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- test: function() { return test; } +-}); + /* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./antd/index */"./antd/index.js"); + + _antd_index__WEBPACK_IMPORTED_MODULE_0__.locales.zh_CN; +@@ -38,10 +35,11 @@ + var __WEBPACK_DEFAULT_EXPORT__ = _zh_locale__WEBPACK_IMPORTED_MODULE_0__["default"]; + }), "./zh_locale.js": (function (__unused_webpack_module, exports) { +var __webpack_unused_export__; "use strict"; @@ -14,13 +24,3 @@ exports["default"] = void 0; /* eslint-disable no-template-curly-in-string */ var _default = {}; exports["default"] = _default; -@@ -28,9 +29,6 @@ - "./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - "use strict"; - __webpack_require__.r(__webpack_exports__); --__webpack_require__.d(__webpack_exports__, { -- test: function() { return test; } --}); - /* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./antd/index */"./antd/index.ts"); - - _antd_index__WEBPACK_IMPORTED_MODULE_0__.locales.zh_CN; diff --git a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/new_treeshaking.snap index 4283ab50ff2..b0c610197e1 100644 --- a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/new_treeshaking.snap @@ -7,69 +7,26 @@ source: crates/rspack_testing/src/run_fixture.rs __webpack_require__(/*! ./source */"./source/index.js"); console.log('something'); }), -"./source/index.js": (function (module, __unused_webpack_exports, __webpack_require__) { -var _class_call_check = __webpack_require__(/*! @swc/helpers/_/_class_call_check */"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js"); -var _create_class = __webpack_require__(/*! @swc/helpers/_/_create_class */"../../../../../node_modules/@swc/helpers/esm/_create_class.js"); -var Response = function() { - "use strict"; - function Response(mode) { - _class_call_check._(this, Response); +"./source/index.js": (function (module) { +class Response { + /** + * @param {CompiledMode} mode + */ constructor(mode){ // eslint-disable-next-line no-undefined if (mode.data === undefined) mode.data = {}; this.data = mode.data; this.isMatchIgnored = false; } - _create_class._(Response, [ - { - key: "ignoreMatch", - value: function ignoreMatch() { - this.isMatchIgnored = true; - } - } - ]); - return Response; -}(); + ignoreMatch() { + this.isMatchIgnored = true; + } +} function test() { - var res = new Response(); + let res = new Response(); return res; } -var result = test(); +const result = test(); module.exports = result; -}), -"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _class_call_check; }, - _class_call_check: function() { return _class_call_check; } -}); - function _class_call_check(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); -} - -}), -"../../../../../node_modules/@swc/helpers/esm/_create_class.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _create_class; }, - _create_class: function() { return _create_class; } -}); -function _defineProperties(target, props) { - for(var i = 0; i < props.length; i++){ - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } -} - function _create_class(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; -} - }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/output.snap b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/output.snap index 4283ab50ff2..b0c610197e1 100644 --- a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/output.snap @@ -7,69 +7,26 @@ source: crates/rspack_testing/src/run_fixture.rs __webpack_require__(/*! ./source */"./source/index.js"); console.log('something'); }), -"./source/index.js": (function (module, __unused_webpack_exports, __webpack_require__) { -var _class_call_check = __webpack_require__(/*! @swc/helpers/_/_class_call_check */"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js"); -var _create_class = __webpack_require__(/*! @swc/helpers/_/_create_class */"../../../../../node_modules/@swc/helpers/esm/_create_class.js"); -var Response = function() { - "use strict"; - function Response(mode) { - _class_call_check._(this, Response); +"./source/index.js": (function (module) { +class Response { + /** + * @param {CompiledMode} mode + */ constructor(mode){ // eslint-disable-next-line no-undefined if (mode.data === undefined) mode.data = {}; this.data = mode.data; this.isMatchIgnored = false; } - _create_class._(Response, [ - { - key: "ignoreMatch", - value: function ignoreMatch() { - this.isMatchIgnored = true; - } - } - ]); - return Response; -}(); + ignoreMatch() { + this.isMatchIgnored = true; + } +} function test() { - var res = new Response(); + let res = new Response(); return res; } -var result = test(); +const result = test(); module.exports = result; -}), -"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _class_call_check; }, - _class_call_check: function() { return _class_call_check; } -}); - function _class_call_check(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); -} - -}), -"../../../../../node_modules/@swc/helpers/esm/_create_class.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _create_class; }, - _create_class: function() { return _create_class; } -}); -function _defineProperties(target, props) { - for(var i = 0; i < props.length; i++){ - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } -} - function _create_class(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; -} - }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/index.ts b/crates/rspack/tests/tree-shaking/ts-target-es5/index.js similarity index 100% rename from crates/rspack/tests/tree-shaking/ts-target-es5/index.ts rename to crates/rspack/tests/tree-shaking/ts-target-es5/index.js diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap index b3f8deeb29f..4e938081b91 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap @@ -3,499 +3,16 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _async_to_generator; } -}); -function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { - try { - var info = gen[key](arg); - var value = info.value; - } catch (error) { - reject(error); - return; - } - if (info.done) resolve(value); - else Promise.resolve(value).then(_next, _throw); -} - function _async_to_generator(fn) { - return function() { - var self = this, args = arguments; - return new Promise(function(resolve, reject) { - var gen = fn.apply(self, args); - function _next(value) { - asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); - } - function _throw(err) { - asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); - } - _next(undefined); - }); - }; -} - -}), -"../../../../../node_modules/tslib/tslib.es6.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - __generator: function() { return __generator; } -}); -/****************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { - extendStatics = Object.setPrototypeOf || ({ - __proto__: [] - }) instanceof Array && function(d, b) { - d.__proto__ = b; - } || function(d, b) { - for(var p in b)if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; - }; - return extendStatics(d, b); -}; - function __extends(d, b) { - if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { - this.constructor = d; - } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -} - var __assign = function() { - __assign = Object.assign || function __assign(t) { - for(var s, i = 1, n = arguments.length; i < n; i++){ - s = arguments[i]; - for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; - function __rest(s, e) { - var t = {}; - for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") { - for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; - } - return t; -} - function __decorate(decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -} - function __param(paramIndex, decorator) { - return function(target, key) { - decorator(target, key, paramIndex); - }; -} - function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { - function accept(f) { - if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); - return f; - } - var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; - var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; - var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); - var _, done = false; - for(var i = decorators.length - 1; i >= 0; i--){ - var context = {}; - for(var p in contextIn)context[p] = p === "access" ? {} : contextIn[p]; - for(var p in contextIn.access)context.access[p] = contextIn.access[p]; - context.addInitializer = function(f) { - if (done) throw new TypeError("Cannot add initializers after decoration has completed"); - extraInitializers.push(accept(f || null)); - }; - var result = (0, decorators[i])(kind === "accessor" ? { - get: descriptor.get, - set: descriptor.set - } : descriptor[key], context); - if (kind === "accessor") { - if (result === void 0) continue; - if (result === null || typeof result !== "object") throw new TypeError("Object expected"); - if (_ = accept(result.get)) descriptor.get = _; - if (_ = accept(result.set)) descriptor.set = _; - if (_ = accept(result.init)) initializers.push(_); - } else if (_ = accept(result)) { - if (kind === "field") initializers.push(_); - else descriptor[key] = _; - } - } - if (target) Object.defineProperty(target, contextIn.name, descriptor); - done = true; -} - function __runInitializers(thisArg, initializers, value) { - var useValue = arguments.length > 2; - for(var i = 0; i < initializers.length; i++)value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); - return useValue ? value : void 0; -} - function __propKey(x) { - return typeof x === "symbol" ? x : "".concat(x); -} - function __setFunctionName(f, name, prefix) { - if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; - return Object.defineProperty(f, "name", { - configurable: true, - value: prefix ? "".concat(prefix, " ", name) : name - }); -} - function __metadata(metadataKey, metadataValue) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); -} - function __awaiter(thisArg, _arguments, P, generator) { - function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); - }); - } - return new (P || (P = Promise))(function(resolve, reject) { - function fulfilled(value) { - try { - step(generator.next(value)); - } catch (e) { - reject(e); - } - } - function rejected(value) { - try { - step(generator["throw"](value)); - } catch (e) { - reject(e); - } - } - function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -} - function __generator(thisArg, body) { - var _ = { - label: 0, - sent: function() { - if (t[0] & 1) throw t[1]; - return t[1]; - }, - trys: [], - ops: [] - }, f, y, t, g; - return g = { - next: verb(0), - "throw": verb(1), - "return": verb(2) - }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { - return this; - }), g; - function verb(n) { - return function(v) { - return step([ - n, - v - ]); - }; - } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while(g && (g = 0, op[0] && (_ = 0)), _)try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [ - op[0] & 2, - t.value - ]; - switch(op[0]){ - case 0: - case 1: - t = op; - break; - case 4: - _.label++; - return { - value: op[1], - done: false - }; - case 5: - _.label++; - y = op[1]; - op = [ - 0 - ]; - continue; - case 7: - op = _.ops.pop(); - _.trys.pop(); - continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { - _ = 0; - continue; - } - if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { - _.label = op[1]; - break; - } - if (op[0] === 6 && _.label < t[1]) { - _.label = t[1]; - t = op; - break; - } - if (t && _.label < t[2]) { - _.label = t[2]; - _.ops.push(op); - break; - } - if (t[2]) _.ops.pop(); - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } catch (e) { - op = [ - 6, - e - ]; - y = 0; - } finally{ - f = t = 0; - } - if (op[0] & 5) throw op[1]; - return { - value: op[0] ? op[1] : void 0, - done: true - }; - } -} - var __createBinding = Object.create ? function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { - enumerable: true, - get: function() { - return m[k]; - } - }; - Object.defineProperty(o, k2, desc); -} : function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -}; - function __exportStar(m, o) { - for(var p in m)if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); -} - function __values(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function() { - if (o && i >= o.length) o = void 0; - return { - value: o && o[i++], - done: !o - }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -} - function __read(o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while((n === void 0 || n-- > 0) && !(r = i.next()).done)ar.push(r.value); - } catch (error) { - e = { - error: error - }; - } finally{ - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } finally{ - if (e) throw e.error; - } - } - return ar; -} -/** @deprecated */ function __spread() { - for(var ar = [], i = 0; i < arguments.length; i++)ar = ar.concat(__read(arguments[i])); - return ar; -} -/** @deprecated */ function __spreadArrays() { - for(var s = 0, i = 0, il = arguments.length; i < il; i++)s += arguments[i].length; - for(var r = Array(s), k = 0, i = 0; i < il; i++)for(var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)r[k] = a[j]; - return r; -} - function __spreadArray(to, from, pack) { - if (pack || arguments.length === 2) { - for(var i = 0, l = from.length, ar; i < l; i++)if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -} - function __await(v) { - return this instanceof __await ? (this.v = v, this) : new __await(v); -} - function __asyncGenerator(thisArg, _arguments, generator) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var g = generator.apply(thisArg, _arguments || []), i, q = []; - return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { - return this; - }, i; - function verb(n) { - if (g[n]) i[n] = function(v) { - return new Promise(function(a, b) { - q.push([ - n, - v, - a, - b - ]) > 1 || resume(n, v); - }); - }; - } - function resume(n, v) { - try { - step(g[n](v)); - } catch (e) { - settle(q[0][3], e); - } - } - function step(r) { - r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); - } - function fulfill(value) { - resume("next", value); - } - function reject(value) { - resume("throw", value); - } - function settle(f, v) { - if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); - } -} - function __asyncDelegator(o) { - var i, p; - return i = {}, verb("next"), verb("throw", function(e) { - throw e; - }), verb("return"), i[Symbol.iterator] = function() { - return this; - }, i; - function verb(n, f) { - i[n] = o[n] ? function(v) { - return (p = !p) ? { - value: __await(o[n](v)), - done: false - } : f ? f(v) : v; - } : f; - } -} - function __asyncValues(o) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var m = o[Symbol.asyncIterator], i; - return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { - return this; - }, i); - function verb(n) { - i[n] = o[n] && function(v) { - return new Promise(function(resolve, reject) { - v = o[n](v), settle(resolve, reject, v.done, v.value); - }); - }; - } - function settle(resolve, reject, d, v) { - Promise.resolve(v).then(function(v) { - resolve({ - value: v, - done: d - }); - }, reject); - } -} - function __makeTemplateObject(cooked, raw) { - if (Object.defineProperty) Object.defineProperty(cooked, "raw", { - value: raw - }); - else cooked.raw = raw; - return cooked; -} -var __setModuleDefault = Object.create ? function(o, v) { - Object.defineProperty(o, "default", { - enumerable: true, - value: v - }); -} : function(o, v) { - o["default"] = v; -}; - function __importStar(mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) { - for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; -} - function __importDefault(mod) { - return mod && mod.__esModule ? mod : { - default: mod - }; -} - function __classPrivateFieldGet(receiver, state, kind, f) { - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -} - function __classPrivateFieldSet(receiver, state, value, kind, f) { - if (kind === "m") throw new TypeError("Private method is not writable"); - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); - return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; -} - function __classPrivateFieldIn(state, receiver) { - if (receiver === null || typeof receiver !== "object" && typeof receiver !== "function") throw new TypeError("Cannot use 'in' operator on non-object"); - return typeof state === "function" ? receiver === state : state.has(receiver); -} -}), -"./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @swc/helpers/_/_async_to_generator */"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js"); -/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @swc/helpers/_/_ts_generator */"../../../../../node_modules/tslib/tslib.es6.js"); - - - function test() { - return _test.apply(this, arguments); -} -function _test() { - _test = (0, _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { - return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__.__generator)(this, function(_state) { - return [ - 2 - ]; - }); - }); - return _test.apply(this, arguments); -} + async function test() {} test(); }), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.ts")); +var __webpack_exports__ = (__webpack_exec__("./index.js")); } ]); diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/output.snap b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/output.snap index 0c0d606db2f..0d2e2c5f759 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/output.snap @@ -3,511 +3,19 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _async_to_generator; } -}); -function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { - try { - var info = gen[key](arg); - var value = info.value; - } catch (error) { - reject(error); - return; - } - if (info.done) resolve(value); - else Promise.resolve(value).then(_next, _throw); -} - function _async_to_generator(fn) { - return function() { - var self = this, args = arguments; - return new Promise(function(resolve, reject) { - var gen = fn.apply(self, args); - function _next(value) { - asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); - } - function _throw(err) { - asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); - } - _next(undefined); - }); - }; -} - -}), -"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return tslib__WEBPACK_IMPORTED_MODULE_0__.__generator; } -}); -/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */"../../../../../node_modules/tslib/tslib.es6.js"); - -}), -"../../../../../node_modules/tslib/tslib.es6.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - __generator: function() { return __generator; } -}); -/****************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { - extendStatics = Object.setPrototypeOf || ({ - __proto__: [] - }) instanceof Array && function(d, b) { - d.__proto__ = b; - } || function(d, b) { - for(var p in b)if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; - }; - return extendStatics(d, b); -}; - function __extends(d, b) { - if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { - this.constructor = d; - } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -} - var __assign = function() { - __assign = Object.assign || function __assign(t) { - for(var s, i = 1, n = arguments.length; i < n; i++){ - s = arguments[i]; - for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; - function __rest(s, e) { - var t = {}; - for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") { - for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; - } - return t; -} - function __decorate(decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -} - function __param(paramIndex, decorator) { - return function(target, key) { - decorator(target, key, paramIndex); - }; -} - function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { - function accept(f) { - if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); - return f; - } - var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; - var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; - var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); - var _, done = false; - for(var i = decorators.length - 1; i >= 0; i--){ - var context = {}; - for(var p in contextIn)context[p] = p === "access" ? {} : contextIn[p]; - for(var p in contextIn.access)context.access[p] = contextIn.access[p]; - context.addInitializer = function(f) { - if (done) throw new TypeError("Cannot add initializers after decoration has completed"); - extraInitializers.push(accept(f || null)); - }; - var result = (0, decorators[i])(kind === "accessor" ? { - get: descriptor.get, - set: descriptor.set - } : descriptor[key], context); - if (kind === "accessor") { - if (result === void 0) continue; - if (result === null || typeof result !== "object") throw new TypeError("Object expected"); - if (_ = accept(result.get)) descriptor.get = _; - if (_ = accept(result.set)) descriptor.set = _; - if (_ = accept(result.init)) initializers.push(_); - } else if (_ = accept(result)) { - if (kind === "field") initializers.push(_); - else descriptor[key] = _; - } - } - if (target) Object.defineProperty(target, contextIn.name, descriptor); - done = true; -} - function __runInitializers(thisArg, initializers, value) { - var useValue = arguments.length > 2; - for(var i = 0; i < initializers.length; i++)value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); - return useValue ? value : void 0; -} - function __propKey(x) { - return typeof x === "symbol" ? x : "".concat(x); -} - function __setFunctionName(f, name, prefix) { - if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; - return Object.defineProperty(f, "name", { - configurable: true, - value: prefix ? "".concat(prefix, " ", name) : name - }); -} - function __metadata(metadataKey, metadataValue) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); -} - function __awaiter(thisArg, _arguments, P, generator) { - function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); - }); - } - return new (P || (P = Promise))(function(resolve, reject) { - function fulfilled(value) { - try { - step(generator.next(value)); - } catch (e) { - reject(e); - } - } - function rejected(value) { - try { - step(generator["throw"](value)); - } catch (e) { - reject(e); - } - } - function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -} - function __generator(thisArg, body) { - var _ = { - label: 0, - sent: function() { - if (t[0] & 1) throw t[1]; - return t[1]; - }, - trys: [], - ops: [] - }, f, y, t, g; - return g = { - next: verb(0), - "throw": verb(1), - "return": verb(2) - }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { - return this; - }), g; - function verb(n) { - return function(v) { - return step([ - n, - v - ]); - }; - } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while(g && (g = 0, op[0] && (_ = 0)), _)try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [ - op[0] & 2, - t.value - ]; - switch(op[0]){ - case 0: - case 1: - t = op; - break; - case 4: - _.label++; - return { - value: op[1], - done: false - }; - case 5: - _.label++; - y = op[1]; - op = [ - 0 - ]; - continue; - case 7: - op = _.ops.pop(); - _.trys.pop(); - continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { - _ = 0; - continue; - } - if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { - _.label = op[1]; - break; - } - if (op[0] === 6 && _.label < t[1]) { - _.label = t[1]; - t = op; - break; - } - if (t && _.label < t[2]) { - _.label = t[2]; - _.ops.push(op); - break; - } - if (t[2]) _.ops.pop(); - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } catch (e) { - op = [ - 6, - e - ]; - y = 0; - } finally{ - f = t = 0; - } - if (op[0] & 5) throw op[1]; - return { - value: op[0] ? op[1] : void 0, - done: true - }; - } -} - var __createBinding = Object.create ? function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { - enumerable: true, - get: function() { - return m[k]; - } - }; - Object.defineProperty(o, k2, desc); -} : function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -}; - function __exportStar(m, o) { - for(var p in m)if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); -} - function __values(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function() { - if (o && i >= o.length) o = void 0; - return { - value: o && o[i++], - done: !o - }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -} - function __read(o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while((n === void 0 || n-- > 0) && !(r = i.next()).done)ar.push(r.value); - } catch (error) { - e = { - error: error - }; - } finally{ - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } finally{ - if (e) throw e.error; - } - } - return ar; -} -/** @deprecated */ function __spread() { - for(var ar = [], i = 0; i < arguments.length; i++)ar = ar.concat(__read(arguments[i])); - return ar; -} -/** @deprecated */ function __spreadArrays() { - for(var s = 0, i = 0, il = arguments.length; i < il; i++)s += arguments[i].length; - for(var r = Array(s), k = 0, i = 0; i < il; i++)for(var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)r[k] = a[j]; - return r; -} - function __spreadArray(to, from, pack) { - if (pack || arguments.length === 2) { - for(var i = 0, l = from.length, ar; i < l; i++)if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -} - function __await(v) { - return this instanceof __await ? (this.v = v, this) : new __await(v); -} - function __asyncGenerator(thisArg, _arguments, generator) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var g = generator.apply(thisArg, _arguments || []), i, q = []; - return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { - return this; - }, i; - function verb(n) { - if (g[n]) i[n] = function(v) { - return new Promise(function(a, b) { - q.push([ - n, - v, - a, - b - ]) > 1 || resume(n, v); - }); - }; - } - function resume(n, v) { - try { - step(g[n](v)); - } catch (e) { - settle(q[0][3], e); - } - } - function step(r) { - r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); - } - function fulfill(value) { - resume("next", value); - } - function reject(value) { - resume("throw", value); - } - function settle(f, v) { - if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); - } -} - function __asyncDelegator(o) { - var i, p; - return i = {}, verb("next"), verb("throw", function(e) { - throw e; - }), verb("return"), i[Symbol.iterator] = function() { - return this; - }, i; - function verb(n, f) { - i[n] = o[n] ? function(v) { - return (p = !p) ? { - value: __await(o[n](v)), - done: false - } : f ? f(v) : v; - } : f; - } -} - function __asyncValues(o) { - if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); - var m = o[Symbol.asyncIterator], i; - return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() { - return this; - }, i); - function verb(n) { - i[n] = o[n] && function(v) { - return new Promise(function(resolve, reject) { - v = o[n](v), settle(resolve, reject, v.done, v.value); - }); - }; - } - function settle(resolve, reject, d, v) { - Promise.resolve(v).then(function(v) { - resolve({ - value: v, - done: d - }); - }, reject); - } -} - function __makeTemplateObject(cooked, raw) { - if (Object.defineProperty) Object.defineProperty(cooked, "raw", { - value: raw - }); - else cooked.raw = raw; - return cooked; -} -var __setModuleDefault = Object.create ? function(o, v) { - Object.defineProperty(o, "default", { - enumerable: true, - value: v - }); -} : function(o, v) { - o["default"] = v; -}; - function __importStar(mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) { - for(var k in mod)if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; -} - function __importDefault(mod) { - return mod && mod.__esModule ? mod : { - default: mod - }; -} - function __classPrivateFieldGet(receiver, state, kind, f) { - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -} - function __classPrivateFieldSet(receiver, state, value, kind, f) { - if (kind === "m") throw new TypeError("Private method is not writable"); - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); - return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value; -} - function __classPrivateFieldIn(state, receiver) { - if (receiver === null || typeof receiver !== "object" && typeof receiver !== "function") throw new TypeError("Cannot use 'in' operator on non-object"); - return typeof state === "function" ? receiver === state : state.has(receiver); -} -}), -"./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { test: function() { return test; } }); -/* harmony import */var _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @swc/helpers/_/_async_to_generator */"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js"); -/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @swc/helpers/_/_ts_generator */"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js"); - - - function test() { - return _test.apply(this, arguments); -} -function _test() { - _test = (0, _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { - return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__._)(this, function(_state) { - return [ - 2 - ]; - }); - }); - return _test.apply(this, arguments); -} + async function test() {} test(); }), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.ts")); +var __webpack_exports__ = (__webpack_exec__("./index.js")); } ]); diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff index 04d52c3653e..e54d0a7d7bc 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff @@ -1,40 +1,12 @@ --- expected +++ actual -@@ -37,15 +37,6 @@ - } - - }), --"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --"use strict"; --__webpack_require__.r(__webpack_exports__); --__webpack_require__.d(__webpack_exports__, { -- _: function() { return tslib__WEBPACK_IMPORTED_MODULE_0__.__generator; } --}); --/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */"../../../../../node_modules/tslib/tslib.es6.js"); -- --}), - "../../../../../node_modules/tslib/tslib.es6.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - "use strict"; - __webpack_require__.r(__webpack_exports__); -@@ -482,11 +473,8 @@ - "./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -6,9 +6,6 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); - /* harmony import */var _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @swc/helpers/_/_async_to_generator */"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js"); --/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @swc/helpers/_/_ts_generator */"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js"); -+/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @swc/helpers/_/_ts_generator */"../../../../../node_modules/tslib/tslib.es6.js"); - - - function test() { -@@ -494,7 +482,7 @@ - } - function _test() { - _test = (0, _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { -- return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__._)(this, function(_state) { -+ return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__.__generator)(this, function(_state) { - return [ - 2 - ]; + async function test() {} + test(); + }), diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/test.config.json b/crates/rspack/tests/tree-shaking/ts-target-es5/test.config.json index 0b350c035dd..8a24d2060d9 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/test.config.json +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/test.config.json @@ -12,4 +12,4 @@ "process.env.NODE_ENV": "'development'" } } -} \ No newline at end of file +} diff --git a/crates/rspack_binding_options/src/options/raw_experiments.rs b/crates/rspack_binding_options/src/options/raw_experiments.rs index 69235f2f56b..f7c14572d56 100644 --- a/crates/rspack_binding_options/src/options/raw_experiments.rs +++ b/crates/rspack_binding_options/src/options/raw_experiments.rs @@ -15,7 +15,6 @@ pub struct RawIncrementalRebuild { #[napi(object)] pub struct RawRspackFuture { pub new_treeshaking: bool, - pub disable_transform_by_default: bool, } #[derive(Deserialize, Debug, Default)] @@ -32,7 +31,6 @@ impl From for RspackFuture { fn from(value: RawRspackFuture) -> Self { Self { new_treeshaking: value.new_treeshaking, - disable_transform_by_default: value.disable_transform_by_default, } } } diff --git a/crates/rspack_core/src/lib.rs b/crates/rspack_core/src/lib.rs index df6919a153d..506e1db9ef1 100644 --- a/crates/rspack_core/src/lib.rs +++ b/crates/rspack_core/src/lib.rs @@ -161,11 +161,6 @@ pub enum ModuleType { Js, JsDynamic, JsEsm, - Jsx, - JsxDynamic, - JsxEsm, - Tsx, - Ts, WasmSync, WasmAsync, AssetInline, @@ -189,8 +184,8 @@ impl ModuleType { pub fn is_js_like(&self) -> bool { matches!( self, - ModuleType::Js | ModuleType::JsEsm | ModuleType::JsDynamic | ModuleType::Ts - ) || self.is_jsx_like() + ModuleType::Js | ModuleType::JsEsm | ModuleType::JsDynamic + ) } pub fn is_asset_like(&self) -> bool { @@ -199,36 +194,21 @@ impl ModuleType { ModuleType::Asset | ModuleType::AssetInline | ModuleType::AssetResource ) } - pub fn is_jsx_like(&self) -> bool { - matches!( - self, - ModuleType::Tsx | ModuleType::Jsx | ModuleType::JsxEsm | ModuleType::JsxDynamic - ) - } pub fn is_wasm_like(&self) -> bool { matches!(self, ModuleType::WasmSync | ModuleType::WasmAsync) } pub fn is_js_auto(&self) -> bool { - matches!( - self, - ModuleType::Js | ModuleType::Jsx | ModuleType::Ts | ModuleType::Tsx - ) + matches!(self, ModuleType::Js) } pub fn is_js_esm(&self) -> bool { - matches!( - self, - ModuleType::JsEsm | ModuleType::JsxEsm | ModuleType::Ts | ModuleType::Tsx - ) + matches!(self, ModuleType::JsEsm) } pub fn is_js_dynamic(&self) -> bool { - matches!( - self, - ModuleType::JsDynamic | ModuleType::JsxDynamic | ModuleType::Ts | ModuleType::Tsx - ) + matches!(self, ModuleType::JsDynamic) } /// Webpack arbitrary determines the binary type from [NormalModule.binary](https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/NormalModule.js#L302) @@ -242,13 +222,6 @@ impl ModuleType { ModuleType::JsEsm => "javascript/esm", ModuleType::JsDynamic => "javascript/dynamic", - ModuleType::Jsx => "javascriptx", - ModuleType::JsxEsm => "javascriptx/esm", - ModuleType::JsxDynamic => "javascriptx/dynamic", - - ModuleType::Ts => "typescript", - ModuleType::Tsx => "typescriptx", - ModuleType::Css => "css", ModuleType::CssModule => "css/module", ModuleType::CssAuto => "css/auto", @@ -289,15 +262,6 @@ impl From<&str> for ModuleType { "js/dynamic" | "javascript/dynamic" => Self::JsDynamic, "js/esm" | "javascript/esm" => Self::JsEsm, - // TODO: remove in 0.5.0 - "jsx" | "javascriptx" | "jsx/auto" | "javascriptx/auto" => Self::Jsx, - "jsx/dynamic" | "javascriptx/dynamic" => Self::JsxDynamic, - "jsx/esm" | "javascriptx/esm" => Self::JsxEsm, - - // TODO: remove in 0.5.0 - "ts" | "typescript" => Self::Ts, - "tsx" | "typescriptx" => Self::Tsx, - "css" => Self::Css, "css/module" => Self::CssModule, "css/auto" => Self::CssAuto, diff --git a/crates/rspack_core/src/normal_module_factory.rs b/crates/rspack_core/src/normal_module_factory.rs index cf70236b9a6..0960752b8d5 100644 --- a/crates/rspack_core/src/normal_module_factory.rs +++ b/crates/rspack_core/src/normal_module_factory.rs @@ -593,18 +593,10 @@ impl NormalModuleFactory { .registered_parser_and_generator_builder .get(&resolved_module_type) .ok_or_else(|| { - let mut e = format!("Unexpected `ModuleType` found: {resolved_module_type}. "); - - match resolved_module_type { - ModuleType::Css => e.push_str( - "Setting `'css'` as the `Rule.type` is only possible with `experiments.css` set to `true`", - ), - ModuleType::Ts | ModuleType::Tsx | - ModuleType::Jsx | ModuleType::JsxDynamic | ModuleType::JsxEsm => e.push_str("`Rule.type` that are not supported by webpack is deprecated. See: https://github.com/web-infra-dev/rspack/discussions/4070"), - _ => (), - } - - internal_error!(e) + internal_error!( + "No parser registered for '{}'", + resolved_module_type.as_str() + ) })?(); let mut create_data = NormalModuleCreateData { diff --git a/crates/rspack_core/src/options/compiler_options.rs b/crates/rspack_core/src/options/compiler_options.rs index 3bcd401b1e8..724eb7389ef 100644 --- a/crates/rspack_core/src/options/compiler_options.rs +++ b/crates/rspack_core/src/options/compiler_options.rs @@ -43,12 +43,4 @@ impl CompilerOptions { pub fn is_new_tree_shaking(&self) -> bool { self.experiments.rspack_future.new_treeshaking } - - /// This controls whether we're using the old Rspack behavior to transform a module. - /// - `true`: use the old strategy, and transform the non web standard modules into a standardized one. - /// `Rule.type` that are not supported by webpack is not usable. - /// - `false`: use the new strategy, only web-standard modules are supported. - pub fn should_transform_by_default(&self) -> bool { - !self.experiments.rspack_future.disable_transform_by_default - } } diff --git a/crates/rspack_core/src/options/experiments.rs b/crates/rspack_core/src/options/experiments.rs index 2a1873a313c..43f3338fb74 100644 --- a/crates/rspack_core/src/options/experiments.rs +++ b/crates/rspack_core/src/options/experiments.rs @@ -24,7 +24,6 @@ impl IncrementalRebuildMakeState { #[derive(Debug, Default)] pub struct RspackFuture { pub new_treeshaking: bool, - pub disable_transform_by_default: bool, } #[derive(Debug, Default)] diff --git a/crates/rspack_core/src/tree_shaking/optimizer.rs b/crates/rspack_core/src/tree_shaking/optimizer.rs index 7ec8b5980dc..af5e6cd39d5 100644 --- a/crates/rspack_core/src/tree_shaking/optimizer.rs +++ b/crates/rspack_core/src/tree_shaking/optimizer.rs @@ -1567,14 +1567,7 @@ fn is_js_like_uri(uri: &str) -> bool { match resolve_module_type_by_uri(uri) { Some(module_type) => matches!( module_type, - crate::ModuleType::Js - | crate::ModuleType::JsDynamic - | crate::ModuleType::JsEsm - | crate::ModuleType::Jsx - | crate::ModuleType::JsxDynamic - | crate::ModuleType::JsxEsm - | crate::ModuleType::Tsx - | crate::ModuleType::Ts + crate::ModuleType::Js | crate::ModuleType::JsDynamic | crate::ModuleType::JsEsm ), None => false, } diff --git a/crates/rspack_error/tests/fixtures/jsx_syntax_error/fixtures__jsx_syntax_error.snap b/crates/rspack_error/tests/fixtures/jsx_syntax_error/fixtures__jsx_syntax_error.snap deleted file mode 100644 index 3e6c02d7f80..00000000000 --- a/crates/rspack_error/tests/fixtures/jsx_syntax_error/fixtures__jsx_syntax_error.snap +++ /dev/null @@ -1,29 +0,0 @@ ---- -source: crates/rspack_error/tests/fixtures.rs -expression: jsx_syntax_error ---- -ModuleParseError - - × Module parse failed: - ╰─▶ × JSX parsing error - ╭──── - 1 │ let a = /test>; - · ▲ - · ╰── Unexpected token. Did you mean `{'>'}` or `>`? - ╰──── - - help: - You may need an appropriate loader to handle this file type. -ModuleParseError - - × Module parse failed: - ╰─▶ × JSX parsing error - ╭──── - 1 │ let a = /test>; - · ▲ - · ╰── Unexpected eof - ╰──── - - help: - You may need an appropriate loader to handle this file type. - diff --git a/crates/rspack_error/tests/fixtures/jsx_syntax_error/index.js b/crates/rspack_error/tests/fixtures/jsx_syntax_error/index.js deleted file mode 100644 index de6527c989f..00000000000 --- a/crates/rspack_error/tests/fixtures/jsx_syntax_error/index.js +++ /dev/null @@ -1 +0,0 @@ -import test from "./index.jsx"; diff --git a/crates/rspack_error/tests/fixtures/jsx_syntax_error/index.jsx b/crates/rspack_error/tests/fixtures/jsx_syntax_error/index.jsx deleted file mode 100644 index 3ffa8447758..00000000000 --- a/crates/rspack_error/tests/fixtures/jsx_syntax_error/index.jsx +++ /dev/null @@ -1 +0,0 @@ -let a = /test>; diff --git a/crates/rspack_error/tests/fixtures/recoverable_syntax_error/fixtures__recoverable_syntax_error.snap b/crates/rspack_error/tests/fixtures/recoverable_syntax_error/fixtures__recoverable_syntax_error.snap index a5d4e12ff2f..a1fd80b2728 100644 --- a/crates/rspack_error/tests/fixtures/recoverable_syntax_error/fixtures__recoverable_syntax_error.snap +++ b/crates/rspack_error/tests/fixtures/recoverable_syntax_error/fixtures__recoverable_syntax_error.snap @@ -5,11 +5,11 @@ expression: recoverable_syntax_error ModuleParseError × Module parse failed: - ╰─▶ × TSX parsing error + ╰─▶ × JavaScript parsing error ╭──── 1 │ let c = () => {}; - · ┬ - · ╰── Expression expected + · ─┬ + · ╰── An arrow function is not allowed here ╰──── help: @@ -17,11 +17,11 @@ ModuleParseError ModuleParseError × Module parse failed: - ╰─▶ × TSX parsing error + ╰─▶ × JavaScript parsing error ╭──── 1 │ let c = () => {}; - · ┬ - · ╰── Expected a semicolon + · ┬ + · ╰── Expression expected ╰──── help: diff --git a/crates/rspack_error/tests/fixtures/ts_syntax_error/fixtures__ts_syntax_error.snap b/crates/rspack_error/tests/fixtures/ts_syntax_error/fixtures__ts_syntax_error.snap deleted file mode 100644 index 1816944c915..00000000000 --- a/crates/rspack_error/tests/fixtures/ts_syntax_error/fixtures__ts_syntax_error.snap +++ /dev/null @@ -1,20 +0,0 @@ ---- -source: crates/rspack_error/tests/fixtures.rs -expression: ts_syntax_error ---- -ModuleParseError - - × Module parse failed: - ╰─▶ × Typescript parsing error - ╭─[3:1] - 3 │ // Comma is required, but parser can recover because of the newline. - 4 │ d = 10 - 5 │ g = CONST - · ┬ - · ╰── Expected ',', got 'g' - 6 │ } - ╰──── - - help: - You may need an appropriate loader to handle this file type. - diff --git a/crates/rspack_error/tests/fixtures/ts_syntax_error/index.ts b/crates/rspack_error/tests/fixtures/ts_syntax_error/index.ts deleted file mode 100644 index 87ed5ba9acc..00000000000 --- a/crates/rspack_error/tests/fixtures/ts_syntax_error/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -const CONST = 9000 % 2; -const enum D { - // Comma is required, but parser can recover because of the newline. - d = 10 - g = CONST -} \ No newline at end of file diff --git a/crates/rspack_error/tests/fixtures/tsx_syntax_error/fixtures__tsx_syntax_error.snap b/crates/rspack_error/tests/fixtures/tsx_syntax_error/fixtures__tsx_syntax_error.snap deleted file mode 100644 index 771bee89fcd..00000000000 --- a/crates/rspack_error/tests/fixtures/tsx_syntax_error/fixtures__tsx_syntax_error.snap +++ /dev/null @@ -1,17 +0,0 @@ ---- -source: crates/rspack_error/tests/fixtures.rs -expression: tsx_syntax_error ---- -ModuleParseError - - × Module parse failed: - ╰─▶ × TSX parsing error - ╭──── - 1 │ let c = /test>; - · ──┬─ - · ╰── Unexpected token `test`. Expected jsx identifier - ╰──── - - help: - You may need an appropriate loader to handle this file type. - diff --git a/crates/rspack_error/tests/fixtures/tsx_syntax_error/index.tsx b/crates/rspack_error/tests/fixtures/tsx_syntax_error/index.tsx deleted file mode 100644 index 42c5006b8c9..00000000000 --- a/crates/rspack_error/tests/fixtures/tsx_syntax_error/index.tsx +++ /dev/null @@ -1 +0,0 @@ -let c = /test>; diff --git a/crates/rspack_loader_swc/tests/fixtures/esm/test.config.json b/crates/rspack_loader_swc/tests/fixtures/esm/test.config.json index 4d5f0504ba9..3e39f9f31a6 100644 --- a/crates/rspack_loader_swc/tests/fixtures/esm/test.config.json +++ b/crates/rspack_loader_swc/tests/fixtures/esm/test.config.json @@ -11,8 +11,7 @@ "loader": "builtin:swc-loader", "options": " {\n \"jsc\": {\n \"target\": \"es2015\",\n \"parser\": {\n \"syntax\": \"ecmascript\",\n \"jsx\": true,\n \"dynamicImport\": true,\n \"classProperty\": true,\n \"exportNamespaceFrom\": true,\n \"exportDefaultFrom\": true\n }\n }\n }" } - ], - "type": "jsx" + ] } ] }, diff --git a/crates/rspack_plugin_dev_friendly_split_chunks/src/plugin.rs b/crates/rspack_plugin_dev_friendly_split_chunks/src/plugin.rs index 69a313f4152..c27e6766c7a 100644 --- a/crates/rspack_plugin_dev_friendly_split_chunks/src/plugin.rs +++ b/crates/rspack_plugin_dev_friendly_split_chunks/src/plugin.rs @@ -252,11 +252,6 @@ impl EstimatedSize for T { fn estimated_size(&self, source_type: &rspack_core::SourceType) -> f64 { use rspack_core::ModuleType; let coefficient: f64 = match self.module_type() { - // 5.0 is a number in practice - rspack_core::ModuleType::Jsx - | ModuleType::JsxDynamic - | ModuleType::JsxEsm - | ModuleType::Tsx => 7.5, ModuleType::Js | ModuleType::JsDynamic => 1.5, _ => 1.0, }; diff --git a/crates/rspack_plugin_javascript/src/ast/parse.rs b/crates/rspack_plugin_javascript/src/ast/parse.rs index 77407f3d2d1..4645ae0e020 100644 --- a/crates/rspack_plugin_javascript/src/ast/parse.rs +++ b/crates/rspack_plugin_javascript/src/ast/parse.rs @@ -17,8 +17,8 @@ use crate::IsModule; fn module_type_to_is_module(value: &ModuleType) -> IsModule { // parser options align with webpack match value { - ModuleType::JsEsm | ModuleType::JsxEsm => IsModule::Bool(true), - ModuleType::JsDynamic | ModuleType::JsxDynamic => IsModule::Bool(false), + ModuleType::JsEsm => IsModule::Bool(true), + ModuleType::JsDynamic => IsModule::Bool(false), _ => IsModule::Unknown, } } diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index d213499136e..8a65ba55eae 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -15,10 +15,10 @@ use rspack_core::{ use rspack_error::miette::Diagnostic; use rspack_error::{DiagnosticExt, IntoTWithDiagnosticArray, Result, TWithDiagnosticArray}; use swc_core::common::SyntaxContext; +use swc_core::ecma::parser::{EsConfig, Syntax}; use crate::ast::CodegenOptions; use crate::inner_graph_plugin::InnerGraphPlugin; -use crate::utils::syntax_by_module_type; use crate::visitors::ScanDependenciesResult; use crate::visitors::{run_before_pass, scan_dependencies, swc_visitor::resolver}; use crate::{SideEffectsFlagPluginVisitor, SyntaxContextInfo}; @@ -95,12 +95,14 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { .. } = parse_context; let mut diagnostics: Vec> = vec![]; - let syntax = syntax_by_module_type( - &resource_data.resource_path, - module_type, - compiler_options.builtins.decorator.is_some(), - compiler_options.should_transform_by_default(), - ); + let syntax = Syntax::Es(EsConfig { + jsx: false, + export_default_from: false, + decorators: false, + fn_bind: true, + allow_super_outside_method: true, + ..Default::default() + }); let use_source_map = compiler_options.devtool.enabled(); let use_simple_source_map = compiler_options.devtool.source_map(); let original_map = source.map(&MapOptions::new(!compiler_options.devtool.cheap())); @@ -144,15 +146,7 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { } }; - run_before_pass( - resource_data, - &mut ast, - compiler_options, - syntax, - build_info, - module_type, - &source, - )?; + run_before_pass(&mut ast, compiler_options)?; let output: crate::TransformOutput = crate::ast::stringify( &ast, @@ -178,7 +172,7 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { program.visit_mut_with(&mut resolver( context.unresolved_mark, context.top_level_mark, - compiler_options.should_transform_by_default() && syntax.typescript(), + false, )); }); diff --git a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs index f2370e26119..7e6b5202344 100644 --- a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs @@ -25,34 +25,11 @@ impl Plugin for JsPlugin { fn apply( &self, ctx: PluginContext<&mut rspack_core::ApplyContext>, - options: &mut CompilerOptions, + _options: &mut CompilerOptions, ) -> Result<()> { let create_parser_and_generator = move || Box::new(JavaScriptParserAndGenerator::new()) as Box; - if options.should_transform_by_default() { - ctx.context.register_parser_and_generator_builder( - ModuleType::Ts, - Box::new(create_parser_and_generator), - ); - ctx.context.register_parser_and_generator_builder( - ModuleType::Tsx, - Box::new(create_parser_and_generator), - ); - ctx.context.register_parser_and_generator_builder( - ModuleType::Jsx, - Box::new(create_parser_and_generator), - ); - ctx.context.register_parser_and_generator_builder( - ModuleType::JsxEsm, - Box::new(create_parser_and_generator), - ); - ctx.context.register_parser_and_generator_builder( - ModuleType::JsxDynamic, - Box::new(create_parser_and_generator), - ); - } - ctx .context .register_parser_and_generator_builder(ModuleType::Js, Box::new(create_parser_and_generator)); diff --git a/crates/rspack_plugin_javascript/src/utils/mod.rs b/crates/rspack_plugin_javascript/src/utils/mod.rs index 1ffde28cbac..070c0a85bc7 100644 --- a/crates/rspack_plugin_javascript/src/utils/mod.rs +++ b/crates/rspack_plugin_javascript/src/utils/mod.rs @@ -3,92 +3,14 @@ pub mod eval; mod get_prop_from_obj; pub mod mangle_exports; -use std::path::Path; - use rspack_core::{ErrorSpan, ModuleType}; use rspack_error::{DiagnosticKind, TraceableError}; use rustc_hash::FxHashSet as HashSet; use swc_core::common::{SourceFile, Span, Spanned}; -use swc_core::ecma::parser::Syntax; -use swc_core::ecma::parser::{EsConfig, TsConfig}; pub use self::get_prop_from_obj::*; pub use self::r#const::*; -fn syntax_by_ext( - filename: &Path, - enable_decorators: bool, - should_transform_by_default: bool, -) -> Syntax { - // swc_core::base::Compiler::process_js_with_custom_pass() - let ext = filename - .extension() - .and_then(|ext| ext.to_str()) - .unwrap_or("js"); - match ext == "ts" || ext == "tsx" { - true => { - let filename = filename.to_string_lossy(); - Syntax::Typescript(TsConfig { - decorators: enable_decorators, - tsx: ext == "tsx", - dts: filename.ends_with(".d.ts") || filename.ends_with(".d.tsx"), - ..Default::default() - }) - } - false => Syntax::Es(EsConfig { - jsx: ext == "jsx", - export_default_from: true, - decorators_before_export: true, - decorators: should_transform_by_default && enable_decorators, - fn_bind: true, - allow_super_outside_method: true, - ..Default::default() - }), - } -} - -pub fn syntax_by_module_type( - filename: &Path, - module_type: &ModuleType, - enable_decorators: bool, - should_transform_by_default: bool, -) -> Syntax { - let js_syntax = Syntax::Es(EsConfig { - jsx: should_transform_by_default && matches!(module_type, ModuleType::Jsx), - export_default_from: false, - decorators_before_export: true, - // If `disableTransformByDefault` is on, then we treat everything passed in as a web standard stuff, - // which means everything that is not a web standard would results in a parsing error. - // So as the decorator. - decorators: should_transform_by_default && enable_decorators, - fn_bind: true, - allow_super_outside_method: true, - ..Default::default() - }); - - // Legacy behavior: `ts`, `tsx`, etc. - if should_transform_by_default { - return match module_type { - ModuleType::Js | ModuleType::Jsx => js_syntax, - ModuleType::Ts | ModuleType::Tsx => { - let filename = filename.to_string_lossy(); - Syntax::Typescript(TsConfig { - // `disableTransformByDefault` will not affect TypeScript-like modules, - // as we are following standard of TypeScript compiler. - // This is not a web standard by all means. - decorators: enable_decorators, - tsx: matches!(module_type, ModuleType::Tsx), - dts: filename.ends_with(".d.ts") || filename.ends_with(".d.tsx"), - ..Default::default() - }) - } - _ => syntax_by_ext(filename, enable_decorators, should_transform_by_default), - }; - } - - js_syntax -} - #[derive(PartialEq, Eq, Hash)] pub struct EcmaError(String, Span); pub struct EcmaErrorsDeduped(Vec); @@ -135,10 +57,7 @@ pub fn ecma_parse_error_deduped_to_rspack_error( ModuleType::Js | ModuleType::JsDynamic | ModuleType::JsEsm => { ("JavaScript", DiagnosticKind::JavaScript) } - ModuleType::Jsx | ModuleType::JsxDynamic | ModuleType::JsxEsm => ("JSX", DiagnosticKind::Jsx), - ModuleType::Tsx => ("TSX", DiagnosticKind::Tsx), - ModuleType::Ts => ("Typescript", DiagnosticKind::Typescript), - _ => unreachable!(), + _ => unreachable!("Only JavaScript module type is supported"), }; let span: ErrorSpan = span.into(); rspack_error::TraceableError::from_source_file( diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs index 8535f2c7fd9..2d3566044ee 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs @@ -67,7 +67,7 @@ impl Visit for CommonJsExportDependencyScanner<'_> { noop_visit_type!(); fn visit_program(&mut self, program: &Program) { - self.is_harmony = matches!(self.module_type, ModuleType::JsEsm | ModuleType::JsxEsm) + self.is_harmony = matches!(self.module_type, ModuleType::JsEsm) || matches!(program, Program::Module(module) if module.body.iter().any(|s| matches!(s, ModuleItem::ModuleDecl(_)))); program.visit_children_with(self); } diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_detection_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_detection_scanner.rs index ba1b78e8d16..c281c7576ba 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_detection_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_detection_scanner.rs @@ -46,7 +46,7 @@ impl Visit for HarmonyDetectionScanner<'_> { noop_visit_type!(); fn visit_program(&mut self, program: &'_ Program) { - let strict_harmony_module = matches!(self.module_type, ModuleType::JsEsm | ModuleType::JsxEsm); + let strict_harmony_module = matches!(self.module_type, ModuleType::JsEsm); let is_harmony = matches!(program, Program::Module(module) if module.body.iter().any(|s| matches!(s, ModuleItem::ModuleDecl(_)))); diff --git a/crates/rspack_plugin_javascript/src/visitors/mod.rs b/crates/rspack_plugin_javascript/src/visitors/mod.rs index 1eaf65cfc03..8904a3a79bb 100644 --- a/crates/rspack_plugin_javascript/src/visitors/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/mod.rs @@ -1,97 +1,16 @@ mod dependency; -use std::path::{Path, PathBuf}; -use std::sync::Arc; pub use dependency::*; -use either::Either; use swc_core::common::comments::Comments; use swc_core::ecma::visit::Fold; -use xxhash_rust::xxh32::xxh32; mod clear_mark; -use rspack_core::{BuildInfo, ModuleType}; -use swc_core::ecma::transforms::base::Assumptions; pub mod swc_visitor; use rspack_ast::javascript::Ast; -use rspack_core::{CompilerOptions, ResourceData}; +use rspack_core::CompilerOptions; use rspack_error::{AnyhowError, Result}; -use swc_core::common::{chain, Mark, SourceMap}; -use swc_core::ecma::parser::Syntax; -use swc_core::ecma::transforms::base::pass::{noop, Optional}; - -macro_rules! either { - ($config:expr, $f:expr) => { - if let Some(config) = &$config { - #[allow(clippy::redundant_closure_call)] - Either::Left($f(config)) - } else { - Either::Right(noop()) - } - }; -} - -/// Rspack builtins -/// - `react`: a port of `react-refresh/babel`, and `react-fast-refresh-loader` -/// - `relay`: a port of `babel-plugin-relay` -/// - `import`: a port of `babel-plugin-import` -/// - `emotion`: a port of `babel-plugin-emotion` -// #[deprecated( -// note = "Builtin transform is deprecated and will be removed in JS version 0.5.0, see: https://github.com/web-infra-dev/rspack/pull/4133" -// )] -#[allow(clippy::too_many_arguments)] -fn builtins_additional_feature_transforms<'b>( - resource_data: &'b ResourceData, - options: &'b CompilerOptions, - module_type: &'b ModuleType, - source: &'b str, - top_level_mark: Mark, - unresolved_mark: Mark, - cm: Arc, -) -> impl Fold + 'b { - let comments = None; - // TODO: should use react-loader to get exclude/include - let should_transform_by_react = module_type.is_jsx_like(); - - chain!( - Optional::new( - rspack_swc_visitors::react( - top_level_mark, - comments, - &cm, - &options.builtins.react, - unresolved_mark - ), - should_transform_by_react - ), - Optional::new( - rspack_swc_visitors::fold_react_refresh(unresolved_mark), - should_transform_by_react && options.builtins.react.refresh.unwrap_or_default() - ), - either!( - options.builtins.emotion, - |emotion_options: &rspack_swc_visitors::EmotionOptions| { - rspack_swc_visitors::emotion( - emotion_options.clone(), - &resource_data.resource_path, - xxh32(source.as_bytes(), 0), - cm.clone(), - comments, - ) - } - ), - either!(options.builtins.relay, |relay_option| { - rspack_swc_visitors::relay( - relay_option, - &resource_data.resource_path, - PathBuf::from(AsRef::::as_ref(&options.context)), - unresolved_mark, - ) - }), - either!(options.builtins.plugin_import, |config| { - swc_plugin_import::plugin_import(config) - }) - ) -} +use swc_core::common::{chain, Mark}; +use swc_core::ecma::transforms::base::pass::Optional; /// Webpack builtin plugins /// - `define`: a port of `DefinePlugin` @@ -137,57 +56,7 @@ fn builtins_webpack_plugin_define_optimizer(unresolved_mark: Mark) -> impl Fold } #[allow(clippy::too_many_arguments)] -// #[deprecated( -// note = "Compat transform is deprecated and will be removed in JS version 0.5.0, see: https://github.com/web-infra-dev/rspack/discussions/4070" -// )] -fn compat_transform<'b>( - resource_data: &'b ResourceData, - options: &'b CompilerOptions, - top_level_mark: Mark, - unresolved_mark: Mark, - assumptions: Assumptions, - syntax: Syntax, -) -> impl Fold + 'b { - let es_version = match options.target.es_version { - rspack_core::TargetEsVersion::Esx(es_version) => Some(es_version), - _ => None, - }; - let resource_path = resource_data.resource_path.to_string_lossy(); - - chain!( - Optional::new( - swc_visitor::export_default_from(), - syntax.export_default_from() - ), - swc_visitor::paren_remover(None), - Optional::new( - swc_visitor::compat( - options.builtins.preset_env.clone(), - es_version, - assumptions, - top_level_mark, - unresolved_mark, - None, - syntax.typescript(), - ), - !resource_path.contains("@swc/helpers") - && !resource_path.contains("tslib") - && !resource_path.contains("core-js"), - ), - swc_visitor::reserved_words(), - ) -} - -#[allow(clippy::too_many_arguments)] -pub fn run_before_pass( - resource_data: &ResourceData, - ast: &mut Ast, - options: &CompilerOptions, - syntax: Syntax, - _build_info: &mut BuildInfo, - module_type: &ModuleType, - source: &str, -) -> Result<()> { +pub fn run_before_pass(ast: &mut Ast, options: &CompilerOptions) -> Result<()> { let cm = ast.get_context().source_map.clone(); ast .transform_with_handler(cm.clone(), |_handler, program, context| { @@ -195,53 +64,9 @@ pub fn run_before_pass( let unresolved_mark = context.unresolved_mark; let comments: Option<&dyn Comments> = None; - let mut assumptions = Assumptions::default(); - if syntax.typescript() { - assumptions.set_class_methods = true; - assumptions.set_public_class_fields = true; - } - let mut pass = chain!( - swc_visitor::resolver(unresolved_mark, top_level_mark, syntax.typescript()), - Optional::new( - swc_visitor::decorator(assumptions, &options.builtins.decorator), - // Decorator transformation varies from `ModuleType`, - // - TypeScript-like: decorators will be transformed by default, with legacy settings and will emit meta data. - // Since this is a default behavior with tsc. - // - JavaScript-like: decorators will not be transformed(if `disableTransformByDefault` is on), and the parse will fail. - (options.should_transform_by_default() || syntax.typescript()) && syntax.decorators() - ), - Optional::new( - swc_visitor::typescript(top_level_mark, comments, &cm), - options.should_transform_by_default() && syntax.typescript() - ), - Optional::new( - builtins_additional_feature_transforms( - resource_data, - options, - module_type, - source, - top_level_mark, - unresolved_mark, - cm - ), - options.should_transform_by_default() - ), - Optional::new( - compat_transform( - resource_data, - options, - top_level_mark, - unresolved_mark, - assumptions, - syntax - ), - options.should_transform_by_default() - ), + swc_visitor::resolver(unresolved_mark, top_level_mark, false), builtins_webpack_plugin(options, unresolved_mark), - // This will be deprecated in the future when TypeScript support and transform by default is dropped. - // These features are coupled with this. - swc_visitor::inject_helpers(unresolved_mark), swc_visitor::hygiene(false, top_level_mark), swc_visitor::fixer(comments.map(|v| v as &dyn Comments)), ); diff --git a/crates/rspack_testing/src/eval_raw.rs b/crates/rspack_testing/src/eval_raw.rs index 8abf4a9c321..31b44e1e89a 100644 --- a/crates/rspack_testing/src/eval_raw.rs +++ b/crates/rspack_testing/src/eval_raw.rs @@ -26,9 +26,14 @@ const config = require("{config_path}"); config.context ??= "{test_dir}"; config.output ??= {{}}; config.output.path ??= "{test_dir}/dist"; -const normalized = rspack.getNormalizedRspackOptions(config); -rspack.applyRspackOptionsDefaults(normalized); -const raw = rspack.getRawOptions(normalized); +const normalized = rspack.config.getNormalizedRspackOptions(config); +rspack.config.applyRspackOptionsDefaults(normalized); +let fakeCompiler = {{ + ruleSet: {{ + references: new Map() + }} +}}; +const raw = rspack.config.__internal__getRawOptions(normalized, fakeCompiler); JSON.stringify(raw, null, 2) "# ) diff --git a/crates/rspack_testing/src/test_config.rs b/crates/rspack_testing/src/test_config.rs index d7c88c4e1e7..0c706c4aa76 100644 --- a/crates/rspack_testing/src/test_config.rs +++ b/crates/rspack_testing/src/test_config.rs @@ -326,11 +326,8 @@ impl TestConfig { let mut rules = vec![ rule!("\\.json$", "json"), rule!("\\.mjs$", "js/esm"), - rule!("\\.cjs$", "js/auto"), // TODO: change to js/dynamic + rule!("\\.cjs$", "js/dynamic"), rule!("\\.js$", "js/auto"), - rule!("\\.jsx$", "jsx"), - rule!("\\.ts$", "ts"), - rule!("\\.tsx$", "tsx"), rule!("\\.css$", "css"), rule!("\\.wasm$", "webassembly/async"), ]; diff --git a/diffcases/arco-pro/rspack.config.js b/diffcases/arco-pro/rspack.config.js index 840b80979dc..c680686534a 100644 --- a/diffcases/arco-pro/rspack.config.js +++ b/diffcases/arco-pro/rspack.config.js @@ -4,7 +4,7 @@ const { default: HtmlPlugin } = require("@rspack/plugin-html"); /** @type {import('@rspack/cli').Configuration} */ const config = { - mode: 'production', + mode: "production", context: __dirname, entry: "./src/index.tsx", target: ["web", "es5"], @@ -80,7 +80,7 @@ const config = { // Alias to the unminified version mitigates this problem. // See also mockjs: require.resolve("./patches/mock.js"), - "@swc/helpers": require.resolve('@swc/helpers'), + "@swc/helpers": require.resolve("@swc/helpers") } }, output: { @@ -106,24 +106,21 @@ const config = { title: "Arco Pro App", template: path.join(__dirname, "index.html"), favicon: path.join(__dirname, "public", "favicon.ico") - }), + }) ], infrastructureLogging: { debug: false }, experiments: { - css: true, - rspackFuture: { - disableTransformByDefault: true - } + css: true }, builtins: { css: { modules: { exportsOnly: true, - localIdentName: "example-arco-design-pro---[path][name][ext]-[local]", - }, - }, - }, + localIdentName: "example-arco-design-pro---[path][name][ext]-[local]" + } + } + } }; module.exports = config; diff --git a/examples/react-refresh-babel-loader/rspack.config.js b/examples/react-refresh-babel-loader/rspack.config.js index 57c0d632ce8..49de7e4f4d4 100644 --- a/examples/react-refresh-babel-loader/rspack.config.js +++ b/examples/react-refresh-babel-loader/rspack.config.js @@ -1,20 +1,15 @@ -const rspack = require("@rspack/core") -const ReactRefreshPlugin = require("@rspack/plugin-react-refresh") +const rspack = require("@rspack/core"); +const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); -const isProduction = process.env.NODE_ENV === "production" +const isProduction = process.env.NODE_ENV === "production"; /** @type {import('@rspack/cli').Configuration} */ const config = { - experiments: { - rspackFuture: { - disableTransformByDefault: true, - } - }, mode: isProduction ? "production" : "development", entry: { main: "./src/index.tsx" }, devtool: false, optimization: { - minimize: false, // Disabling minification because it takes too long on CI + minimize: false // Disabling minification because it takes too long on CI }, module: { rules: [ @@ -25,9 +20,11 @@ const config = { options: { presets: [ ["@babel/preset-react", { runtime: "automatic" }], - '@babel/preset-typescript', + "@babel/preset-typescript" ], - plugins: [!isProduction && require.resolve('react-refresh/babel')].filter(Boolean) + plugins: [ + !isProduction && require.resolve("react-refresh/babel") + ].filter(Boolean) } } } @@ -36,7 +33,7 @@ const config = { plugins: [ new rspack.HtmlRspackPlugin({ template: "./index.html" }), new rspack.DefinePlugin({ "process.env.NODE_ENV": "'development'" }), - !isProduction && new ReactRefreshPlugin(), + !isProduction && new ReactRefreshPlugin() ].filter(Boolean) }; diff --git a/examples/react-refresh/rspack.config.js b/examples/react-refresh/rspack.config.js index 67d3d359076..d68b7838339 100644 --- a/examples/react-refresh/rspack.config.js +++ b/examples/react-refresh/rspack.config.js @@ -1,18 +1,13 @@ -const rspack = require("@rspack/core") -const ReactRefreshPlugin = require("@rspack/plugin-react-refresh") +const rspack = require("@rspack/core"); +const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); -const isProduction = process.env.NODE_ENV === "production" +const isProduction = process.env.NODE_ENV === "production"; /** @type {import('@rspack/cli').Configuration} */ const config = { - experiments: { - rspackFuture: { - disableTransformByDefault: true, - } - }, mode: isProduction ? "production" : "development", entry: { main: "./src/index.tsx" }, - devtool: 'source-map', + devtool: "source-map", module: { rules: [ { @@ -30,7 +25,7 @@ const config = { react: { runtime: "automatic", development: !isProduction, - refresh: !isProduction, + refresh: !isProduction } } } @@ -40,12 +35,12 @@ const config = { ] }, optimization: { - minimize: false, // Disabling minification because it takes too long on CI + minimize: false // Disabling minification because it takes too long on CI }, plugins: [ new rspack.HtmlRspackPlugin({ template: "./index.html" }), new rspack.DefinePlugin({ "process.env.NODE_ENV": "'development'" }), - !isProduction && new ReactRefreshPlugin(), + !isProduction && new ReactRefreshPlugin() ].filter(Boolean) }; diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/index.test.ts b/packages/playground/cases/react/basic-disableTransformByDefault/index.test.ts deleted file mode 100644 index 33fefe02749..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/index.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { test, expect } from "@/fixtures"; - -test("render should work", async ({ page }) => { - expect(await page.textContent(".header")).toBe("Hello World"); - expect(await page.textContent("#lazy-component")).toBe("Lazy Component"); -}); - -test("hmr should work", async ({ page, fileAction, rspack }) => { - expect(await page.textContent("button")).toBe("10"); - await page.click("button"); - expect(await page.textContent("button")).toBe("11"); - expect(await page.textContent(".placeholder")).toBe("__PLACE_HOLDER__"); - fileAction.updateFile("src/App.jsx", content => - content.replace("__PLACE_HOLDER__", "__EDITED__") - ); - await rspack.waitingForHmr(async function () { - return (await page.textContent(".placeholder")) === "__EDITED__"; - }); - expect(await page.textContent("button")).toBe("11"); -}); - -test("context+component should work", async ({ page, fileAction, rspack }) => { - expect(await page.textContent("#context")).toBe("context-value"); - await page.click("#context"); - expect(await page.textContent("#context")).toBe("context-value-click"); - fileAction.updateFile("src/CountProvider.jsx", content => - content.replace("context-value", "context-value-update") - ); - await rspack.waitingForHmr(async function () { - return (await page.textContent("#context")) === "context-value-update"; - }); -}); - -test("ReactRefreshFinder should work", async ({ page }) => { - expect(await page.textContent("#nest-function")).toBe("nest-function"); -}); - -test("update same export name from different module should work", async ({ - page, - fileAction, - rspack -}) => { - expect(await page.textContent(".same-export-name1")).toBe("__NAME_1__"); - expect(await page.textContent(".same-export-name2")).toBe("__NAME_2__"); - fileAction.updateFile("src/SameExportName1.jsx", content => - content.replace("__NAME_1__", "__name_1__") - ); - await rspack.waitingForHmr(async function () { - return (await page.textContent(".same-export-name1")) === "__name_1__"; - }); - expect(await page.textContent(".same-export-name2")).toBe("__NAME_2__"); - fileAction.updateFile("src/SameExportName2.jsx", content => - content.replace("__NAME_2__", "__name_2__") - ); - await rspack.waitingForHmr(async function () { - return (await page.textContent(".same-export-name2")) === "__name_2__"; - }); - expect(await page.textContent(".same-export-name1")).toBe("__name_1__"); -}); diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/rspack.config.js b/packages/playground/cases/react/basic-disableTransformByDefault/rspack.config.js deleted file mode 100644 index 8fd89ed39da..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/rspack.config.js +++ /dev/null @@ -1,50 +0,0 @@ -const rspack = require("@rspack/core"); -const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); - -/** @type { import('@rspack/core').RspackOptions } */ -module.exports = { - context: __dirname, - mode: "development", - module: { - rules: [ - { - test: /\.jsx$/, - use: { - loader: "builtin:swc-loader", - options: { - jsc: { - parser: { - syntax: "ecmascript", - jsx: true - }, - transform: { - react: { - runtime: "automatic", - development: true, - refresh: true - } - } - } - } - } - } - ] - }, - devtool: false, - plugins: [ - new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), - new ReactRefreshPlugin() - ], - entry: "./src/index.jsx", - devServer: { - hot: true - }, - cache: false, - stats: "none", - infrastructureLogging: { - debug: false - }, - watchOptions: { - poll: 1000 - } -}; diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/App.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/App.jsx deleted file mode 100644 index bdc458f22fc..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/App.jsx +++ /dev/null @@ -1,32 +0,0 @@ -import React from 'react' -import './index.css' -import { ContextComponent } from './CountProvider' -import { ReactRefreshFinder } from './ReactRefreshFinder' -import { SameExportName as SameExportName1 } from './SameExportName1' -import { SameExportName as SameExportName2 } from './SameExportName2' -import ComponentInNodeModules from "foo" - -const Button = () => { - const [count, setCount] = React.useState(10) - return -} - -const LazyComponent = React.lazy(() => import('./LazyComponent')) - -export const App = () => { - return ( -
-
Hello World
-
}> - - - - - ) -} diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/CountProvider.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/CountProvider.jsx deleted file mode 100644 index afbe1fcbe34..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/CountProvider.jsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; - -export const CountContext = React.createContext(); - -export function CountProvider({ children }) { - const [count, setCount] = React.useState('context-value'); - return ( - - {children} - - ); -} - -export function ContextComponent() { - const { count, setCount } = React.useContext(CountContext); - return
setCount((count) => count + '-click')}> - {count} -
-} \ No newline at end of file diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/LazyComponent.css b/packages/playground/cases/react/basic-disableTransformByDefault/src/LazyComponent.css deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/LazyComponent.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/LazyComponent.jsx deleted file mode 100644 index 65545394690..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/LazyComponent.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import './LazyComponent.css' - -function LazyComponent () { - return
Lazy Component
-} - -export default LazyComponent diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/ReactRefreshFinder.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/ReactRefreshFinder.jsx deleted file mode 100644 index 83b0509d747..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/ReactRefreshFinder.jsx +++ /dev/null @@ -1,10 +0,0 @@ -import React, { useState } from 'react'; - -function CreateReactRefreshFinder() { - return function Component() { - useState(1); - return
nest-function
; - }; -} - -export const ReactRefreshFinder = CreateReactRefreshFinder() \ No newline at end of file diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/SameExportName1.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/SameExportName1.jsx deleted file mode 100644 index 2a7f2b45f15..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/SameExportName1.jsx +++ /dev/null @@ -1,3 +0,0 @@ -export function SameExportName() { - return
__NAME_1__
-} diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/SameExportName2.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/SameExportName2.jsx deleted file mode 100644 index 8bf62ab6bb5..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/SameExportName2.jsx +++ /dev/null @@ -1,3 +0,0 @@ -export function SameExportName() { - return
__NAME_2__
-} diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/index.css b/packages/playground/cases/react/basic-disableTransformByDefault/src/index.css deleted file mode 100644 index 753f48a591f..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/index.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background-color: rgba(0, 0, 0, 0); -} diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/index.html b/packages/playground/cases/react/basic-disableTransformByDefault/src/index.html deleted file mode 100644 index 127a457455b..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - -
- - diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/src/index.jsx b/packages/playground/cases/react/basic-disableTransformByDefault/src/index.jsx deleted file mode 100644 index 52e72c3334e..00000000000 --- a/packages/playground/cases/react/basic-disableTransformByDefault/src/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from "react"; -import { createRoot } from "react-dom/client"; -import { App } from './App'; -import { CountProvider } from "./CountProvider"; - -const container = createRoot(document.getElementById("root")); -container.render( - - - -); diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/.gitignore b/packages/playground/cases/react/basic/.gitignore similarity index 100% rename from packages/playground/cases/react/basic-disableTransformByDefault/.gitignore rename to packages/playground/cases/react/basic/.gitignore diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/node_modules/foo/index.jsx b/packages/playground/cases/react/basic/node_modules/foo/index.jsx similarity index 100% rename from packages/playground/cases/react/basic-disableTransformByDefault/node_modules/foo/index.jsx rename to packages/playground/cases/react/basic/node_modules/foo/index.jsx diff --git a/packages/playground/cases/react/basic-disableTransformByDefault/node_modules/foo/package.json b/packages/playground/cases/react/basic/node_modules/foo/package.json similarity index 100% rename from packages/playground/cases/react/basic-disableTransformByDefault/node_modules/foo/package.json rename to packages/playground/cases/react/basic/node_modules/foo/package.json diff --git a/packages/playground/cases/react/basic/react-refresh.js b/packages/playground/cases/react/basic/react-refresh.js deleted file mode 100644 index e4b58b1fff8..00000000000 --- a/packages/playground/cases/react/basic/react-refresh.js +++ /dev/null @@ -1,17 +0,0 @@ -const reactRefresh = require("@rspack/plugin-react-refresh/react-refresh"); - -function shouldLooksLikeAModuleId(id) { - console.log(id); - if (typeof id === "string" && !id.includes("[object Object]")) { - return; - } - throw new Error(`Looks like ${id} is not a module.id`); -} - -module.exports = { - ...reactRefresh, - register(type, id) { - shouldLooksLikeAModuleId(id); - return reactRefresh.register(type, id); - } -}; diff --git a/packages/playground/cases/react/basic/rspack.config.js b/packages/playground/cases/react/basic/rspack.config.js index 2e5bdebac88..8fd89ed39da 100644 --- a/packages/playground/cases/react/basic/rspack.config.js +++ b/packages/playground/cases/react/basic/rspack.config.js @@ -1,20 +1,41 @@ +const rspack = require("@rspack/core"); +const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); + /** @type { import('@rspack/core').RspackOptions } */ module.exports = { context: __dirname, mode: "development", module: { - // add this to test react refresh runtime shouldn't inject runtime,see #3984 rules: [ { - test: /\.js$/, - type: "jsx" + test: /\.jsx$/, + use: { + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "ecmascript", + jsx: true + }, + transform: { + react: { + runtime: "automatic", + development: true, + refresh: true + } + } + } + } + } } ] }, - entry: [ - "@rspack/plugin-react-refresh/react-refresh-entry", - "./src/index.jsx" + devtool: false, + plugins: [ + new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), + new ReactRefreshPlugin() ], + entry: "./src/index.jsx", devServer: { hot: true }, @@ -23,21 +44,6 @@ module.exports = { infrastructureLogging: { debug: false }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - }, - builtins: { - provide: { - $ReactRefreshRuntime$: [require.resolve("./react-refresh.js")] - }, - html: [ - { - template: "./src/index.html" - } - ] - }, watchOptions: { poll: 1000 } diff --git a/packages/playground/cases/react/basic/src/App.jsx b/packages/playground/cases/react/basic/src/App.jsx index a72ff3a972a..bdc458f22fc 100644 --- a/packages/playground/cases/react/basic/src/App.jsx +++ b/packages/playground/cases/react/basic/src/App.jsx @@ -4,6 +4,7 @@ import { ContextComponent } from './CountProvider' import { ReactRefreshFinder } from './ReactRefreshFinder' import { SameExportName as SameExportName1 } from './SameExportName1' import { SameExportName as SameExportName2 } from './SameExportName2' +import ComponentInNodeModules from "foo" const Button = () => { const [count, setCount] = React.useState(10) @@ -25,6 +26,7 @@ export const App = () => { loading...}> + ) } diff --git a/packages/playground/cases/react/class-component-disableTransformByDefault/index.test.ts b/packages/playground/cases/react/class-component-disableTransformByDefault/index.test.ts deleted file mode 100644 index b1c3c5f0a17..00000000000 --- a/packages/playground/cases/react/class-component-disableTransformByDefault/index.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { test, expect } from "@/fixtures"; - -test("render should work", async ({ page }) => { - expect(await page.textContent(".header")).toBe("Hello World"); -}); - -test("class component hmr should work", async ({ - page, - fileAction, - rspack -}) => { - expect(await page.textContent("button")).toBe("10"); - await page.click("button"); - expect(await page.textContent("button")).toBe("11"); - expect(await page.textContent(".placeholder")).toBe("__PLACE_HOLDER__"); - fileAction.updateFile("src/App.jsx", content => - content.replace("__PLACE_HOLDER__", "__EDITED__") - ); - await rspack.waitingForHmr(async function () { - return (await page.textContent(".placeholder")) === "__EDITED__"; - }); - // class component will not keep local status - expect(await page.textContent("button")).toBe("10"); -}); diff --git a/packages/playground/cases/react/class-component-disableTransformByDefault/rspack.config.js b/packages/playground/cases/react/class-component-disableTransformByDefault/rspack.config.js deleted file mode 100644 index 0df57a6d324..00000000000 --- a/packages/playground/cases/react/class-component-disableTransformByDefault/rspack.config.js +++ /dev/null @@ -1,49 +0,0 @@ -const rspack = require("@rspack/core"); -const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); - -/** @type { import('@rspack/core').RspackOptions } */ -module.exports = { - context: __dirname, - mode: "development", - entry: "./src/index.jsx", - module: { - rules: [ - { - test: /\.jsx$/, - use: { - loader: "builtin:swc-loader", - options: { - jsc: { - parser: { - syntax: "ecmascript", - jsx: true - }, - transform: { - react: { - runtime: "automatic", - development: true, - refresh: true - } - } - } - } - } - } - ] - }, - plugins: [ - new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), - new ReactRefreshPlugin() - ], - devServer: { - hot: true - }, - cache: false, - stats: "none", - infrastructureLogging: { - debug: false - }, - watchOptions: { - poll: 1000 - } -}; diff --git a/packages/playground/cases/react/class-component-disableTransformByDefault/src/App.jsx b/packages/playground/cases/react/class-component-disableTransformByDefault/src/App.jsx deleted file mode 100644 index dd95da73edd..00000000000 --- a/packages/playground/cases/react/class-component-disableTransformByDefault/src/App.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import React from "react"; - -const Button = () => { - const [count, setCount] = React.useState(10); - return ; -}; - -export class App extends React.Component { - render() { - return ( -
-
Hello World
-
- ); - } -} diff --git a/packages/playground/cases/react/class-component-disableTransformByDefault/src/index.html b/packages/playground/cases/react/class-component-disableTransformByDefault/src/index.html deleted file mode 100644 index 127a457455b..00000000000 --- a/packages/playground/cases/react/class-component-disableTransformByDefault/src/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - -
- - diff --git a/packages/playground/cases/react/class-component-disableTransformByDefault/src/index.jsx b/packages/playground/cases/react/class-component-disableTransformByDefault/src/index.jsx deleted file mode 100644 index 18f79ce0697..00000000000 --- a/packages/playground/cases/react/class-component-disableTransformByDefault/src/index.jsx +++ /dev/null @@ -1,6 +0,0 @@ -import React from 'react' -import { createRoot } from 'react-dom/client' -import { App } from './App' - -const container = createRoot(document.getElementById('root')) -container.render() diff --git a/packages/playground/cases/react/class-component/react-refresh.js b/packages/playground/cases/react/class-component/react-refresh.js deleted file mode 100644 index e4b58b1fff8..00000000000 --- a/packages/playground/cases/react/class-component/react-refresh.js +++ /dev/null @@ -1,17 +0,0 @@ -const reactRefresh = require("@rspack/plugin-react-refresh/react-refresh"); - -function shouldLooksLikeAModuleId(id) { - console.log(id); - if (typeof id === "string" && !id.includes("[object Object]")) { - return; - } - throw new Error(`Looks like ${id} is not a module.id`); -} - -module.exports = { - ...reactRefresh, - register(type, id) { - shouldLooksLikeAModuleId(id); - return reactRefresh.register(type, id); - } -}; diff --git a/packages/playground/cases/react/class-component/rspack.config.js b/packages/playground/cases/react/class-component/rspack.config.js index cf23dc3c12f..0df57a6d324 100644 --- a/packages/playground/cases/react/class-component/rspack.config.js +++ b/packages/playground/cases/react/class-component/rspack.config.js @@ -1,10 +1,39 @@ +const rspack = require("@rspack/core"); +const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); + /** @type { import('@rspack/core').RspackOptions } */ module.exports = { context: __dirname, mode: "development", - entry: [ - "@rspack/plugin-react-refresh/react-refresh-entry", - "./src/index.jsx" + entry: "./src/index.jsx", + module: { + rules: [ + { + test: /\.jsx$/, + use: { + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "ecmascript", + jsx: true + }, + transform: { + react: { + runtime: "automatic", + development: true, + refresh: true + } + } + } + } + } + } + ] + }, + plugins: [ + new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), + new ReactRefreshPlugin() ], devServer: { hot: true @@ -14,21 +43,6 @@ module.exports = { infrastructureLogging: { debug: false }, - builtins: { - provide: { - $ReactRefreshRuntime$: [require.resolve("./react-refresh.js")] - }, - html: [ - { - template: "./src/index.html" - } - ] - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - }, watchOptions: { poll: 1000 } diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/index.test.ts b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/index.test.ts deleted file mode 100644 index 72eda5d7793..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/index.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { test, expect } from "@/fixtures"; - -test("tailwindcss should work when modify js file", async ({ - page, - fileAction, - rspack -}) => { - function getAppFontSize() { - return page.evaluate(() => { - const app = document.querySelector("#app"); - if (!app) { - return ""; - } - return window.getComputedStyle(app).fontSize; - }); - } - - let appFontSize = await getAppFontSize(); - expect(appFontSize).toBe("24px"); - - // update - fileAction.updateFile("src/App.jsx", content => { - return content.replace("text-2xl", "text-3xl"); - }); - await rspack.waitingForHmr(async () => { - const classNames = await page.getAttribute("#app", "class"); - return classNames?.includes("text-3xl") || false; - }); - - appFontSize = await getAppFontSize(); - expect(appFontSize).toBe("30px"); -}); diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/rspack.config.js b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/rspack.config.js deleted file mode 100644 index 5ef996fcc03..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/rspack.config.js +++ /dev/null @@ -1,57 +0,0 @@ -const path = require("path"); -const rspack = require("@rspack/core"); -const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); - -module.exports = { - context: __dirname, - entry: { - main: "./src/main.jsx" - }, - plugins: [ - new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), - new ReactRefreshPlugin() - ], - module: { - rules: [ - { - test: /\.jsx$/, - use: { - loader: "builtin:swc-loader", - options: { - jsc: { - parser: { - syntax: "ecmascript", - jsx: true - }, - transform: { - react: { - runtime: "automatic", - development: true, - refresh: true - } - } - } - } - } - }, - { - test: /\.css$/, - use: [ - { - loader: "postcss-loader", - options: { - postcssOptions: { - plugins: { - tailwindcss: { - config: path.join(__dirname, "./tailwind.config.js") - } - } - } - } - } - ], - type: "css" - } - ] - } -}; diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/App.css b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/App.css deleted file mode 100644 index 6300d8a49d6..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/App.css +++ /dev/null @@ -1,10 +0,0 @@ -@tailwind base; -@tailwind components; -@tailwind utilities; - -#root { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/App.jsx b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/App.jsx deleted file mode 100644 index 51826c77656..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/App.jsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from "react"; -import "./App.css"; - -function App() { - return ( -

- Hello world! -

- ); -} - -export default App; diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/index.html b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/index.html deleted file mode 100644 index 127a457455b..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - -
- - diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/main.jsx b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/main.jsx deleted file mode 100644 index d0d585c0881..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/src/main.jsx +++ /dev/null @@ -1,5 +0,0 @@ -import React from "react"; -import ReactDOM from "react-dom/client"; -import App from "./App"; - -ReactDOM.createRoot(document.getElementById("root")).render(); diff --git a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/tailwind.config.js b/packages/playground/cases/react/tailwindcss-disableTransformByDefault/tailwind.config.js deleted file mode 100644 index dffcc47fcd0..00000000000 --- a/packages/playground/cases/react/tailwindcss-disableTransformByDefault/tailwind.config.js +++ /dev/null @@ -1,9 +0,0 @@ -const path = require("path"); -/** @type {import('tailwindcss').Config} */ -module.exports = { - content: [path.join(__dirname, "./src/**/*.{html,js,jsx}")], - theme: { - extend: {} - }, - plugins: [] -}; diff --git a/packages/playground/cases/react/tailwindcss/rspack.config.js b/packages/playground/cases/react/tailwindcss/rspack.config.js index 631bdc43cb3..5ef996fcc03 100644 --- a/packages/playground/cases/react/tailwindcss/rspack.config.js +++ b/packages/playground/cases/react/tailwindcss/rspack.config.js @@ -1,19 +1,39 @@ const path = require("path"); +const rspack = require("@rspack/core"); +const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); module.exports = { context: __dirname, entry: { main: "./src/main.jsx" }, - builtins: { - html: [ - { - template: "./src/index.html" - } - ] - }, + plugins: [ + new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), + new ReactRefreshPlugin() + ], module: { rules: [ + { + test: /\.jsx$/, + use: { + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "ecmascript", + jsx: true + }, + transform: { + react: { + runtime: "automatic", + development: true, + refresh: true + } + } + } + } + } + }, { test: /\.css$/, use: [ @@ -33,10 +53,5 @@ module.exports = { type: "css" } ] - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } } }; diff --git a/packages/playground/cases/react/with-babel/rspack.config.js b/packages/playground/cases/react/with-babel/rspack.config.js index 59f01776518..fa48cc50f1f 100644 --- a/packages/playground/cases/react/with-babel/rspack.config.js +++ b/packages/playground/cases/react/with-babel/rspack.config.js @@ -9,13 +9,34 @@ module.exports = { rules: [ { test: /\.jsx$/, - use: { - loader: "babel-loader", - options: { - presets: [["@babel/preset-react", { runtime: "automatic" }]], - plugins: [require.resolve("react-refresh/babel")] + use: [ + { + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "typescript", + tsx: true + }, + transform: { + react: { + runtime: "automatic", + development: true, + refresh: true + } + }, + externalHelpers: true + } + } + }, + { + loader: "babel-loader", + options: { + presets: [["@babel/preset-react", { runtime: "automatic" }]], + plugins: [require.resolve("react-refresh/babel")] + } } - } + ] } ] }, @@ -23,11 +44,6 @@ module.exports = { new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), new ReactRefreshPlugin() ], - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - }, entry: "./src/index.jsx", devServer: { hot: true diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/index.test.ts b/packages/playground/cases/react/worker-disableTransformByDefault/index.test.ts deleted file mode 100644 index e5cf91b389c..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/index.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { test, expect } from "@/fixtures"; - -test("should successfully render the page", async ({ page }) => { - expect(await page.textContent("button")).toBe("+"); - expect(await page.textContent("h1")).toBe("0"); -}); - -// test("worker should work", async ({ page, fileAction, rspack }) => { -// await page.click("button"); -// expect(await page.textContent("h1")).toBe("1"); -// await page.click("button"); -// expect(await page.textContent("h1")).toBe("2"); -// }); diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/rspack.config.js b/packages/playground/cases/react/worker-disableTransformByDefault/rspack.config.js deleted file mode 100644 index 0df57a6d324..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/rspack.config.js +++ /dev/null @@ -1,49 +0,0 @@ -const rspack = require("@rspack/core"); -const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); - -/** @type { import('@rspack/core').RspackOptions } */ -module.exports = { - context: __dirname, - mode: "development", - entry: "./src/index.jsx", - module: { - rules: [ - { - test: /\.jsx$/, - use: { - loader: "builtin:swc-loader", - options: { - jsc: { - parser: { - syntax: "ecmascript", - jsx: true - }, - transform: { - react: { - runtime: "automatic", - development: true, - refresh: true - } - } - } - } - } - } - ] - }, - plugins: [ - new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), - new ReactRefreshPlugin() - ], - devServer: { - hot: true - }, - cache: false, - stats: "none", - infrastructureLogging: { - debug: false - }, - watchOptions: { - poll: 1000 - } -}; diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/src/App.jsx b/packages/playground/cases/react/worker-disableTransformByDefault/src/App.jsx deleted file mode 100644 index 9ccfd1f8ac4..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/src/App.jsx +++ /dev/null @@ -1,21 +0,0 @@ -import React, { useState } from "react"; -import Button from './Button' - -let updateRenderTimes; - -const worker = new Worker(new URL("./worker", import.meta.url)); - -worker.onmessage = (e) => { - updateRenderTimes(e.data) -} - -export const App = () => { - const [renderTimes, setRenderTimes] = useState(0) - updateRenderTimes = setRenderTimes; - return ( -
-

{renderTimes}

-
- ); -}; diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/src/Button.jsx b/packages/playground/cases/react/worker-disableTransformByDefault/src/Button.jsx deleted file mode 100644 index ddaa59b3bee..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/src/Button.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import React from "react"; - -export default function Button({ onClick }) { - return ; -}; - -Button.count = 0; - -Button.get = () => { - return Button.count; -} - -Button.add = () => { - Button.count += 1; -} diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/src/index.html b/packages/playground/cases/react/worker-disableTransformByDefault/src/index.html deleted file mode 100644 index 127a457455b..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/src/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - -
- - diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/src/index.jsx b/packages/playground/cases/react/worker-disableTransformByDefault/src/index.jsx deleted file mode 100644 index 032d1403b0c..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/src/index.jsx +++ /dev/null @@ -1,6 +0,0 @@ -import React from "react"; -import { createRoot } from "react-dom/client"; -import { App } from './App'; - -const container = createRoot(document.getElementById("root")); -container.render(); diff --git a/packages/playground/cases/react/worker-disableTransformByDefault/src/worker.js b/packages/playground/cases/react/worker-disableTransformByDefault/src/worker.js deleted file mode 100644 index 01baa84f07d..00000000000 --- a/packages/playground/cases/react/worker-disableTransformByDefault/src/worker.js +++ /dev/null @@ -1,6 +0,0 @@ -import Button from "./Button"; - -onmessage = e => { - Button.add(); - postMessage(Button.get()); -}; diff --git a/packages/playground/cases/react/worker/rspack.config.js b/packages/playground/cases/react/worker/rspack.config.js index 5114e5be5dc..0df57a6d324 100644 --- a/packages/playground/cases/react/worker/rspack.config.js +++ b/packages/playground/cases/react/worker/rspack.config.js @@ -1,8 +1,40 @@ +const rspack = require("@rspack/core"); +const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); + /** @type { import('@rspack/core').RspackOptions } */ module.exports = { context: __dirname, mode: "development", entry: "./src/index.jsx", + module: { + rules: [ + { + test: /\.jsx$/, + use: { + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "ecmascript", + jsx: true + }, + transform: { + react: { + runtime: "automatic", + development: true, + refresh: true + } + } + } + } + } + } + ] + }, + plugins: [ + new rspack.HtmlRspackPlugin({ template: "./src/index.html" }), + new ReactRefreshPlugin() + ], devServer: { hot: true }, @@ -11,18 +43,6 @@ module.exports = { infrastructureLogging: { debug: false }, - builtins: { - html: [ - { - template: "./src/index.html" - } - ] - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - }, watchOptions: { poll: 1000 } diff --git a/packages/rspack-cli/tests/build/basic/public/main.js b/packages/rspack-cli/tests/build/basic/public/main.js index f79697dcdc4..6aac1450321 100644 --- a/packages/rspack-cli/tests/build/basic/public/main.js +++ b/packages/rspack-cli/tests/build/basic/public/main.js @@ -1,10 +1,6 @@ (function () { var __webpack_modules__ = { - "./src/entry.js": function ( - __unused_webpack_module, - exports, - __webpack_require__ - ) { + "./src/entry.js": function () { console.log("CONFIG"); } }; diff --git a/packages/rspack-cli/tests/build/issue-4467/index.test.ts b/packages/rspack-cli/tests/build/issue-4467/index.test.ts index 309a27e4dc9..2cae118ef2a 100644 --- a/packages/rspack-cli/tests/build/issue-4467/index.test.ts +++ b/packages/rspack-cli/tests/build/issue-4467/index.test.ts @@ -3,10 +3,17 @@ import { run } from "../../utils/test-utils"; it("should not print the warning for child compiler", async () => { const cwd = path.resolve(__dirname, "./child"); - const { exitCode, stderr } = await run(cwd); + const { exitCode, stderr } = await run( + cwd, + [], + {}, + { + RSPACK_DEP_WARNINGS: true + } + ); expect(exitCode).toBe(0); expect(stderr).not.toContain( - "'builtins.react = {}' only works for 'experiments.rspackF" + '\'builtins.banner = {"banner":""}\' has been deprecated' ); expect(stderr).not.toContain( `'builtins.decorator = {"legacy":true,"emitMetadata":true}' onl` @@ -15,9 +22,16 @@ it("should not print the warning for child compiler", async () => { it("should print the warning for root compiler", async () => { const cwd = path.resolve(__dirname, "./root"); - const { exitCode, stderr } = await run(cwd); + const { exitCode, stderr } = await run( + cwd, + [], + {}, + { + RSPACK_DEP_WARNINGS: true + } + ); expect(exitCode).toBe(0); expect(stderr).toContain( - "'builtins.react = {}' only works for 'experiments.rspackF" + '\'builtins.banner = {"banner":""}\' has been deprecated' ); }); diff --git a/packages/rspack-cli/tests/build/issue-4467/root/rspack.config.js b/packages/rspack-cli/tests/build/issue-4467/root/rspack.config.js index 25dcb4e4c4f..3ce5d18f1d8 100644 --- a/packages/rspack-cli/tests/build/issue-4467/root/rspack.config.js +++ b/packages/rspack-cli/tests/build/issue-4467/root/rspack.config.js @@ -3,7 +3,9 @@ const path = require("path"); const config = { entry: path.resolve(__dirname, "./index.js"), builtins: { - react: {} + banner: { + banner: "" + } } }; diff --git a/packages/rspack-dev-server/src/server.ts b/packages/rspack-dev-server/src/server.ts index dd50df19b06..db73f81f666 100644 --- a/packages/rspack-dev-server/src/server.ts +++ b/packages/rspack-dev-server/src/server.ts @@ -181,46 +181,6 @@ export class RspackDevServer extends WebpackDevServer { "ansi-html-community": path.resolve(__dirname, "./ansiHTML"), ...compiler.options.resolve.alias }; - - if ( - // @ts-expect-error - !compiler.options.experiments.rspackFuture.disableTransformByDefault - ) { - compiler.options.builtins.react ??= {}; - // enable react.development by default - compiler.options.builtins.react.development ??= true; - // enable react.refresh by default - compiler.options.builtins.react.refresh ??= true; - if (compiler.options.builtins.react.refresh) { - const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); - const runtimePaths = ReactRefreshPlugin.deprecated_runtimePaths; - new compiler.webpack.EntryPlugin( - compiler.context, - runtimePaths[0], - { - name: undefined - } - ).apply(compiler); - new compiler.webpack.ProvidePlugin({ - $ReactRefreshRuntime$: runtimePaths[1] - }).apply(compiler); - compiler.options.module.rules.unshift({ - include: runtimePaths, - type: "js" - }); - } - } - } else if (compiler.options.builtins.react?.refresh) { - if (mode === "production") { - this.logger.warn( - "React Refresh runtime should not be included in the production bundle.\n" + - "Make sure to disable React Refresh for production by setting `builtins.react.refresh` to `false` in the configuration." - ); - } else { - this.logger.warn( - "The `builtins.react.refresh` needs `builtins.react.development` and `devServer.hot` enabled" - ); - } } }); diff --git a/packages/rspack-dev-server/tests/normalizeOptions.test.ts b/packages/rspack-dev-server/tests/normalizeOptions.test.ts index 146851a3bc0..784258bc502 100644 --- a/packages/rspack-dev-server/tests/normalizeOptions.test.ts +++ b/packages/rspack-dev-server/tests/normalizeOptions.test.ts @@ -68,12 +68,7 @@ describe("normalize options snapshot", () => { const entries1 = await getAdditionEntries( {}, { - entry: ["something"], - experiments: { - rspackFuture: { - disableTransformByDefault: true - } - } + entry: ["something"] } ); expect(entries1["undefined"]).not.toContain(reactRefreshEntry); @@ -81,39 +76,12 @@ describe("normalize options snapshot", () => { {}, { entry: ["something"], - plugins: [new ReactRefreshPlugin()], - experiments: { - rspackFuture: { - disableTransformByDefault: true - } - } + plugins: [new ReactRefreshPlugin()] } ); expect(entries2["undefined"]).toContain(reactRefreshEntry); }); - it("react.development and react.refresh should be true by default when hot enabled", async () => { - const compiler = rspack({ - entry: ENTRY, - stats: "none", - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } - }); - const server = new RspackDevServer( - { - hot: true - }, - compiler - ); - await server.start(); - expect(compiler.options.builtins.react?.refresh).toBe(true); - expect(compiler.options.builtins.react?.development).toBe(true); - await server.stop(); - }); - it("should apply HMR plugin by default", async () => { const compiler = rspack({ entry: ENTRY, diff --git a/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts b/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts index b38eceec447..fb9b4e67971 100644 --- a/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts +++ b/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts @@ -23,6 +23,5 @@ export class RspackDiffConfigPlugin implements RspackPluginInstance { options.experiments ??= {}; options.experiments.rspackFuture ??= {}; - options.experiments.rspackFuture.disableTransformByDefault = true; } } diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index 9a835c76e63..8d9ffaf9da6 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -321,32 +321,6 @@ export function deprecated_resolveBuiltins( noEmitAssets = true; } - if (options.experiments.rspackFuture?.disableTransformByDefault) { - ( - [ - "react", - "pluginImport", - "decorator", - "presetEnv", - "emotion", - "relay" - ] as const - ).forEach(key => { - if (builtins[key]) { - isRoot && - deprecatedWarn( - `'builtins.${key} = ${JSON.stringify( - builtins[key] - )}' only works for 'experiments.rspackFuture.disableTransformByDefault = false', please migrate to ${termlink( - "builtin:swc-loader options", - "https://www.rspack.dev/guide/loader.html#builtinswc-loader" - )}`, - true - ); - } - }); - } - return { // TODO: discuss with webpack, this should move to css generator options css: options.experiments.css diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index ef691b3500c..8629973061f 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -347,15 +347,6 @@ function tryMatch(payload: string, condition: RuleSetCondition): boolean { return false; } -const deprecatedRuleType = (type?: string) => { - type ??= "javascript/auto"; - if (/ts|typescript|tsx|typescriptx|jsx|javascriptx/.test(type)) { - deprecatedWarn( - `'Rule.type: ${type}' has been deprecated, please migrate to builtin:swc-loader with type 'javascript/auto'` - ); - } -}; - const getRawModuleRule = ( rule: RuleSetRule, path: string, @@ -480,9 +471,6 @@ const getRawModuleRule = ( return true; }); } - if (options.experiments.rspackFuture.disableTransformByDefault) { - deprecatedRuleType(rule.type); - } return rawModuleRule; }; @@ -762,10 +750,8 @@ function getRawRspackFutureOptions( future: RspackFutureOptions ): RawRspackFuture { assert(!isNil(future.newTreeshaking)); - assert(!isNil(future.disableTransformByDefault)); return { - newTreeshaking: future.newTreeshaking, - disableTransformByDefault: future.disableTransformByDefault + newTreeshaking: future.newTreeshaking }; } diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 7bab8a22b50..9505b6279b7 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -90,8 +90,6 @@ export const applyRspackOptionsDefaults = ( applyModuleDefaults(options.module, { // syncWebAssembly: options.experiments.syncWebAssembly, asyncWebAssembly: options.experiments.asyncWebAssembly!, - disableTransformByDefault: - options.experiments.rspackFuture!.disableTransformByDefault!, css: options.experiments.css! }); @@ -185,7 +183,6 @@ const applyExperimentsDefaults = ( D(experiments, "rspackFuture", {}); if (typeof experiments.rspackFuture === "object") { D(experiments.rspackFuture, "newTreeshaking", false); - D(experiments.rspackFuture, "disableTransformByDefault", true); D(experiments.rspackFuture, "disableApplyEntryLazily", true); } }; @@ -216,12 +213,10 @@ const applyModuleDefaults = ( module: ModuleOptions, { asyncWebAssembly, - css, - disableTransformByDefault + css }: { asyncWebAssembly: boolean; css: boolean; - disableTransformByDefault: boolean; } ) => { assertNotNill(module.parser); @@ -295,24 +290,6 @@ const applyModuleDefaults = ( } ]; - // TODO: remove in 0.5.0 - if (!disableTransformByDefault) { - rules.push( - { - test: /\.jsx$/i, - type: "jsx" - }, - { - test: /\.ts$/i, - type: "ts" - }, - { - test: /\.tsx$/i, - type: "tsx" - } - ); - } - if (asyncWebAssembly) { const wasm = { type: "webassembly/async", diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index 2fdfc27ffaf..2172a8d0856 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -1040,7 +1040,6 @@ export type IncrementalRebuildOptions = z.infer< const rspackFutureOptions = z.strictObject({ newTreeshaking: z.boolean().optional(), - disableTransformByDefault: z.boolean().optional(), disableApplyEntryLazily: z.boolean().optional() }); export type RspackFutureOptions = z.infer; diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index a4c25be88b2..dd58c77dea0 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -51,13 +51,15 @@ export { sources }; import { getNormalizedRspackOptions, - applyRspackOptionsDefaults + applyRspackOptionsDefaults, + getRawOptions } from "./config"; export const config = { getNormalizedRspackOptions, applyRspackOptionsDefaults, getNormalizedWebpackOptions: getNormalizedRspackOptions, - applyWebpackOptionsDefaults: applyRspackOptionsDefaults + applyWebpackOptionsDefaults: applyRspackOptionsDefaults, + __internal__getRawOptions: getRawOptions }; export type * from "./config"; diff --git a/packages/rspack/tests/__snapshots__/Defaults.unittest.ts.snap b/packages/rspack/tests/__snapshots__/Defaults.unittest.ts.snap index 15a5d0f88f6..919b5dd97de 100644 --- a/packages/rspack/tests/__snapshots__/Defaults.unittest.ts.snap +++ b/packages/rspack/tests/__snapshots__/Defaults.unittest.ts.snap @@ -27,7 +27,6 @@ exports[`snapshots should have the correct base config 1`] = ` "newSplitChunks": true, "rspackFuture": { "disableApplyEntryLazily": true, - "disableTransformByDefault": true, "newTreeshaking": false, }, "topLevelAwait": true, diff --git a/packages/rspack/tests/configCases/builtins/decorator/foo.ts b/packages/rspack/tests/configCases/builtins/decorator/foo.ts deleted file mode 100644 index 40677afef65..00000000000 --- a/packages/rspack/tests/configCases/builtins/decorator/foo.ts +++ /dev/null @@ -1,20 +0,0 @@ -function methodDecorator(target, name, descriptor) { - const fn = descriptor.value; - descriptor.value = function (...args) { - const res = fn.call(this, ...args); - if (res === undefined) { - return 2; - } - return res; - }; -} -class B { - @methodDecorator - test_return_2() {} - - @methodDecorator - test_return_3() { - return 3; - } -} -export { B }; diff --git a/packages/rspack/tests/configCases/builtins/decorator/index.js b/packages/rspack/tests/configCases/builtins/decorator/index.js deleted file mode 100644 index ccf40ff1f3f..00000000000 --- a/packages/rspack/tests/configCases/builtins/decorator/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import { B } from "./foo"; - -function clsDecorator(cls) { - cls.prototype.a = 1; -} -@clsDecorator -class A {} - -it("should decorator be transformed", () => { - const a = new A(); - expect(a.a).toBe(1); - const b = new B(); - expect(b.test_return_2()).toBe(2); - expect(b.test_return_3()).toBe(3); -}); diff --git a/packages/rspack/tests/configCases/builtins/decorator/tsconfig.json b/packages/rspack/tests/configCases/builtins/decorator/tsconfig.json deleted file mode 100644 index 504cd646e14..00000000000 --- a/packages/rspack/tests/configCases/builtins/decorator/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "experimentalDecorators": true - } -} diff --git a/packages/rspack/tests/configCases/builtins/decorator/webpack.config.js b/packages/rspack/tests/configCases/builtins/decorator/webpack.config.js deleted file mode 100644 index 57f9fc15417..00000000000 --- a/packages/rspack/tests/configCases/builtins/decorator/webpack.config.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - target: ["node", "es2022"], - builtins: {}, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/plugin-import/index.js b/packages/rspack/tests/configCases/builtins/plugin-import/index.js deleted file mode 100644 index 07942dd5fe6..00000000000 --- a/packages/rspack/tests/configCases/builtins/plugin-import/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import { AaBb } from "./src/foo"; -import { CcDd } from "./src/bar"; - -it("should resolve right", () => { - expect(AaBb).toBe("Foo"); - expect(CcDd).toBe("Bar"); -}); diff --git a/packages/rspack/tests/configCases/builtins/plugin-import/src/bar/cc-dd/index.js b/packages/rspack/tests/configCases/builtins/plugin-import/src/bar/cc-dd/index.js deleted file mode 100644 index 91b83d550c7..00000000000 --- a/packages/rspack/tests/configCases/builtins/plugin-import/src/bar/cc-dd/index.js +++ /dev/null @@ -1 +0,0 @@ -export default "Bar"; diff --git a/packages/rspack/tests/configCases/builtins/plugin-import/src/bar/cc-dd/style.css b/packages/rspack/tests/configCases/builtins/plugin-import/src/bar/cc-dd/style.css deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/packages/rspack/tests/configCases/builtins/plugin-import/src/foo/aa-bb/index.js b/packages/rspack/tests/configCases/builtins/plugin-import/src/foo/aa-bb/index.js deleted file mode 100644 index 1b25fd8f4ba..00000000000 --- a/packages/rspack/tests/configCases/builtins/plugin-import/src/foo/aa-bb/index.js +++ /dev/null @@ -1 +0,0 @@ -export default "Foo"; diff --git a/packages/rspack/tests/configCases/builtins/plugin-import/src/foo/aa-bb/style/index.js b/packages/rspack/tests/configCases/builtins/plugin-import/src/foo/aa-bb/style/index.js deleted file mode 100644 index dd37ec7b3e1..00000000000 --- a/packages/rspack/tests/configCases/builtins/plugin-import/src/foo/aa-bb/style/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log("foo-style"); diff --git a/packages/rspack/tests/configCases/builtins/plugin-import/webpack.config.js b/packages/rspack/tests/configCases/builtins/plugin-import/webpack.config.js deleted file mode 100644 index b9de861c05d..00000000000 --- a/packages/rspack/tests/configCases/builtins/plugin-import/webpack.config.js +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = { - module: { - rules: [ - { - test: /.css/, - type: "asset" - } - ] - }, - builtins: { - pluginImport: [ - { - libraryName: "./src/foo", - customName: "./src/foo/{{ kebabCase member }}", - style: true - }, - { - libraryName: "./src/bar", - customName: "./src/bar/{{ kebabCase member }}", - style: `{{ member }}/style.css` - } - ] - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/preset-env/index.js b/packages/rspack/tests/configCases/builtins/preset-env/index.js deleted file mode 100644 index 69c9177c121..00000000000 --- a/packages/rspack/tests/configCases/builtins/preset-env/index.js +++ /dev/null @@ -1,27 +0,0 @@ -const fs = require("fs"); - -it("builtins preset env", () => { - const test = () => 1; - expect(test()).toBe(1); -}); - -it("builtins preset env code check", () => { - const content = fs.readFileSync(__filename, "utf-8"); - expect(content).not.toMatch(/\=\>/); -}); - -it("should transfrom arrow", () => { - const obj = {}; - - function fn() { - expect(this).toBe(obj); - expect(arguments[0]).toBe(1); - const b = () => { - expect(this).toBe(obj); - expect(arguments[0]).toBe(1); - }; - b(); - } - - fn.apply(obj, [1]); -}); diff --git a/packages/rspack/tests/configCases/builtins/preset-env/webpack.config.js b/packages/rspack/tests/configCases/builtins/preset-env/webpack.config.js deleted file mode 100644 index 96bebdf339b..00000000000 --- a/packages/rspack/tests/configCases/builtins/preset-env/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - builtins: { - presetEnv: { - targets: ["chrome 20"] - } - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/provide/webpack.config.js b/packages/rspack/tests/configCases/builtins/provide/webpack.config.js index f0ee4f6c5b2..8dd1ea9f049 100644 --- a/packages/rspack/tests/configCases/builtins/provide/webpack.config.js +++ b/packages/rspack/tests/configCases/builtins/provide/webpack.config.js @@ -19,10 +19,5 @@ module.exports = { process: "./process.js" }, treeShaking: true - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } } }; diff --git a/packages/rspack/tests/configCases/builtins/react-refresh-false/index.jsx b/packages/rspack/tests/configCases/builtins/react-refresh-false/index.jsx deleted file mode 100644 index 1063695cabb..00000000000 --- a/packages/rspack/tests/configCases/builtins/react-refresh-false/index.jsx +++ /dev/null @@ -1,5 +0,0 @@ -function component () { - return
-} - -it('react refresh false should run', () => {}) diff --git a/packages/rspack/tests/configCases/builtins/react-refresh-false/webpack.config.js b/packages/rspack/tests/configCases/builtins/react-refresh-false/webpack.config.js deleted file mode 100644 index 49946feca2a..00000000000 --- a/packages/rspack/tests/configCases/builtins/react-refresh-false/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - builtins: { - react: { - refresh: false - } - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/react-runtime-automic/index.jsx b/packages/rspack/tests/configCases/builtins/react-runtime-automic/index.jsx deleted file mode 100644 index 37406fa8adc..00000000000 --- a/packages/rspack/tests/configCases/builtins/react-runtime-automic/index.jsx +++ /dev/null @@ -1,5 +0,0 @@ -const element =
; - -it("react automatic", () => { - expect(element.type).toBe("div"); -}); diff --git a/packages/rspack/tests/configCases/builtins/react-runtime-automic/webpack.config.js b/packages/rspack/tests/configCases/builtins/react-runtime-automic/webpack.config.js deleted file mode 100644 index 0965c013d89..00000000000 --- a/packages/rspack/tests/configCases/builtins/react-runtime-automic/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - builtins: { - react: { - runtime: "automatic" - } - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/react-runtime-classic/index.jsx b/packages/rspack/tests/configCases/builtins/react-runtime-classic/index.jsx deleted file mode 100644 index 00639c94454..00000000000 --- a/packages/rspack/tests/configCases/builtins/react-runtime-classic/index.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -const element =
; - -it("react classic", () => { - expect(element.type).toBe("div"); -}); diff --git a/packages/rspack/tests/configCases/builtins/react-runtime-classic/webpack.config.js b/packages/rspack/tests/configCases/builtins/react-runtime-classic/webpack.config.js deleted file mode 100644 index de1b84c041c..00000000000 --- a/packages/rspack/tests/configCases/builtins/react-runtime-classic/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - builtins: { - react: { - runtime: "classic" - } - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-custom/custom/MyComponent.graphql.ts b/packages/rspack/tests/configCases/builtins/relay-config-custom/custom/MyComponent.graphql.ts deleted file mode 100644 index bd816eaba4c..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-custom/custom/MyComponent.graphql.ts +++ /dev/null @@ -1 +0,0 @@ -module.exports = 1; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-custom/index.jsx b/packages/rspack/tests/configCases/builtins/relay-config-custom/index.jsx deleted file mode 100644 index 428e75ae807..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-custom/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -const { graphql } = require("react-relay"); - -it("graphql", () => { - const query = graphql` - fragment MyComponent on Type { - field - } - `; - - expect(query).toBe(1); -}); diff --git a/packages/rspack/tests/configCases/builtins/relay-config-custom/webpack.config.js b/packages/rspack/tests/configCases/builtins/relay-config-custom/webpack.config.js deleted file mode 100644 index 347f3e179c2..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-custom/webpack.config.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - builtins: { - relay: { - language: "typescript", - artifactDirectory: "./custom" - } - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-js/custom/MyComponent.graphql.ts b/packages/rspack/tests/configCases/builtins/relay-config-js/custom/MyComponent.graphql.ts deleted file mode 100644 index bd816eaba4c..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-js/custom/MyComponent.graphql.ts +++ /dev/null @@ -1 +0,0 @@ -module.exports = 1; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-js/index.jsx b/packages/rspack/tests/configCases/builtins/relay-config-js/index.jsx deleted file mode 100644 index 428e75ae807..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-js/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -const { graphql } = require("react-relay"); - -it("graphql", () => { - const query = graphql` - fragment MyComponent on Type { - field - } - `; - - expect(query).toBe(1); -}); diff --git a/packages/rspack/tests/configCases/builtins/relay-config-js/relay.config.js b/packages/rspack/tests/configCases/builtins/relay-config-js/relay.config.js deleted file mode 100644 index cb368f17caf..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-js/relay.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - language: "typescript", - artifactDirectory: "./custom" -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-js/webpack.config.js b/packages/rspack/tests/configCases/builtins/relay-config-js/webpack.config.js deleted file mode 100644 index fc616c2afaa..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-js/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - builtins: { - relay: true - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-json/custom/MyComponent.graphql.ts b/packages/rspack/tests/configCases/builtins/relay-config-json/custom/MyComponent.graphql.ts deleted file mode 100644 index bd816eaba4c..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-json/custom/MyComponent.graphql.ts +++ /dev/null @@ -1 +0,0 @@ -module.exports = 1; diff --git a/packages/rspack/tests/configCases/builtins/relay-config-json/index.jsx b/packages/rspack/tests/configCases/builtins/relay-config-json/index.jsx deleted file mode 100644 index 428e75ae807..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-json/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -const { graphql } = require("react-relay"); - -it("graphql", () => { - const query = graphql` - fragment MyComponent on Type { - field - } - `; - - expect(query).toBe(1); -}); diff --git a/packages/rspack/tests/configCases/builtins/relay-config-json/relay.config.json b/packages/rspack/tests/configCases/builtins/relay-config-json/relay.config.json deleted file mode 100644 index a80d534946b..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-json/relay.config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "language": "typescript", - "artifactDirectory": "./custom" -} diff --git a/packages/rspack/tests/configCases/builtins/relay-config-json/webpack.config.js b/packages/rspack/tests/configCases/builtins/relay-config-json/webpack.config.js deleted file mode 100644 index fc616c2afaa..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-config-json/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - builtins: { - relay: true - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-default/__generated__/MyComponent.graphql.js b/packages/rspack/tests/configCases/builtins/relay-default/__generated__/MyComponent.graphql.js deleted file mode 100644 index bd816eaba4c..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-default/__generated__/MyComponent.graphql.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 1; diff --git a/packages/rspack/tests/configCases/builtins/relay-default/index.jsx b/packages/rspack/tests/configCases/builtins/relay-default/index.jsx deleted file mode 100644 index 428e75ae807..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-default/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -const { graphql } = require("react-relay"); - -it("graphql", () => { - const query = graphql` - fragment MyComponent on Type { - field - } - `; - - expect(query).toBe(1); -}); diff --git a/packages/rspack/tests/configCases/builtins/relay-default/webpack.config.js b/packages/rspack/tests/configCases/builtins/relay-default/webpack.config.js deleted file mode 100644 index fc616c2afaa..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-default/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - builtins: { - relay: true - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-json/__generated__/MyComponent.graphql.js b/packages/rspack/tests/configCases/builtins/relay-json/__generated__/MyComponent.graphql.js deleted file mode 100644 index bd816eaba4c..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-json/__generated__/MyComponent.graphql.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 1; diff --git a/packages/rspack/tests/configCases/builtins/relay-json/index.jsx b/packages/rspack/tests/configCases/builtins/relay-json/index.jsx deleted file mode 100644 index 428e75ae807..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-json/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -const { graphql } = require("react-relay"); - -it("graphql", () => { - const query = graphql` - fragment MyComponent on Type { - field - } - `; - - expect(query).toBe(1); -}); diff --git a/packages/rspack/tests/configCases/builtins/relay-json/package.json b/packages/rspack/tests/configCases/builtins/relay-json/package.json deleted file mode 100644 index c7b2e5c1852..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-json/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "relay": { - "language": "javascript" - } -} \ No newline at end of file diff --git a/packages/rspack/tests/configCases/builtins/relay-json/webpack.config.js b/packages/rspack/tests/configCases/builtins/relay-json/webpack.config.js deleted file mode 100644 index fc616c2afaa..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-json/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - builtins: { - relay: true - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-webpack-require/custom/MyComponent.graphql.ts b/packages/rspack/tests/configCases/builtins/relay-webpack-require/custom/MyComponent.graphql.ts deleted file mode 100644 index 0e35d0cbb39..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-webpack-require/custom/MyComponent.graphql.ts +++ /dev/null @@ -1 +0,0 @@ -module.exports = new Error("should never resolved here"); diff --git a/packages/rspack/tests/configCases/builtins/relay-webpack-require/index.js b/packages/rspack/tests/configCases/builtins/relay-webpack-require/index.js deleted file mode 100644 index 8449c845709..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-webpack-require/index.js +++ /dev/null @@ -1,15 +0,0 @@ -const { graphql } = require("react-relay"); - -it("graphql", () => { - // https://github.com/web-infra-dev/rspack/issues/2440 - // This will transformed to require('./custom/MyComponent.graphql.ts'), - // If succeed, `require` would become `__webpack_require__`, - // Then it will resolved to mock.js - const mock = graphql` - fragment MyComponent on Type { - field - } - `; - - expect(mock.found).toBeTruthy(); -}); diff --git a/packages/rspack/tests/configCases/builtins/relay-webpack-require/mock.js b/packages/rspack/tests/configCases/builtins/relay-webpack-require/mock.js deleted file mode 100644 index 7911b6106eb..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-webpack-require/mock.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - found: true -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-webpack-require/relay.config.js b/packages/rspack/tests/configCases/builtins/relay-webpack-require/relay.config.js deleted file mode 100644 index 5ec440eecb7..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-webpack-require/relay.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - language: "typescript", - artifactDirectory: "custom" -}; diff --git a/packages/rspack/tests/configCases/builtins/relay-webpack-require/webpack.config.js b/packages/rspack/tests/configCases/builtins/relay-webpack-require/webpack.config.js deleted file mode 100644 index 3a2566b460b..00000000000 --- a/packages/rspack/tests/configCases/builtins/relay-webpack-require/webpack.config.js +++ /dev/null @@ -1,20 +0,0 @@ -const { resolve } = require("path"); - -module.exports = { - resolve: { - alias: { - [resolve(__dirname, "./custom/MyComponent.graphql.ts")]: resolve( - __dirname, - "./mock.js" - ) - } - }, - builtins: { - relay: true - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/builtins/use-defined-field/index.ts b/packages/rspack/tests/configCases/builtins/use-defined-field/index.ts deleted file mode 100644 index 8b13e7b0a91..00000000000 --- a/packages/rspack/tests/configCases/builtins/use-defined-field/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -class Parent { - time: undefined | number = new Date().valueOf(); -} - -class Child extends Parent { - time: undefined | number; -} - -it("should class use defined field", () => { - const parent = new Parent(); - const child = new Child(); - expect(typeof parent.time).toBe("number"); - expect(typeof child.time).toBe("number"); -}); diff --git a/packages/rspack/tests/configCases/builtins/use-defined-field/webpack.config.js b/packages/rspack/tests/configCases/builtins/use-defined-field/webpack.config.js deleted file mode 100644 index 57f9fc15417..00000000000 --- a/packages/rspack/tests/configCases/builtins/use-defined-field/webpack.config.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - target: ["node", "es2022"], - builtins: {}, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/errors.js b/packages/rspack/tests/configCases/errors/decorator-parse-failed/errors.js similarity index 100% rename from packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/errors.js rename to packages/rspack/tests/configCases/errors/decorator-parse-failed/errors.js diff --git a/packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/foo.js b/packages/rspack/tests/configCases/errors/decorator-parse-failed/foo.js similarity index 100% rename from packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/foo.js rename to packages/rspack/tests/configCases/errors/decorator-parse-failed/foo.js diff --git a/packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/index.js b/packages/rspack/tests/configCases/errors/decorator-parse-failed/index.js similarity index 63% rename from packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/index.js rename to packages/rspack/tests/configCases/errors/decorator-parse-failed/index.js index 2584745ceee..8d5c1180fd4 100644 --- a/packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/index.js +++ b/packages/rspack/tests/configCases/errors/decorator-parse-failed/index.js @@ -1,5 +1,5 @@ -it("should not be able to parse decorator if `disableTransformByDefault` is enabled", () => { +it("should not be able to parse decorator", () => { let error = null; try { require("./foo.js") diff --git a/packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/webpack.config.js b/packages/rspack/tests/configCases/errors/decorator-parse-failed/webpack.config.js similarity index 100% rename from packages/rspack/tests/configCases/errors/experiments-disable-transform-parse-error/webpack.config.js rename to packages/rspack/tests/configCases/errors/decorator-parse-failed/webpack.config.js diff --git a/packages/rspack/tests/configCases/errors/experiments-css-off/errors.js b/packages/rspack/tests/configCases/errors/experiments-css-off/errors.js index 7b0ad699a28..62f8db9c2f8 100644 --- a/packages/rspack/tests/configCases/errors/experiments-css-off/errors.js +++ b/packages/rspack/tests/configCases/errors/experiments-css-off/errors.js @@ -1 +1 @@ -module.exports = [[/Unexpected `ModuleType` found: css/]]; +module.exports = [[/No parser registered for 'css'/]]; diff --git a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.js b/packages/rspack/tests/configCases/errors/mismatched-module-type/app.js deleted file mode 100644 index 5b4e8077083..00000000000 --- a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.js +++ /dev/null @@ -1,4 +0,0 @@ -const React = { - createElement() {} -}; -export const App = () =>
; diff --git a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.jsx b/packages/rspack/tests/configCases/errors/mismatched-module-type/app.jsx deleted file mode 100644 index 5b4e8077083..00000000000 --- a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.jsx +++ /dev/null @@ -1,4 +0,0 @@ -const React = { - createElement() {} -}; -export const App = () =>
; diff --git a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.ts b/packages/rspack/tests/configCases/errors/mismatched-module-type/app.ts deleted file mode 100644 index 5abf3571d6f..00000000000 --- a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.ts +++ /dev/null @@ -1,7 +0,0 @@ -const React = { - createElement(elm: any) {} -}; -function Component() { - return
-} -export const App = () => >; diff --git a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.tsx b/packages/rspack/tests/configCases/errors/mismatched-module-type/app.tsx deleted file mode 100644 index 941ab11c821..00000000000 --- a/packages/rspack/tests/configCases/errors/mismatched-module-type/app.tsx +++ /dev/null @@ -1,7 +0,0 @@ -const React = { - createElement(elm: any) {} -}; -function Component() { - return
; -} -export const App = () => >; diff --git a/packages/rspack/tests/configCases/errors/mismatched-module-type/index.js b/packages/rspack/tests/configCases/errors/mismatched-module-type/index.js deleted file mode 100644 index 55eac1d450b..00000000000 --- a/packages/rspack/tests/configCases/errors/mismatched-module-type/index.js +++ /dev/null @@ -1,39 +0,0 @@ -it("should throw if `jsx` is used in `js`", () => { - let errored = false - try { - require("./app.js"); - } catch(err) { - errored = true - } - expect(errored).toBeTruthy() -}); - -it("should throw if `tsx` is used in `ts`", () => { - let errored = false - try { - require("./app.ts"); - } catch(err) { - errored = true - } - expect(errored).toBeTruthy() -}); - -it("should throw if `jsx` is sat to type `js`", () => { - let errored = false - try { - require("./app.jsx"); - } catch(err) { - errored = true - } - expect(errored).toBeTruthy() -}) - -it("should throw if `tsx` is sat to type `ts`", () => { - let errored = false - try { - require("./app.tsx"); - } catch(err) { - errored = true - } - expect(errored).toBeTruthy() -}) \ No newline at end of file diff --git a/packages/rspack/tests/configCases/errors/mismatched-module-type/webpack.config.js b/packages/rspack/tests/configCases/errors/mismatched-module-type/webpack.config.js deleted file mode 100644 index 9afe138274e..00000000000 --- a/packages/rspack/tests/configCases/errors/mismatched-module-type/webpack.config.js +++ /dev/null @@ -1,26 +0,0 @@ -const path = require("path"); -const resolve = filename => path.resolve(__dirname, filename); - -/** - * @type {import('@rspack/core').RspackOptions} - */ -module.exports = { - context: __dirname, - module: { - rules: [ - { - test: resolve("app.jsx"), - type: "js" - }, - { - test: resolve("app.tsx"), - type: "ts" - }, - ] - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/errors/rule-type-fatal-error/index.js b/packages/rspack/tests/configCases/errors/rule-type-fatal-error/index.js index b15bd0b463f..46b8f16ab5e 100644 --- a/packages/rspack/tests/configCases/errors/rule-type-fatal-error/index.js +++ b/packages/rspack/tests/configCases/errors/rule-type-fatal-error/index.js @@ -1,5 +1,5 @@ -it("should not be able to parse and transform typescript modules if `disableTransformByDefault` is enabled", () => { +it("should not be able to parse and transform typescript modules", () => { let error = null; try { require("./ts") @@ -10,7 +10,7 @@ it("should not be able to parse and transform typescript modules if `disableTran expect(error.message).toContain("Expression expected") }); -it("should not be able to parse and transform tsx modules if `disableTransformByDefault` is enabled", () => { +it("should not be able to parse and transform tsx modules", () => { let error = null; try { require("./tsx") @@ -21,7 +21,7 @@ it("should not be able to parse and transform tsx modules if `disableTransformBy expect(error.message).toContain("Expected '(', got '<'") }); -it("should not be able to parse and transform jsx modules if `disableTransformByDefault` is enabled", () => { +it("should not be able to parse and transform jsx modules", () => { let error = null; try { require("./jsx") diff --git a/packages/rspack/tests/configCases/module/module-type/app.js b/packages/rspack/tests/configCases/module/module-type/app.js deleted file mode 100644 index 5b4e8077083..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/app.js +++ /dev/null @@ -1,4 +0,0 @@ -const React = { - createElement() {} -}; -export const App = () =>
; diff --git a/packages/rspack/tests/configCases/module/module-type/app.jsx b/packages/rspack/tests/configCases/module/module-type/app.jsx deleted file mode 100644 index 5b4e8077083..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/app.jsx +++ /dev/null @@ -1,4 +0,0 @@ -const React = { - createElement() {} -}; -export const App = () =>
; diff --git a/packages/rspack/tests/configCases/module/module-type/app.ts b/packages/rspack/tests/configCases/module/module-type/app.ts deleted file mode 100644 index 1dd8b40d99a..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/app.ts +++ /dev/null @@ -1,4 +0,0 @@ -const React = { - createElement(elm: any) {} -}; -export const App = () =>
; diff --git a/packages/rspack/tests/configCases/module/module-type/app.tsx b/packages/rspack/tests/configCases/module/module-type/app.tsx deleted file mode 100644 index faabb94b40c..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/app.tsx +++ /dev/null @@ -1,10 +0,0 @@ -const React = { - createElement(elm: any) {} -}; -function Component() { - return
; -} - -export function App() { - return >; -} diff --git a/packages/rspack/tests/configCases/module/module-type/index.js b/packages/rspack/tests/configCases/module/module-type/index.js deleted file mode 100644 index 518807096c1..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/index.js +++ /dev/null @@ -1,11 +0,0 @@ -it("should finalize (j|t)sx-in-(j|t)s with internal module type `(j|t)sx`", () => { - require("./app.js"); - require("./app.ts"); -}); - -it("should work with auto module type finalizations", () => { - require("./app.tsx"); - require("./app.jsx"); - require("./lib.ts"); - require("./lib.js"); -}); diff --git a/packages/rspack/tests/configCases/module/module-type/lib.js b/packages/rspack/tests/configCases/module/module-type/lib.js deleted file mode 100644 index ede7bc80d75..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/lib.js +++ /dev/null @@ -1 +0,0 @@ -export const lib = "lib"; diff --git a/packages/rspack/tests/configCases/module/module-type/lib.ts b/packages/rspack/tests/configCases/module/module-type/lib.ts deleted file mode 100644 index 6a4f94f75cf..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/lib.ts +++ /dev/null @@ -1 +0,0 @@ -export const lib: string = "lib"; diff --git a/packages/rspack/tests/configCases/module/module-type/webpack.config.js b/packages/rspack/tests/configCases/module/module-type/webpack.config.js deleted file mode 100644 index 4208b15e8a7..00000000000 --- a/packages/rspack/tests/configCases/module/module-type/webpack.config.js +++ /dev/null @@ -1,26 +0,0 @@ -const path = require("path"); -const resolve = filename => path.resolve(__dirname, filename); - -/** - * @type {import('@rspack/core').RspackOptions} - */ -module.exports = { - context: __dirname, - module: { - rules: [ - { - test: resolve("app.js"), - type: "jsx" - }, - { - test: resolve("app.ts"), - type: "tsx" - } - ] - }, - experiments: { - rspackFuture: { - disableTransformByDefault: false - } - } -}; diff --git a/packages/rspack/tests/configCases/target/web-es5-disable-transform-by-default/index.js b/packages/rspack/tests/configCases/target/web-es5-disable-transform-by-default/index.js deleted file mode 100644 index 40bcb998b8b..00000000000 --- a/packages/rspack/tests/configCases/target/web-es5-disable-transform-by-default/index.js +++ /dev/null @@ -1,4 +0,0 @@ -it("should not use `target` to control user code downgrading with `disableTransformByDefault` enabled", () => { - const a = () => {}; - expect(a.toString()).toContain("=>"); -}); diff --git a/packages/rspack/tests/configCases/target/web-es5/index.js b/packages/rspack/tests/configCases/target/web-es5/index.js new file mode 100644 index 00000000000..bbee2330948 --- /dev/null +++ b/packages/rspack/tests/configCases/target/web-es5/index.js @@ -0,0 +1,4 @@ +it("should not use `target` to control user code downgrading", () => { + const a = () => {}; + expect(a.toString()).toContain("=>"); +}); diff --git a/packages/rspack/tests/configCases/target/web-es5-disable-transform-by-default/webpack.config.js b/packages/rspack/tests/configCases/target/web-es5/webpack.config.js similarity index 100% rename from packages/rspack/tests/configCases/target/web-es5-disable-transform-by-default/webpack.config.js rename to packages/rspack/tests/configCases/target/web-es5/webpack.config.js diff --git a/packages/rspack/tests/diagnostics/factorize/stats.err b/packages/rspack/tests/diagnostics/factorize/stats.err new file mode 100644 index 00000000000..b7b9139e8e1 --- /dev/null +++ b/packages/rspack/tests/diagnostics/factorize/stats.err @@ -0,0 +1,7 @@ +PublicPath: (none) +asset main.js 654 bytes [emitted] (name: main) +Entrypoint main 654 bytes = main.js + +ERROR in × Failed to resolve ./ in project root + +Rspack compiled with 1 error (7b83f020d7fca5c78879) \ No newline at end of file diff --git a/packages/rspack/tests/diagnostics/module-parse-failed/stats.err b/packages/rspack/tests/diagnostics/module-parse-failed/stats.err new file mode 100644 index 00000000000..b7b9139e8e1 --- /dev/null +++ b/packages/rspack/tests/diagnostics/module-parse-failed/stats.err @@ -0,0 +1,7 @@ +PublicPath: (none) +asset main.js 654 bytes [emitted] (name: main) +Entrypoint main 654 bytes = main.js + +ERROR in × Failed to resolve ./ in project root + +Rspack compiled with 1 error (7b83f020d7fca5c78879) \ No newline at end of file