Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/oxc_compat/src/es_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2015TemplateLiterals,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(8u16, 0u16, 0u16)),
(Node, Version(8u16, 10u16, 0u16)),
(Node, Version(10u16, 0u16, 0u16)),
(Firefox, Version(53u16, 0u16, 0u16)),
(Chrome, Version(62u16, 0u16, 0u16)),
(Safari, Version(13u16, 0u16, 0u16)),
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2015Classes,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(5u16, 0u16, 0u16)),
(Node, Version(5u16, 0u16, 0u16)),
(Node, Version(6u16, 0u16, 0u16)),
(Firefox, Version(45u16, 0u16, 0u16)),
(Chrome, Version(46u16, 0u16, 0u16)),
(Safari, Version(10u16, 0u16, 0u16)),
Expand All @@ -250,7 +250,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2015ObjectSuper,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(5u16, 0u16, 0u16)),
(Node, Version(5u16, 0u16, 0u16)),
(Node, Version(6u16, 0u16, 0u16)),
(Firefox, Version(45u16, 0u16, 0u16)),
(Chrome, Version(46u16, 0u16, 0u16)),
(Safari, Version(10u16, 0u16, 0u16)),
Expand Down Expand Up @@ -390,7 +390,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2015Spread,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(5u16, 0u16, 0u16)),
(Node, Version(5u16, 0u16, 0u16)),
(Node, Version(6u16, 0u16, 0u16)),
(Firefox, Version(45u16, 0u16, 0u16)),
(Chrome, Version(46u16, 0u16, 0u16)),
(Safari, Version(10u16, 0u16, 0u16)),
Expand Down Expand Up @@ -441,7 +441,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2015TypeofSymbol,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(3u16, 0u16, 0u16)),
(Node, Version(0u16, 12u16, 0u16)),
(Node, Version(4u16, 0u16, 0u16)),
(Firefox, Version(36u16, 0u16, 0u16)),
(Chrome, Version(38u16, 0u16, 0u16)),
(Safari, Version(9u16, 0u16, 0u16)),
Expand Down Expand Up @@ -684,7 +684,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2020OptionalChaining,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(16u16, 0u16, 0u16)),
(Node, Version(16u16, 9u16, 0u16)),
(Node, Version(16u16, 1u16, 0u16)),
(Firefox, Version(74u16, 0u16, 0u16)),
(Chrome, Version(91u16, 0u16, 0u16)),
(Safari, Version(13u16, 1u16, 0u16)),
Expand Down Expand Up @@ -771,7 +771,7 @@ pub fn features() -> &'static FxHashMap<ESFeature, EngineTargets> {
ES2022PrivatePropertyInObject,
EngineTargets::new(FxHashMap::from_iter([
(Samsung, Version(16u16, 0u16, 0u16)),
(Node, Version(16u16, 9u16, 0u16)),
(Node, Version(16u16, 4u16, 0u16)),
(Firefox, Version(90u16, 0u16, 0u16)),
(Chrome, Version(91u16, 0u16, 0u16)),
(Safari, Version(15u16, 0u16, 0u16)),
Expand Down
10 changes: 8 additions & 2 deletions tasks/compat_data/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Compat Data

Get engine compatibility Data from https://github.com/compat-table/compat-table/
Get engine compatibility data from

Code extracted from https://github.com/babel/babel/tree/v7.26.2/packages/babel-compat-data
- https://github.com/compat-table/compat-table/
- https://github.com/compat-table/node-compat-table

Code extracted from

- https://github.com/babel/babel/tree/v7.26.2/packages/babel-compat-data
- https://github.com/evanw/esbuild/blob/v0.27.2/compat-table/src/kangax.ts

## Adding a new feature

Expand Down
105 changes: 100 additions & 5 deletions tasks/compat_data/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// https://github.com/babel/babel/blob/v7.26.2/packages/babel-compat-data/scripts/utils-build-data.js

const fs = require("node:fs");
const path = require("node:path");
const envs = require("./compat-table/environments");
const parseEnvsVersions = require("./compat-table/build-utils/parse-envs-versions");
const interpolateAllResults = require("./compat-table/build-utils/interpolate-all-results");
Expand All @@ -28,25 +29,119 @@ const environments = [
];

const envsVersions = parseEnvsVersions(envs);
// Override node versions
const nodeVersions = require("fs")
.readFileSync("../coverage/node-compat-table/v8.versions")
.toString()
.replace(/v/g, "")
.trim()
.split("\n")
.reverse()
.map((version) => {
const versions = version.split(".").map((n) => parseInt(n, 10));
return {
id: "node" + versions.join("_"),
name: "node",
version: versions,
};
});
const es5NodeVersions = new Set(["node0_4", "node0_6", "node0_8"]);
const es5EnvsVersions = envsVersions["node"].filter((n) => es5NodeVersions.has(n.id));
envsVersions["node"] = es5EnvsVersions.concat(nodeVersions);

const compatSources = ["es5", "es6", "es2016plus", "esnext"].map((source) => {
const data = require(`./compat-table/data-${source}`);
interpolateAllResults(data.tests, envs);
return data;
});

const compatibilityTests = compatSources.flatMap((data) =>
data.tests.flatMap((test) => {
if (!test.subtests) return test;
const reformatNodeCompatTable = () => {
const nodeCompatTableDir = path.join(__dirname, "../coverage/node-compat-table/results/v8");
const testMap = {};
const subtestMap = {};
const tests = [];

// Format the data like the kangax table
for (const entry of fs.readdirSync(nodeCompatTableDir)) {
// Note: this omits data for the "0.x.y" releases because the data isn't clean
const match = /^([1-9]\d*\.\d+\.\d+)\.json$/.exec(entry);
if (match) {
const version = "node" + match[1].replace(/\./g, "_");
const jsonPath = path.join(nodeCompatTableDir, entry);
const json = JSON.parse(fs.readFileSync(jsonPath, "utf8"));

for (const key in json) {
if (key.startsWith("ES")) {
const object = json[key];

for (const key in object) {
const testResult = object[key];
const split = key.replace("<code>", "").replace("</code>", "").split("›");

if (split.length === 2) {
let test = testMap[split[1]];
if (!test) {
test = testMap[split[1]] = { name: split[1], res: {} };
tests.push(test);
}
test.res[version] = testResult;
} else if (split.length === 3) {
const subtestKey = `${split[1]}: ${split[2]}`;
let subtest = subtestMap[subtestKey];
if (!subtest) {
let test = testMap[split[1]];
if (!test) {
test = testMap[split[1]] = { name: split[1], res: {} };
tests.push(test);
}
subtest = subtestMap[subtestKey] = { name: split[2], res: {} };
test.subtests ||= [];
test.subtests.push(subtest);
}
subtest.res[version] = testResult;
}
}
}
}
}
}

return tests;
};

const flattenFeatureData = (tests) => {
return tests.flatMap((test) => {
if (!test.subtests) return test;
return test.subtests.map((subtest) =>
Object.assign({}, subtest, {
name: test.name + " / " + subtest.name,
group: test.name,
}),
);
}),
);
});
};

const compatibilityTests = compatSources.flatMap((data) => flattenFeatureData(data.tests));
const nodeTests = flattenFeatureData(reformatNodeCompatTable());

// Merge nodeTests into compatibilityTests
compatibilityTests.forEach((t) => {
const found = nodeTests.find((test) => t.name == test.name);
if (found) {
// Remove all node data from compatibilityTests then merge nodeTests into it.
Object.keys(t.res).forEach((key) => {
if (key.startsWith("node")) {
t.res[key] = undefined;
}
});
Object.assign(t.res, found.res);
} else {
// Add missing node data.
nodeVersions.forEach((v) => {
t.res[v.id] = true;
});
}
});

const getLowestImplementedVersion = ({ features }, env, exclude = () => false) => {
const tests = compatibilityTests.filter((test) => {
Expand Down
Loading
Loading