From 9a0acc65d16580c18d4fec5d9de81a1b5564bd7b Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Mon, 1 Jul 2024 15:59:24 +0200 Subject: [PATCH 1/4] Add `feature.spec_url` convenience --- .../src/browser-compat-data/feature.test.ts | 15 +++++++++++++++ .../src/browser-compat-data/feature.ts | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/compute-baseline/src/browser-compat-data/feature.test.ts b/packages/compute-baseline/src/browser-compat-data/feature.test.ts index 3f1a470e071..599a81c00e3 100644 --- a/packages/compute-baseline/src/browser-compat-data/feature.test.ts +++ b/packages/compute-baseline/src/browser-compat-data/feature.test.ts @@ -26,6 +26,21 @@ describe("features", function () { }); }); + describe("spec_url", function () { + it("returns an empty array if there's no spec_url", function () { + const noSpec = feature("javascript.builtins.Date.parse.iso_8601"); + assert(noSpec.spec_url.length === 0); + }); + + it("returns an array regardless of the number of spec_urls", function () { + const oneSpec = feature("css.properties.grid").spec_url; + assert.equal(oneSpec.length, 1); + + const twoSpecs = feature("css.properties.width").spec_url; + assert.equal(twoSpecs.length, 2); + }); + }); + describe("tags", function () { it("returns an array for features with tags", function () { const f = feature("css.types.length.cap"); diff --git a/packages/compute-baseline/src/browser-compat-data/feature.ts b/packages/compute-baseline/src/browser-compat-data/feature.ts index b88039c6c6b..b3bc46a4ee2 100644 --- a/packages/compute-baseline/src/browser-compat-data/feature.ts +++ b/packages/compute-baseline/src/browser-compat-data/feature.ts @@ -56,6 +56,18 @@ export class Feature { return this.data.__compat?.mdn_url; } + /** + * The feature's specification URLs as an array (whether there are any URLs or + * not). + */ + get spec_url(): string[] { + const underlying = this.data.__compat?.spec_url; + if (underlying) { + return Array.isArray(underlying) ? underlying : [underlying]; + } + return []; + } + _supportedBy( browser: Browser, ): { release: Release; qualifications?: Qualifications }[] { From a382e75a56c1163cf844f74f2fc80e36ae8d3b71 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Mon, 1 Jul 2024 16:00:20 +0200 Subject: [PATCH 2/4] Use `feature.spec_url` convenience --- scripts/update-drafts.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/update-drafts.ts b/scripts/update-drafts.ts index e802d8cc2e2..d7e00de4efd 100644 --- a/scripts/update-drafts.ts +++ b/scripts/update-drafts.ts @@ -61,13 +61,7 @@ async function main() { continue; } - const spec_url = feature.data.__compat.spec_url; - if (!spec_url) { - continue; - } - - const urls = Array.isArray(spec_url) ? spec_url : [spec_url]; - for (const url of urls) { + for (const url of feature.spec_url) { const spec = pageToSpec.get(normalize(url)); if (!spec) { console.warn(`${url} not matched to any spec`); From 95cf696e4a2c841d2241ca2d7f2c63be0ab02260 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Mon, 1 Jul 2024 16:08:29 +0200 Subject: [PATCH 3/4] Add `feature.standard_track` convenience --- .../src/browser-compat-data/feature.test.ts | 13 +++++++++++++ .../src/browser-compat-data/feature.ts | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/packages/compute-baseline/src/browser-compat-data/feature.test.ts b/packages/compute-baseline/src/browser-compat-data/feature.test.ts index 599a81c00e3..60362d1aced 100644 --- a/packages/compute-baseline/src/browser-compat-data/feature.test.ts +++ b/packages/compute-baseline/src/browser-compat-data/feature.test.ts @@ -26,6 +26,19 @@ describe("features", function () { }); }); + describe("standard_track", function () { + it("returns true only when true", function () { + const noStatus = feature("webextensions.manifest.storage"); + assert.equal(noStatus.standard_track, false); + + const nonStandard = feature("css.properties.-webkit-text-zoom"); + assert.equal(nonStandard.standard_track, false); + + const standard = feature("html.elements.table"); + assert.equal(standard.standard_track, true); + }); + }); + describe("spec_url", function () { it("returns an empty array if there's no spec_url", function () { const noSpec = feature("javascript.builtins.Date.parse.iso_8601"); diff --git a/packages/compute-baseline/src/browser-compat-data/feature.ts b/packages/compute-baseline/src/browser-compat-data/feature.ts index b3bc46a4ee2..ea469fe14ff 100644 --- a/packages/compute-baseline/src/browser-compat-data/feature.ts +++ b/packages/compute-baseline/src/browser-compat-data/feature.ts @@ -68,6 +68,10 @@ export class Feature { return []; } + get standard_track(): boolean { + return this.data.__compat?.status?.standard_track ?? false; + } + _supportedBy( browser: Browser, ): { release: Release; qualifications?: Qualifications }[] { From b705f89981f9ee6462d5dd8442a4e7d099c3efc2 Mon Sep 17 00:00:00 2001 From: "Daniel D. Beck" Date: Mon, 1 Jul 2024 16:08:47 +0200 Subject: [PATCH 4/4] Use `feature.standard_track` convenience --- scripts/update-drafts.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/update-drafts.ts b/scripts/update-drafts.ts index d7e00de4efd..7415a2620aa 100644 --- a/scripts/update-drafts.ts +++ b/scripts/update-drafts.ts @@ -1,8 +1,8 @@ import { Compat } from "compute-baseline/browser-compat-data"; import fs from "node:fs/promises"; import { fileURLToPath } from "node:url"; -import YAML from "yaml"; import webSpecs from 'web-specs' assert { type: 'json' }; +import YAML from "yaml"; import features from '../index.js'; function* getPages(spec): Generator { @@ -56,8 +56,7 @@ async function main() { } // Skip deprecated and non-standard features. - const status = feature.data.__compat.status; - if (status?.deprecated || !status?.standard_track) { + if (feature.deprecated || !feature.standard_track) { continue; }