fix(es/preset-env): Fix default target (#6921)

**Description:**

Previously the default value of `targets` was `""`, which is not deterministic.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6888.
This commit is contained in:
Donny/강동윤 2023-02-09 14:08:41 +09:00 committed by GitHub
parent fe095e9dc1
commit 85a8defc37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 255 additions and 36 deletions

View File

@ -1,6 +1,6 @@
var e = 1;
try {
throw 2;
} catch {
} catch (e1) {
console.log(e);
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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;
})()();

View File

@ -1,4 +1,4 @@
const c = /*#__PURE__*/ React.createElement("img", {
var c = /*#__PURE__*/ React.createElement("img", {
alt: "caf\xe9"
}).props.alt;
console.log(c);

View File

@ -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,

View File

@ -0,0 +1,14 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
},
"minify": false,
"isModule": true,
"env": {
"mode": "usage",
"coreJs": "3.27.2"
}
}

View File

@ -0,0 +1,3 @@
'test'.replaceAll('', '');
'1.2.3'.split('.').at(-1);
[123].at(1);

View File

@ -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);

View File

@ -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"));
}

View File

@ -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"));
}

View File

@ -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"));
}

View File

@ -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",

View File

@ -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<Version>,
#[serde(default = "default_targets")]
#[serde(default)]
pub targets: Option<Targets>,
#[serde(default = "default_path")]
@ -581,10 +581,6 @@ pub struct Config {
pub bugfixes: bool,
}
fn default_targets() -> Option<Targets> {
Some(Targets::Query(Query::Single("".into())))
}
fn default_path() -> PathBuf {
if cfg!(target_arch = "wasm32") {
Default::default()