Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/preset-env): update data.rs for core-js3 #7023

Merged
merged 11 commits into from
Mar 11, 2023
166 changes: 118 additions & 48 deletions crates/swc_ecma_preset_env/src/corejs3/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,32 @@ static MAP_DEPENDENCIES: &[&str] = &concat2::<19>(
COMMON_ITERATORS_WITH_TAG,
);

static SET_DEPENDENCIES: &[&str] = &concat2::<21>(
static SET_DEPENDENCIES: &[&str] = &concat2::<28>(
&[
"es.set",
"esnext.set.add-all",
"esnext.set.delete-all",
"esnext.set.difference",
"esnext.set.difference.v2",
"esnext.set.every",
"esnext.set.filter",
"esnext.set.find",
"esnext.set.intersection",
"esnext.set.intersection.v2",
"esnext.set.is-disjoint-from",
"esnext.set.is-disjoint-from.v2",
"esnext.set.is-subset-of",
"esnext.set.is-subset-of.v2",
"esnext.set.is-superset-of",
"esnext.set.is-superset-of.v2",
"esnext.set.join",
"esnext.set.map",
"esnext.set.reduce",
"esnext.set.some",
"esnext.set.symmetric-difference",
"esnext.set.symmetric-difference.v2",
"esnext.set.union",
"esnext.set.union.v2",
],
COMMON_ITERATORS_WITH_TAG,
);
Expand All @@ -120,18 +127,29 @@ static WEAK_SET_DEPENDENCIES: &[&str] = &concat2::<7>(
COMMON_ITERATORS_WITH_TAG,
);

static URL_SEARCH_PARAMS_DEPENDENCIES: &[&str] =
&concat2::<5>(&["web.url-search-params"], COMMON_ITERATORS_WITH_TAG);
static URL_SEARCH_PARAMS_DEPENDENCIES: &[&str] = &concat2::<6>(
&["web.url-search-params", "web.url-search-params.size"],
COMMON_ITERATORS_WITH_TAG,
);

pub static REGEXP_DEPENDENCIES: &[&str] = &["es.regexp.constructor"];
pub static REGEXP_DEPENDENCIES: &[&str] = &[
"es.regexp.constructor",
"es.regexp.dot-all",
"es.regexp.exec",
"es.regexp.sticky",
"es.regexp.to-string",
];

static TYPED_ARRAY: &[&str] = &[
"es.typed-array.at",
"es.typed-array.copy-within",
"es.typed-array.every",
"es.typed-array.fill",
"es.typed-array.filter",
"es.typed-array.find",
"es.typed-array.find-index",
"es.typed-array.find-last",
"es.typed-array.find-last-index",
"es.typed-array.for-each",
"es.typed-array.includes",
"es.typed-array.index-of",
Expand All @@ -148,38 +166,43 @@ static TYPED_ARRAY: &[&str] = &[
"es.typed-array.sort",
"es.typed-array.subarray",
"es.typed-array.to-locale-string",
"es.typed-array.to-reversed",
"es.typed-array.to-sorted",
"es.typed-array.to-string",
"es.typed-array.with",
"es.object.to-string",
"es.array.iterator",
"es.array-buffer.slice",
"esnext.array-buffer.detached",
"esnext.array-buffer.transfer",
"esnext.array-buffer.transfer-to-fixed-length",
"esnext.typed-array.filter-reject",
"esnext.typed-array.find-last",
"esnext.typed-array.find-last-index",
"esnext.typed-array.group-by",
"esnext.typed-array.to-reversed",
"esnext.typed-array.to-sorted",
"esnext.typed-array.to-spliced",
"esnext.typed-array.unique-by",
"esnext.typed-array.with",
];

static FLOAT32_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.float32-array"]);
static FLOAT64_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.float64-array"]);
static INT8_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.int8-array"]);
static INT16_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.int16-array"]);
static INT32_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.int32-array"]);
static UINT8_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.uint8-array"]);
static FLOAT32_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.float32-array"]);
static FLOAT64_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.float64-array"]);
static INT8_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.int8-array"]);
static INT16_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.int16-array"]);
static INT32_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.int32-array"]);
static UINT8_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.uint8-array"]);
static UINT8_CLAMPED_ARRAY: &[&str] =
&concat2::<36>(TYPED_ARRAY, &["es.typed-array.uint8-clamped-array"]);
static UINT16_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.uint16-array"]);
static UINT32_ARRAY: &[&str] = &concat2::<36>(TYPED_ARRAY, &["es.typed-array.uint32-array"]);
&concat2::<40>(TYPED_ARRAY, &["es.typed-array.uint8-clamped-array"]);
static UINT16_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.uint16-array"]);
static UINT32_ARRAY: &[&str] = &concat2::<40>(TYPED_ARRAY, &["es.typed-array.uint32-array"]);

static OBSERVEABLE: &[&str] = &concat2::<6>(
&["esnext.observable", "esnext.symbol.observable"],
static OBSERVEABLE: &[&str] = &concat2::<7>(
&[
"esnext.observable",
"esnext.symbol.observable",
"es.object.to-string",
],
COMMON_ITERATORS_WITH_TAG,
);

static URL_DEP: &[&str] = &concat2::<6>(&["web.url"], URL_SEARCH_PARAMS_DEPENDENCIES);
static URL_DEP: &[&str] = &concat2::<7>(&["web.url"], URL_SEARCH_PARAMS_DEPENDENCIES);

static DOM_EXCEPTION: &[&str] = &[
"web.dom-exception.constructor",
Expand All @@ -202,6 +225,9 @@ static STRUCTURE_CLONE: &[&str] = &concat2::<10>(
);

static ERROR_DEP: &[&str] = &["es.error.cause", "es.error.to-string"];
static SUPPRESSED_ERROR_DEP: &[&str] =
&concat2::<3>(ERROR_DEP, &["esnext.suppressed-error.constructor"]);

static AGGREGATE_ERROR_DEP: &[&str] = &concat2::<8>(
COMMON_ITERATORS_WITH_TAG,
&[
Expand All @@ -212,7 +238,27 @@ static AGGREGATE_ERROR_DEP: &[&str] = &concat2::<8>(
],
);

static DISPOSABLE_STACK_DEP: &[&str] = &concat2::<6>(
SUPPRESSED_ERROR_DEP,
&[
"esnext.disposable-stack.constructor",
"es.object.to-string",
"esnext.iterator.dispose",
],
);

static ASYNC_DISPOSABLE_STACK_DEP: &[&str] = &concat2::<9>(
&concat2::<5>(SUPPRESSED_ERROR_DEP, PROMISE_DEPENDENCIES),
&[
"esnext.async-disposable-stack.constructor",
"es.object.to-string",
"esnext.async-iterator.async-dispose",
"esnext.iterator.dispose",
],
);

pub static BUILTINS: DataMap<&[&str]> = data_map!(Map {
AsyncDisposableStack: ASYNC_DISPOSABLE_STACK_DEP,
AsyncIterator: ASYNC_ITERATOR,
AggregateError: AGGREGATE_ERROR_DEP,
ArrayBuffer: [
Expand All @@ -227,6 +273,7 @@ pub static BUILTINS: DataMap<&[&str]> = data_map!(Map {
],
Date: ["es.date.to-string"],
DOMException: DOM_EXCEPTION,
DisposableStack: DISPOSABLE_STACK_DEP,
Error: ERROR_DEP,
EvalError: ERROR_DEP,
Iterator: ITERATOR,
Expand All @@ -246,13 +293,11 @@ pub static BUILTINS: DataMap<&[&str]> = data_map!(Map {
RangeError: ERROR_DEP,
ReferenceError: ERROR_DEP,
Reflect: ["es.reflect.to-string-tag", "es.object.to-string"],
RegExp: [
"es.regexp.constructor",
"es.regexp.exec",
"es.regexp.to-string"
],
RegExp: REGEXP_DEPENDENCIES,
Set: SET_DEPENDENCIES,
SuppressedError: SUPPRESSED_ERROR_DEP,
Symbol: SYMBOL_DEPENDENCIES,
SyntaxError: ERROR_DEP,
TypeError: ERROR_DEP,
URIError: ERROR_DEP,
URL: URL_DEP,
Expand All @@ -271,6 +316,7 @@ pub static BUILTINS: DataMap<&[&str]> = data_map!(Map {
parseFloat: ["es.parse-float"],
parseInt: ["es.parse-int"],
queueMicrotask: ["web.queue-microtask"],
self: ["web.self"],
setTimeout: ["web.timers"],
setInterval: ["web.timers"],
setImmediate: ["web.immediate"],
Expand Down Expand Up @@ -389,7 +435,7 @@ static PROMISE_FINALLY: &[&str] = &concat2::<3>(&["es.promise.finally"], PROMISE
pub static INSTANCE_PROPERTIES: DataMap<&[&str]> = data_map!(Map {
asIndexedPairs: INDEXED_PAIRS,
// TODO: check type of variable
at: ["es.string.at-alternative", "es.array.at"],
at: ["esnext.string.at", "es.string.at-alternative", "es.array.at"],
anchor: ["es.string.anchor"],
big: ["es.string.big"],
bind: ["es.function.bind"],
Expand Down Expand Up @@ -423,30 +469,35 @@ pub static INSTANCE_PROPERTIES: DataMap<&[&str]> = data_map!(Map {
fontsize: ["es.string.fontsize"],
forEach: FOR_EACH,
getYear: "es.date.get-year",
group: ["esnext.array.group"],
groupBy: "esnext.array.group-by",
groupByToMap: ["esnext.array.group-by-to-map", "es.map", "es.object.to-string"],
groupToMap:["esnext.array.group-to-map", "es.map", "es.object.to-string"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.group is missing.

includes: ["es.array.includes", "es.string.includes"],
indexOf: ["es.array.index-of"],
isWellFormed: ["esnext.string.is-well-formed"],
italics: ["es.string.italics"],
join: ["es.array.join"],
keys: ARRAY_NATURE_ITERATORS_WITH_TAG,
lastIndex: ["esnext.array.last-index"],
lastIndexOf: ["es.array.last-index-of"],
lastItem: ["esnext.array.last-item"],
link: ["es.string.link"],
map: ["es.array.map", "esnext.async-iterator.map", "esnext.iterator.map"],
match: ["es.string.match", "es.regexp.exec"],
matchAll: ["es.string.match-all", "es.regexp.exec"],
map: ["es.array.map"],
name: ["es.function.name"],
padEnd: ["es.string.pad-end"],
padStart: ["es.string.pad-start"],
push: ["es.array.push"],
reduce: REDUCE,
reduceRight: ["es.array.reduce-right"],
repeat: ["es.string.repeat"],
replace: ["es.string.replace", "es.regexp.exec"],
replaceAll: ["es.string.replace-all", "es.string.replace","es.regexp.exec"],
reverse: ["es.array.reverse"],
search: ["es.string.search", "es.regexp.exec"],
setYear: ["es.date.set-year"],
slice: ["es.array.slice"],
small: ["es.string.small"],
some: SOME,
Expand All @@ -469,27 +520,26 @@ pub static INSTANCE_PROPERTIES: DataMap<&[&str]> = data_map!(Map {
toISOString: ["es.date.to-iso-string"],
toJSON: ["es.date.to-json", "web.url.to-json"],
toPrecision: ["es.number.to-precision"],
toString: [
"es.object.to-string",
"es.regexp.to-string",
"es.date.to-string"
],
toSorted: ["esnext.array.to-sorted", "es.array.sort"],
toSpliced: "esnext.array.to-spliced",
toReversed: ["es.array.to-reversed"],
toSorted: ["es.array.to-sorted", "es.array.sort"],
toSpliced: "es.array.to-spliced",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.toReversed is missing.

toString: ["es.object.to-string", "es.error.to-string", "es.date.to-string", "es.regexp.to-string"],
toWellFormed: ["esnext.string.to-well-formed"],
trim: ["es.string.trim"],
trimEnd: ["es.string.trim-end"],
trimLeft: ["es.string.trim-start"],
trimRight: ["es.string.trim-end"],
trimStart: ["es.string.trim-start"],
uniqueBy: ["esnext.array.unique-by", "es.map"],
unshift: ["es.array.unshift"],
unThis: "esnext.function.un-this",
values: ARRAY_NATURE_ITERATORS_WITH_TAG,
with: "esnext.array.with",
with: "es.array.with",
__defineGetter__: ["es.object.define-getter"],
__defineSetter__: ["es.object.define-setter"],
__lookupGetter__: ["es.object.lookup-getter"],
__lookupSetter__: ["es.object.lookup-setter"],
__proto__: ["es.object.proto"],
});

static ASYNC_ITER_FROM: &[&str] = &concat2::<15>(
Expand Down Expand Up @@ -519,8 +569,8 @@ static MAP_GROUP_BY: &[&str] = &concat2::<20>(&["esnext.map.group-by"], MAP_DEPE
static MAP_KEY_BY: &[&str] = &concat2::<20>(&["esnext.map.key-by"], MAP_DEPENDENCIES);
static MAP_OF: &[&str] = &concat2::<20>(&["esnext.map.key-of"], MAP_DEPENDENCIES);

static SET_FROM: &[&str] = &concat2::<22>(&["esnext.set.from"], SET_DEPENDENCIES);
static SET_OF: &[&str] = &concat2::<22>(&["esnext.set.of"], SET_DEPENDENCIES);
static SET_FROM: &[&str] = &concat2::<29>(&["esnext.set.from"], SET_DEPENDENCIES);
static SET_OF: &[&str] = &concat2::<29>(&["esnext.set.of"], SET_DEPENDENCIES);

static WEAK_MAP_FROM: &[&str] = &concat2::<8>(&["esnext.weak-map.from"], WEAK_MAP_DEPENDENCIES);
static WEAK_MAP_OF: &[&str] = &concat2::<8>(&["esnext.weak-map.of"], WEAK_MAP_DEPENDENCIES);
Expand Down Expand Up @@ -557,6 +607,25 @@ pub static STATIC_PROPERTIES: DataMap<DataMap<&[&str]>> = data_map!(Map {
isConstructor: "esnext.function.is-constructor",
},

Iterator: Map {
from: ["esnext.iterator.from"],
range: [
"esnext.iterator.range",
"es.object.to-string",
],
},

JSON: Map {
isRawJSON: ["esnext.json.is-raw-json"],
parse: ["esnext.json.parse", "es.object.keys"],
rawJSON: [
"esnext.json.raw-json",
"es.object.create",
"es.object.freeze",
],
stringify: ["es.json.stringify"],
},

Object: Map {
assign: "es.object.assign",
create: "es.object.create",
Expand Down Expand Up @@ -617,6 +686,11 @@ pub static STATIC_PROPERTIES: DataMap<DataMap<&[&str]>> = data_map!(Map {

String: Map {
cooked: "esnext.string.cooked",
dedent: [
"esnext.string.dedent",
"es.string.from-code-point",
"es.weak-map",
],
fromCodePoint: "es.string.from-code-point",
raw: "es.string.raw",
},
Expand Down Expand Up @@ -697,13 +771,18 @@ pub static STATIC_PROPERTIES: DataMap<DataMap<&[&str]>> = data_map!(Map {
asyncDispose: ["es.symbol.async-dispose"],
asyncIterator: ["es.symbol.async-iterator"],
dispose: ["esnext.symbol.dispose"],
for: ["es.symbol"],
hasInstance: ["es.symbol.has-instance", "es.function.has-instance"],
isConcatSpreadable: ["es.symbol.is-concat-spreadable", "es.array.concat"],
isRegistered: ["esnext.symbol.is-registered", "es.symbol"],
isWellKnown: ["esnext.symbol.is-well-known", "es.symbol"],
iterator: SYMBOL_ITERATOR,
keyFor: ["es.symbol"],
match: ["es.symbol.match", "es.string.match"],
matcher: ["es.symbol.matcher"],
match: ["es.symbol.match-all", "es.string.match-all"],
matchAll: ["es.symbol.match-all", "es.string.match-all"],
metadata: "esnext.symbol.metadata",
metadataKey: ["esnext.symbol.metadata-key"],
observable: ["esnext.symbol.observable"],
patternMatch: ["esnext.symbol.pattern-match"],
replace: ["es.symbol.replace", "es.string.replace"],
Expand Down Expand Up @@ -737,15 +816,6 @@ pub static STATIC_PROPERTIES: DataMap<DataMap<&[&str]>> = data_map!(Map {
},
});

//pub static COMMON_INSTANCE_DEPENDENCIES: &[&str] = &[
// "es.object.to-string",
// "es.object.define-getter",
// "es.object.define-setter",
// "es.object.lookup-getter",
// "es.object.lookup-setter",
// "es.regexp.exec",
//];

pub static POSSIBLE_GLOBAL_OBJECTS: &[&str] = &["global", "globalThis", "self", "window"];

pub static MODULES_BY_VERSION: Lazy<AHashMap<&'static str, Version>> = Lazy::new(|| {
Expand Down