Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Refactor browser data parsing to handle families #208

Merged
merged 2 commits into from
Mar 14, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions data/built-ins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"es6.typed.data-view": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 15,
"safari": 5,
"node": 0.12,
Expand All @@ -12,6 +13,7 @@
"es6.typed.int8-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -22,6 +24,7 @@
"es6.typed.uint8-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -42,6 +45,7 @@
"es6.typed.int16-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -52,6 +56,7 @@
"es6.typed.uint16-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -62,6 +67,7 @@
"es6.typed.int32-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -72,6 +78,7 @@
"es6.typed.uint32-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -82,6 +89,7 @@
"es6.typed.float32-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -92,6 +100,7 @@
"es6.typed.float64-array": {
"chrome": 5,
"opera": 12,
"edge": 12,
"firefox": 4,
"safari": 5,
"node": 0.12,
Expand All @@ -101,6 +110,7 @@
},
"es6.map": {
"chrome": 51,
"edge": 15,
"firefox": 53,
"safari": 10,
"node": 6.5,
Expand All @@ -109,6 +119,7 @@
},
"es6.set": {
"chrome": 51,
"edge": 15,
"firefox": 53,
"safari": 10,
"node": 6.5,
Expand All @@ -117,6 +128,7 @@
},
"es6.weak-map": {
"chrome": 51,
"edge": 15,
"firefox": 53,
"safari": 9,
"node": 6.5,
Expand Down Expand Up @@ -286,6 +298,7 @@
},
"es6.object.set-prototype-of": {
"chrome": 34,
"edge": 12,
"firefox": 31,
"safari": 9,
"node": 0.12,
Expand Down
3 changes: 3 additions & 0 deletions data/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"transform-es2015-block-scoped-functions": {
"chrome": 41,
"edge": 12,
"firefox": 46,
"safari": 10,
"node": 4,
Expand All @@ -19,6 +20,7 @@
},
"transform-es2015-block-scoping": {
"chrome": 49,
"edge": 14,
"firefox": 51,
"safari": 10,
"node": 6,
Expand All @@ -45,6 +47,7 @@
},
"check-es2015-constants": {
"chrome": 49,
"edge": 14,
"firefox": 51,
"safari": 10,
"node": 6,
Expand Down
133 changes: 83 additions & 50 deletions scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,87 @@ const path = require("path");
const flatten = require("lodash/flatten");
const flattenDeep = require("lodash/flattenDeep");
const mapValues = require("lodash/mapValues");
const pickBy = require("lodash/pickBy");
const pluginFeatures = require("../data/plugin-features");
const builtInFeatures = require("../data/built-in-features");

const renameTests = (tests, getName) =>
tests.map((test) => Object.assign({}, test, { name: getName(test.name) }));

const es6Data = require("compat-table/data-es6");
const es6PlusData = require("compat-table/data-es2016plus");
// The following is adapted from compat-table:
// https://github.com/kangax/compat-table/blob/gh-pages/build.js
//
// It parses and interpolates data so environments that "equal" other
// environments (node4 and chrome45), as well as familial relationships (edge
// and ie11) can be handled properly.

const envs = require("compat-table/environments");

const byTestSuite = (suite) => (browser) => {
return Array.isArray(browser.test_suites)
? browser.test_suites.indexOf(suite) > -1
: true;
};

const es6 = require("compat-table/data-es6");
es6.browsers = pickBy(envs, byTestSuite("es6"));

const es2016plus = require("compat-table/data-es2016plus");
es2016plus.browsers = pickBy(envs, byTestSuite("es2016plus"));

const interpolateAllResults = (rawBrowsers, tests) => {
const interpolateResults = (res) => {
let browser;
let prevBrowser;
let result;
let prevResult;
let prevBid;

for (const bid in rawBrowsers) {
// For browsers that are essentially equal to other browsers,
// copy over the results.
browser = rawBrowsers[bid];
if (browser.equals && res[bid] === undefined) {
result = res[browser.equals];
res[bid] = browser.ignore_flagged && result === "flagged" ? false : result;
// For each browser, check if the previous browser has the same
// browser full name (e.g. Firefox) or family name (e.g. Chakra) as this one.
} else if (
prevBrowser &&
(prevBrowser.full.replace(/,.+$/, "") === browser.full.replace(/,.+$/, "") ||
(browser.family !== undefined && prevBrowser.family === browser.family))
) {
// For each test, check if the previous browser has a result
// that this browser lacks.
result = res[bid];
prevResult = res[prevBid];
if (prevResult !== undefined && result === undefined) {
res[bid] = prevResult;
}
}
prevBrowser = browser;
prevBid = bid;
}
};

// Now print the results.
tests.forEach(function(t) {
// Calculate the result totals for tests which consist solely of subtests.
if ("subtests" in t) {
t.subtests.forEach(function(e) {
interpolateResults(e.res);
});
} else {
interpolateResults(t.res);
}
});
};

interpolateAllResults(es6.browsers, es6.tests);
interpolateAllResults(es2016plus.browsers, es2016plus.tests);

// End of compat-table code adaptation

const environments = [
"chrome",
"opera",
Expand Down Expand Up @@ -51,38 +122,9 @@ const envMap = {
ios51: "ios5.1",
};

const invertedEqualsEnv = Object.keys(envs)
.filter((b) => envs[b].equals)
.reduce((a, b) => {
const checkEnv = envMap[envs[b].equals] || envs[b].equals;
environments.some((env) => {
// go through all environment names to find the the current one
// and try to get the version as integer
const version = parseFloat(checkEnv.replace(env, ""));
if (!isNaN(version)) {
Object.keys(envs).forEach((equals) => {
equals = envMap[equals] || equals;
// Go through all envs from compat-table and get int version
const equalsVersion = parseFloat(equals.replace(env, ""));
// If the current version is smaller than the version that was mentioned
// in `equals` we can add an entry, as older versions should include features
// that newer ones have
if (!isNaN(equalsVersion) && equalsVersion <= version) {
if (!a[equals]) a[equals] = [];
if (a[equals].indexOf(b) >= 0) return;
a[equals].push(b);
}
});
return true;
}
});

return a;
}, {});

const compatibilityTests = flattenDeep([
es6Data,
es6PlusData,
es6,
es2016plus,
].map((data) =>
data.tests.map((test) => {
return test.subtests ?
Expand Down Expand Up @@ -125,24 +167,14 @@ const getLowestImplementedVersion = ({ features }, env) => {
return "-1";
}

// `equals` in compat-table
Object.keys(test).forEach((t) => {
const invertedEnvs = invertedEqualsEnv[envMap[t] || t];
if (invertedEnvs) {
invertedEnvs.forEach((inv) => {
test[inv] = test[t];
});
}
});

return Object.keys(test)
.filter((t) => t.startsWith(env))
// Babel assumes strict mode
.filter((test) => tests[i].res[test] === true || tests[i].res[test] === "strict")
// normalize some keys
.map((test) => envMap[test] || test)
.filter((test) => !isNaN(parseFloat(test.replace(env, ""))))
.shift();
.filter((t) => t.startsWith(env))
// Babel assumes strict mode
.filter((test) => tests[i].res[test] === true || tests[i].res[test] === "strict")
Copy link
Member

Choose a reason for hiding this comment

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

We could merge 2 filters in 1 for perf, but it's just a nit and could be changed in separate PR aimed to optimize things like this.

// normalize some keys
.map((test) => envMap[test] || test)
.filter((test) => !isNaN(parseFloat(test.replace(env, ""))))
.shift();
});

const envFiltered = envTests.filter((t) => t);
Expand Down Expand Up @@ -172,6 +204,7 @@ const generateData = (environments, features) => {
}

const plugin = {};

environments.forEach((env) => {
const version = getLowestImplementedVersion(options, env);
if (version !== null) {
Expand Down
15 changes: 3 additions & 12 deletions test/debug-fixtures/specific-targets/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Modules transform: commonjs

Using plugins:
transform-es2015-arrow-functions {"ie":10,"ios":9,"safari":7}
transform-es2015-block-scoped-functions {"edge":13,"ie":10,"ios":9,"safari":7}
transform-es2015-block-scoped-functions {"ie":10,"ios":9,"safari":7}
transform-es2015-block-scoping {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
transform-es2015-classes {"ie":10,"ios":9,"safari":7}
transform-es2015-computed-properties {"ie":10,"safari":7}
Expand All @@ -38,16 +38,7 @@ Using plugins:
syntax-trailing-function-commas {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}

Using polyfills:
es6.typed.data-view {"edge":13}
es6.typed.int8-array {"edge":13}
es6.typed.uint8-array {"edge":13}
es6.typed.uint8-clamped-array {"ie":10}
es6.typed.int16-array {"edge":13}
es6.typed.uint16-array {"edge":13}
es6.typed.int32-array {"edge":13}
es6.typed.uint32-array {"edge":13}
es6.typed.float32-array {"edge":13}
es6.typed.float64-array {"edge":13}
es6.map {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
es6.set {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
es6.weak-map {"edge":13,"firefox":49,"ie":10,"safari":7}
Expand All @@ -69,7 +60,7 @@ Using polyfills:
es6.symbol {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
es6.object.assign {"ie":10,"safari":7}
es6.object.is {"ie":10,"safari":7}
es6.object.set-prototype-of {"edge":13,"ie":10,"safari":7}
es6.object.set-prototype-of {"ie":10,"safari":7}
es6.function.name {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
es6.string.raw {"ie":10,"safari":7}
es6.string.from-code-point {"ie":10,"safari":7}
Expand Down Expand Up @@ -123,4 +114,4 @@ Using polyfills:
web.timers {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
web.immediate {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
web.dom.iterable {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7}
src/in.js -> lib/in.js
src/in.js -> lib/in.js