Skip to content

Commit

Permalink
adds simple support checker
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisC committed Dec 20, 2023
1 parent 742fc84 commit a506eed
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 26 deletions.
78 changes: 78 additions & 0 deletions scripts/update-bcd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,84 @@ describe("BCD updater", () => {
);
});

it.only("detects updates across multiple default statements", () => {
assert.isFalse(
hasSupportUpdates(
new Map([
["10", true],
["29", false],
["30", true],
]),
[
{
version_added: "30",
},
{
version_removed: "20",
version_added: "≤10",
},
],
),
);

assert.isFalse(
hasSupportUpdates(
new Map([
["19", true],
["29", false],
["30", true],
]),
[
{
version_added: "30",
},
{
version_removed: "20",
version_added: "≤10",
},
],
),
);

assert.isTrue(
hasSupportUpdates(
new Map([
["9", true],
["29", false],
["30", true],
]),
[
{
version_added: "30",
},
{
version_removed: "20",
version_added: "≤10",
},
],
),
);

assert.isTrue(
hasSupportUpdates(
new Map([
["10", true],
["29", true],
["30", true],
]),
[
{
version_added: "30",
},
{
version_removed: "20",
version_added: "≤10",
},
],
),
);
});

it("detects updates for preview statements", () => {
assert.isTrue(
hasSupportUpdates(new Map([["81", true]]), {
Expand Down
50 changes: 24 additions & 26 deletions scripts/update-bcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,31 @@ const skipCurrentBeforeSupport = skip("currentBeforeSupport", ({
}
});

const isSupported = (version: string, statements: SimpleSupportStatement[]) => {
for (const {version_added, version_removed} of statements) {
if (
version_added &&
typeof version_added === "string" &&
compareVersions(version, version_added.replace("≤", ""), ">=")
) {
if (
version_removed &&
typeof version_removed === "string" &&
compareVersions(version, version_removed.replace("≤", ""), ">=")
) {
continue;
}
return true;
}
}
return false;
};

export const hasSupportUpdates = (
versionMap: BrowserSupportMap,
simpleStatement?: SimpleSupportStatement,
defaultStatements: SimpleSupportStatement[],
) => {
if (!simpleStatement || simpleStatement.version_added === null) {
if (!defaultStatements.length) {
return true;
}

Expand All @@ -827,30 +847,8 @@ export const hasSupportUpdates = (
if (hasSupport === null) {
continue;
}

if (typeof simpleStatement.version_added === "boolean") {
if (!simpleStatement.version_added && !hasSupport) {
continue;
} else {
updates.push(version);
}
}

if (typeof simpleStatement.version_added === "string") {
if (simpleStatement.version_added === "preview") {
if (hasSupport) {
updates.push(version);
}
continue;
}

const simpleAdded = simpleStatement.version_added.replace("≤", "");
if (compareVersions(version, simpleAdded, "<") && hasSupport) {
updates.push(version);
}
if (compareVersions(version, simpleAdded, ">=") && !hasSupport) {
updates.push(version);
}
if (hasSupport !== isSupported(version, defaultStatements)) {
updates.push(version);
}
}
return updates.length > 0;
Expand Down

0 comments on commit a506eed

Please sign in to comment.