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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target/
/benchmark/node_modules/
/tasks/benchmark/codspeed/node_modules/
/tasks/transform_conformance/node_modules/
/tasks/compat_data/node_modules/

# vscode
/editors/vscode/node_modules/
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
packages:
- 'napi/**'
- 'wasm/**'
- 'npm/**'
- 'editors/**'
- 'tasks/benchmark/codspeed'
- 'tasks/transform_conformance'
- 'npm/**'
- 'tasks/compat_data'

catalog:
"@napi-rs/cli": 3.0.0-alpha.61
Expand Down
1 change: 1 addition & 0 deletions tasks/compat_data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compat-table/
13 changes: 13 additions & 0 deletions tasks/compat_data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "oxc_compat_data"
version = "0.0.0"
edition.workspace = true
license.workspace = true
publish = false

[lints]
workspace = true

[lib]
test = false
doctest = false
1 change: 1 addition & 0 deletions tasks/compat_data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Code extracted from https://github.com/babel/babel/tree/main/packages/babel-compat-data
172 changes: 172 additions & 0 deletions tasks/compat_data/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// https://github.com/babel/babel/blob/main/packages/babel-compat-data/scripts/build-data.js
// https://github.com/babel/babel/blob/main/packages/babel-compat-data/scripts/utils-build-data.js

const fs = require('node:fs');
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');
const compareVersions = require('./compat-table/build-utils/compare-versions');
const { addElectronSupportFromChromium } = require('./chromium-to-electron');

const environments = [
'chrome',
'opera',
'edge',
'firefox',
'safari',
'node',
'deno',
'ie',
'android',
'ios',
// 'phantom',
'samsung',
'rhino',
'opera_mobile',
];

const envsVersions = parseEnvsVersions(envs);

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;

return test.subtests.map(subtest =>
Object.assign({}, subtest, {
name: test.name + ' / ' + subtest.name,
group: test.name,
})
);
})
);

const getLowestImplementedVersion = (
{ features },
env,
exclude = () => false,
) => {
const tests = compatibilityTests.filter(test => {
let ok = features.includes(test.name);
ok ||= test.group && features.includes(test.group);
ok ||= features.length === 1 && test.name.startsWith(features[0]);
ok &&= !exclude(test.name);
return ok;
});

const envTests = tests.map(({ res }) => {
const versions = envsVersions[env];
let i = versions.length - 1;

// Find the last not-implemented version
for (; i >= 0; i--) {
const { id } = versions[i];
// Babel assumes strict mode
if (res[id] !== true && res[id] !== 'strict') {
break;
}
}

return envsVersions[env][i + 1];
});

if (envTests.length === 0 || envTests.some(t => !t)) return null;

const result = envTests.reduce((a, b) => {
return compareVersions(a, b) > 0 ? a : b;
});

// NOTE(bng): A number of environments in compat-table changed to
// include a trailing zero (node10 -> node10_0), so for now stripping
// it to be consistent
return result.version.join('.').replace(/\.0$/, '');
};

const expandFeatures = features =>
features.flatMap(feat => {
if (feat.includes('/')) return [feat];
return compatibilityTests
.map(test => test.name)
.filter(name => name === feat || name.startsWith(feat + ' / '));
});

