diff --git a/crates/swc/tests/fixture/issues-1xxx/1402/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1402/case1/output/index.ts index 11f3f0383c4..dda230d06d2 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1402/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1402/case1/output/index.ts @@ -1,6 +1,6 @@ var e = 1; try { throw 2; -} catch { +} catch (e1) { console.log(e); } diff --git a/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts index c83f9e21883..9694556cf46 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1448/case1/output/index.ts @@ -1,4 +1,4 @@ import { createRequire as _createRequire } from "module"; -const __require = _createRequire(import.meta.url); -const F = __require("yaml"); +var __require = _createRequire(import.meta.url); +var F = __require("yaml"); console.log(F); diff --git a/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts b/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts index 01d3e8e0eda..a138f7f9c59 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts +++ b/crates/swc/tests/fixture/issues-1xxx/1568/case1/output/index.ts @@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", { }); Object.defineProperty(exports, "default", { enumerable: true, - get: ()=>get + get: function() { + return get; + } }); function get(key) { console.log(key); diff --git a/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js index 48f220be654..a81d8749ac1 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1714/case1/output/index.js @@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", { }); Object.defineProperty(exports, "render", { enumerable: true, - get: ()=>_customRender.customRender + get: function() { + return _customRender.customRender; + } }); -const _exportStar = require("@swc/helpers/lib/_export_star.js").default; -const _customRender = require("./customRender"); +var _exportStar = require("@swc/helpers/lib/_export_star.js").default; +var _customRender = require("./customRender"); _exportStar(require("@testing-library/react"), exports); diff --git a/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js index d34a8d3f0bb..b4723ad02c0 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1721/case1/output/index.js @@ -1,10 +1,129 @@ -async function* lol() { - yield 1; - yield 2; +import _async_iterator from "@swc/helpers/src/_async_iterator.mjs"; +import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; +import _wrap_async_generator from "@swc/helpers/src/_wrap_async_generator.mjs"; +import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; +function lol() { + return _lol.apply(this, arguments); } -async function main() { - for await (const x of lol()){ - console.log(x); - } +function _lol() { + _lol = _wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + 1 + ]; + case 1: + _state.sent(); + return [ + 4, + 2 + ]; + case 2: + _state.sent(); + return [ + 2 + ]; + } + }); + }); + return _lol.apply(this, arguments); +} +function main() { + return _main.apply(this, arguments); +} +function _main() { + _main = _async_to_generator(function() { + var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, x, err; + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + _iteratorAbruptCompletion = false, _didIteratorError = false; + _state.label = 1; + case 1: + _state.trys.push([ + 1, + 6, + 7, + 12 + ]); + _iterator = _async_iterator(lol()); + _state.label = 2; + case 2: + return [ + 4, + _iterator.next() + ]; + case 3: + if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [ + 3, + 5 + ]; + _value = _step.value; + x = _value; + console.log(x); + _state.label = 4; + case 4: + _iteratorAbruptCompletion = false; + return [ + 3, + 2 + ]; + case 5: + return [ + 3, + 12 + ]; + case 6: + err = _state.sent(); + _didIteratorError = true; + _iteratorError = err; + return [ + 3, + 12 + ]; + case 7: + _state.trys.push([ + 7, + , + 10, + 11 + ]); + if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) return [ + 3, + 9 + ]; + return [ + 4, + _iterator["return"]() + ]; + case 8: + _state.sent(); + _state.label = 9; + case 9: + return [ + 3, + 11 + ]; + case 10: + if (_didIteratorError) { + throw _iteratorError; + } + return [ + 7 + ]; + case 11: + return [ + 7 + ]; + case 12: + return [ + 2 + ]; + } + }); + }); + return _main.apply(this, arguments); } main(); diff --git a/crates/swc/tests/fixture/issues-1xxx/1722/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1722/case1/output/index.js index db896fdbfab..f97ff32dfe9 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1722/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1722/case1/output/index.js @@ -1,3 +1,16 @@ -(async function main() { - console.log(1); -})(); +import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; +import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; +(function() { + var _main = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + console.log(1); + return [ + 2 + ]; + }); + }); + function main() { + return _main.apply(this, arguments); + } + return main; +})()(); diff --git a/crates/swc/tests/fixture/issues-2xxx/2154/case1/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2154/case1/output/index.js index 644e5fc459e..642ef4f8994 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2154/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2154/case1/output/index.js @@ -1,4 +1,4 @@ -const c = /*#__PURE__*/ React.createElement("img", { +var c = /*#__PURE__*/ React.createElement("img", { alt: "caf\xe9" }).props.alt; console.log(c); diff --git a/crates/swc/tests/fixture/issues-6xxx/6460/1/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6460/1/output/index.js index e403c84112d..2c8db54a8b5 100644 --- a/crates/swc/tests/fixture/issues-6xxx/6460/1/output/index.js +++ b/crates/swc/tests/fixture/issues-6xxx/6460/1/output/index.js @@ -1,5 +1,7 @@ import "core-js/modules/es.array.at.js"; +import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/es.string.at-alternative.js"; +import "core-js/modules/es.string.split.js"; "1.2.3".split(".").at(-1); [ 123, diff --git a/crates/swc/tests/fixture/issues-6xxx/6888/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6888/input/.swcrc new file mode 100644 index 00000000000..edb66e462cb --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6888/input/.swcrc @@ -0,0 +1,14 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": false + }, + }, + "minify": false, + "isModule": true, + "env": { + "mode": "usage", + "coreJs": "3.27.2" + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6888/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6888/input/index.js new file mode 100644 index 00000000000..04fa229d4a1 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6888/input/index.js @@ -0,0 +1,3 @@ +'test'.replaceAll('', ''); +'1.2.3'.split('.').at(-1); +[123].at(1); diff --git a/crates/swc/tests/fixture/issues-6xxx/6888/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6888/output/index.js new file mode 100644 index 00000000000..317f04e882d --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6888/output/index.js @@ -0,0 +1,11 @@ +import "core-js/modules/es.array.at.js"; +import "core-js/modules/es.regexp.exec.js"; +import "core-js/modules/es.string.at-alternative.js"; +import "core-js/modules/es.string.replace-all.js"; +import "core-js/modules/es.string.replace.js"; +import "core-js/modules/es.string.split.js"; +"test".replaceAll("", ""); +"1.2.3".split(".").at(-1); +[ + 123 +].at(1); diff --git a/crates/swc/tests/fixture/shopify/003-env/output/index.js b/crates/swc/tests/fixture/shopify/003-env/output/index.js index 2eafd6f5b2a..a7974d80c5b 100644 --- a/crates/swc/tests/fixture/shopify/003-env/output/index.js +++ b/crates/swc/tests/fixture/shopify/003-env/output/index.js @@ -4,12 +4,15 @@ Object.defineProperty(exports, "__esModule", { }); Object.defineProperty(exports, "App", { enumerable: true, - get: ()=>App + get: function() { + return App; + } }); -const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; -const _react = /*#__PURE__*/ _interopRequireDefault(require("react")); -const _reactI18N = require("@shopify/react-i18n"); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default; +var _react = /*#__PURE__*/ _interopRequireDefault(require("react")); +var _reactI18N = require("@shopify/react-i18n"); function App() { - const [i18n] = (0, _reactI18N.useI18n)(); + var _useI18n = _slicedToArray((0, _reactI18N.useI18n)(), 1), i18n = _useI18n[0]; return /*#__PURE__*/ _react.default.createElement("h1", null, i18n.translate("foo")); } diff --git a/crates/swc/tests/fixture/shopify/004-jest/output/index.js b/crates/swc/tests/fixture/shopify/004-jest/output/index.js index 2eafd6f5b2a..a7974d80c5b 100644 --- a/crates/swc/tests/fixture/shopify/004-jest/output/index.js +++ b/crates/swc/tests/fixture/shopify/004-jest/output/index.js @@ -4,12 +4,15 @@ Object.defineProperty(exports, "__esModule", { }); Object.defineProperty(exports, "App", { enumerable: true, - get: ()=>App + get: function() { + return App; + } }); -const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; -const _react = /*#__PURE__*/ _interopRequireDefault(require("react")); -const _reactI18N = require("@shopify/react-i18n"); +var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; +var _slicedToArray = require("@swc/helpers/lib/_sliced_to_array.js").default; +var _react = /*#__PURE__*/ _interopRequireDefault(require("react")); +var _reactI18N = require("@shopify/react-i18n"); function App() { - const [i18n] = (0, _reactI18N.useI18n)(); + var _useI18n = _slicedToArray((0, _reactI18N.useI18n)(), 1), i18n = _useI18n[0]; return /*#__PURE__*/ _react.default.createElement("h1", null, i18n.translate("foo")); } diff --git a/crates/swc/tests/fixture/shopify/005-no-module/output/index.js b/crates/swc/tests/fixture/shopify/005-no-module/output/index.js index fbe16db1b69..2bc9aab6794 100644 --- a/crates/swc/tests/fixture/shopify/005-no-module/output/index.js +++ b/crates/swc/tests/fixture/shopify/005-no-module/output/index.js @@ -1,6 +1,7 @@ +import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; import React from "react"; import { useI18n } from "@shopify/react-i18n"; export function App() { - const [i18n] = useI18n(); + var _useI18n = _sliced_to_array(useI18n(), 1), i18n = _useI18n[0]; return /*#__PURE__*/ React.createElement("h1", null, i18n.translate("foo")); } diff --git a/crates/swc_ecma_preset_env/data/core-js-compat/data.json b/crates/swc_ecma_preset_env/data/core-js-compat/data.json index 67beb394348..9c6d63bc0cd 100644 --- a/crates/swc_ecma_preset_env/data/core-js-compat/data.json +++ b/crates/swc_ecma_preset_env/data/core-js-compat/data.json @@ -435,6 +435,7 @@ "opera-android": "65", "opera_mobile": "65", "quest": "17.0", + "react-native": "0.71", "safari": "15.4", "samsung": "16.0" }, @@ -3447,6 +3448,7 @@ "opera-android": "47", "opera_mobile": "47", "quest": "5.0", + "react-native": "0.71", "safari": "11.1", "samsung": "9.0" }, @@ -3561,6 +3563,7 @@ "opera-android": "65", "opera_mobile": "65", "quest": "17.0", + "react-native": "0.71", "safari": "15.4", "samsung": "16.0" }, @@ -3830,6 +3833,7 @@ "opera-android": "47", "opera_mobile": "47", "quest": "5.0", + "react-native": "0.71", "safari": "14.0", "samsung": "9.0" }, @@ -4493,6 +4497,7 @@ "opera-android": "65", "opera_mobile": "65", "quest": "17.0", + "react-native": "0.71", "safari": "15.4", "samsung": "16.0" }, @@ -5194,6 +5199,7 @@ "opera-android": "65", "opera_mobile": "65", "quest": "17.0", + "react-native": "0.71", "safari": "15.4", "samsung": "16.0" }, @@ -5255,28 +5261,52 @@ "esnext.array.last-index": {}, "esnext.array.last-item": {}, "esnext.array.to-reversed": { + "android": "110", "bun": "0.1.1", + "chrome": "110", + "chrome-android": "110", "deno": "1.27", + "edge": "110", + "electron": "23.0", "ios": "16.0", + "opera": "96", "safari": "16.0" }, "esnext.array.to-sorted": { + "android": "110", "bun": "0.1.1", + "chrome": "110", + "chrome-android": "110", "deno": "1.27", + "edge": "110", + "electron": "23.0", "ios": "16.0", + "opera": "96", "safari": "16.0" }, "esnext.array.to-spliced": { + "android": "110", "bun": "0.1.1", + "chrome": "110", + "chrome-android": "110", "deno": "1.27", + "edge": "110", + "electron": "23.0", "ios": "16.0", + "opera": "96", "safari": "16.0" }, "esnext.array.unique-by": {}, "esnext.array.with": { + "android": "110", "bun": "0.1.1", + "chrome": "110", + "chrome-android": "110", "deno": "1.27", + "edge": "110", + "electron": "23.0", "ios": "16.0", + "opera": "96", "safari": "16.0" }, "esnext.async-disposable-stack.constructor": {}, @@ -5559,6 +5589,7 @@ "opera-android": "65", "opera_mobile": "65", "quest": "17.0", + "react-native": "0.71", "safari": "15.4", "samsung": "16.0" }, @@ -5610,22 +5641,40 @@ }, "esnext.typed-array.group-by": {}, "esnext.typed-array.to-reversed": { + "android": "110", "bun": "0.1.1", + "chrome": "110", + "chrome-android": "110", "deno": "1.27", + "edge": "110", + "electron": "23.0", "ios": "16.0", + "opera": "96", "safari": "16.0" }, "esnext.typed-array.to-sorted": { + "android": "110", "bun": "0.1.1", + "chrome": "110", + "chrome-android": "110", "deno": "1.27", + "edge": "110", + "electron": "23.0", "ios": "16.0", + "opera": "96", "safari": "16.0" }, "esnext.typed-array.to-spliced": {}, "esnext.typed-array.unique-by": {}, "esnext.typed-array.with": { + "android": "110", "bun": "0.1.9", - "deno": "1.27" + "chrome": "110", + "chrome-android": "110", + "deno": "1.27", + "edge": "110", + "electron": "23.0", + "opera": "96" }, "esnext.weak-map.delete-all": {}, "esnext.weak-map.from": {}, @@ -5798,6 +5847,7 @@ "android": "86", "chrome": "86", "chrome-android": "86", + "deno": "1.29.3", "edge": "86", "electron": "11.0", "firefox": "31", diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 1811850663e..2ffaa2fefe5 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; -use preset_env_base::query::{targets_to_versions, Query}; +use preset_env_base::query::targets_to_versions; pub use preset_env_base::{query::Targets, version::Version, BrowserData, Versions}; use regenerator::RegeneratorVisitor; use serde::Deserialize; @@ -565,7 +565,7 @@ pub struct Config { #[serde(default)] pub core_js: Option, - #[serde(default = "default_targets")] + #[serde(default)] pub targets: Option, #[serde(default = "default_path")] @@ -581,10 +581,6 @@ pub struct Config { pub bugfixes: bool, } -fn default_targets() -> Option { - Some(Targets::Query(Query::Single("".into()))) -} - fn default_path() -> PathBuf { if cfg!(target_arch = "wasm32") { Default::default()