const generateData = (environments, features) => {
const data = {};

const normalized = {};
for (const [key, options] of Object.entries(features)) {
if (options.overwrite) {
if (!options.replaces || options.features) {
throw new Error(
`.overwrite is only supported when using .replace and not defining .features (${key})`,
);
}
options.features = features[options.replaces].features;
}
if (!options.features) {
normalized[key] = {
features: expandFeatures([options]),
};
} else {
normalized[key] = {
...options,
features: expandFeatures(options.features),
};
}
}

const overlapping = {};

// Apply bugfixes
for (
const [key, { features, replaces, overwrite }] of Object.entries(
normalized,
)
) {
if (replaces) {
if (normalized[replaces].replaces) {
throw new Error(`Transitive replacement is not supported (${key})`);
}

if (overwrite) {
normalized[key] = {
features: normalized[replaces].features,
overwrite,
};
} else {
normalized[replaces].features = normalized[replaces].features.filter(
feat => !features.includes(feat),
);
}

if (!overlapping[replaces]) overlapping[replaces] = [];
overlapping[replaces].push(key);
}
}

// eslint-disable-next-line prefer-const
for (let [key, options] of Object.entries(normalized)) {
const plugin = {};

environments.forEach(env => {
const version = getLowestImplementedVersion(options, env);
if (version) plugin[env] = version;
});
addElectronSupportFromChromium(plugin);

if (options.overwrite) Object.assign(plugin, options.overwrite);

data[key] = plugin;
}

return { data, overlapping };
};

const { data } = generateData(environments, require(`./plugin-features`));

fs.writeFileSync('./data.json', JSON.stringify(data, null, 2));
25 changes: 25 additions & 0 deletions tasks/compat_data/chromium-to-electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// https://github.com/babel/babel/blob/main/packages/babel-compat-data/scripts/chromium-to-electron.js

const chromiumVersions = require('./chromium-versions');
const chromiumVersionList = Object.keys(chromiumVersions);

function chromiumToElectron(version) {
if (chromiumVersions[version]) {
return chromiumVersions[version];
}
const supportedVersion = chromiumVersionList.concat(version);
supportedVersion.sort((a, b) => +a - +b);
const nextSupportedVersion = supportedVersion[supportedVersion.indexOf(version) + 1];
return chromiumVersions[nextSupportedVersion];
}

function addElectronSupportFromChromium(supportData) {
if (supportData.chrome) {
const electronVersion = chromiumToElectron(supportData.chrome);
if (electronVersion) {
supportData.electron = electronVersion;
}
}
}

module.exports.addElectronSupportFromChromium = addElectronSupportFromChromium;
74 changes: 74 additions & 0 deletions tasks/compat_data/chromium-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// https://github.com/Kilian/electron-to-chromium/blob/master/chromium-versions.js

module.exports = {
'39': '0.20',
'40': '0.21',
'41': '0.21',
'42': '0.25',
'43': '0.27',
'44': '0.30',
'45': '0.31',
'47': '0.36',
'49': '0.37',
'50': '1.1',
'51': '1.2',
'52': '1.3',
'53': '1.4',
'54': '1.4',
'56': '1.6',
'58': '1.7',
'59': '1.8',
'61': '2.0',
'66': '3.0',
'69': '4.0',
'72': '5.0',
'73': '5.0',
'76': '6.0',
'78': '7.0',
'79': '8.0',
'80': '8.0',
'82': '9.0',
'83': '9.0',
'84': '10.0',
'85': '10.0',
'86': '11.0',
'87': '11.0',
'89': '12.0',
'90': '13.0',
'91': '13.0',
'92': '14.0',
'93': '14.0',
'94': '15.0',
'95': '16.0',
'96': '16.0',
'98': '17.0',
'99': '18.0',
'100': '18.0',
'102': '19.0',
'103': '20.0',
'104': '20.0',
'105': '21.0',
'106': '21.0',
'107': '22.0',
'108': '22.0',
'110': '23.0',
'111': '24.0',
'112': '24.0',
'114': '25.0',
'116': '26.0',
'118': '27.0',
'119': '28.0',
'120': '28.0',
'121': '29.0',
'122': '29.0',
'123': '30.0',
'124': '30.0',
'125': '31.0',
'126': '31.0',
'127': '32.0',
'128': '32.0',
'129': '33.0',
'130': '33.0',
'131': '34.0',
'132': '34.0',
};
10 changes: 10 additions & 0 deletions tasks/compat_data/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "compat-data",
"scripts": {
"init": "degit compat-table/compat-table#4fd1acb5bdd34846cb18887310f7a8000989c34e compat-table",
"build": "node build.js"
},
"devDependencies": {
"degit": "2.8.4"
}
}
Loading