-
Notifications
You must be signed in to change notification settings - Fork 199
compute-baseline: Add per-release support checks to Features
#1339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
77259eb
fef80be
17cd3fa
c79d74c
c07b62d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| import { Identifier } from "@mdn/browser-compat-data"; | ||
|
|
||
| import { Identifier, SimpleSupportStatement } from "@mdn/browser-compat-data"; | ||
| import { Browser } from "./browser.js"; | ||
| import { Compat, defaultCompat } from "./compat.js"; | ||
| import { Release } from "./release.js"; | ||
| import { | ||
| Qualifications, | ||
| RealSupportStatement, | ||
| statement, | ||
| Supported, | ||
| SupportStatement, | ||
| UnknownSupport, | ||
| Unsupported, | ||
| } from "./supportStatements.js"; | ||
| import { isFeatureData } from "./typeUtils.js"; | ||
|
|
||
|
|
@@ -72,33 +75,84 @@ export class Feature { | |
| return this.data.__compat?.status?.standard_track ?? false; | ||
| } | ||
|
|
||
| _supportedBy( | ||
| browser: Browser, | ||
| ): { release: Release; qualifications?: Qualifications }[] { | ||
| /** | ||
| * Get this feature's support statement data, for a given browser. | ||
| */ | ||
| rawSupportStatements(browser: Browser): SimpleSupportStatement[] { | ||
| const support = this.data?.__compat?.support; | ||
| if (support === undefined) { | ||
| throw Error("This feature contains no __compat object."); | ||
| throw new Error("This feature contains no __compat object."); | ||
| } | ||
|
|
||
| const statementOrStatements = support[browser.id]; | ||
|
|
||
| if (statementOrStatements === undefined) { | ||
| throw Error(`${this} contains no support data for ${browser.name}`); | ||
| throw new Error(`${this} contains no support data for ${browser.name}`); | ||
| } | ||
|
|
||
| const rawStatements = Array.isArray(statementOrStatements) | ||
| return Array.isArray(statementOrStatements) | ||
| ? statementOrStatements | ||
| : [statementOrStatements]; | ||
| } | ||
|
|
||
| /** | ||
| * Get this feature's `SupportStatement` or `RealSupportStatement` objects, | ||
| * for a given browser. | ||
| */ | ||
| supportStatements(browser: Browser): SupportStatement[] { | ||
| return this.rawSupportStatements(browser).map((raw) => | ||
| statement(raw, browser, this), | ||
| ); | ||
| } | ||
|
Comment on lines
+101
to
+105
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too happens in a few places, now consolidated. |
||
|
|
||
| /** | ||
| * Find out whether this feature's support data says that a given browser | ||
| * release is supported (with or without qualifications), unsupported, or | ||
| * unknown. | ||
| */ | ||
| supportedInDetails( | ||
| release: Release, | ||
| ): (Supported | Unsupported | UnknownSupport)[] { | ||
| const result = []; | ||
| for (const raw of rawStatements) { | ||
| const s = statement(raw, browser, this); | ||
| for (const s of this.supportStatements(release.browser)) { | ||
| this.assertRealSupportStatement(s, release.browser); | ||
|
|
||
| if (!(s instanceof RealSupportStatement)) { | ||
| throw Error( | ||
| `${this.id} contains non-real values for ${browser.name}. Cannot expand support.`, | ||
| ); | ||
|
Comment on lines
+117
to
-100
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also happens in a couple of places, so I consolidated that too—it's at the end. I have no idea how to order things. 😬
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order is hard. End is fine. |
||
| result.push(s.supportedInDetails(release)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Find out whether this feature's support data says that a given browser | ||
| * release is supported (`true`), unsupported (`false`), or unknown (`null`). | ||
| * Note that this ignores qualifications such as partial implementations, | ||
| * prefixes, alternative names, and flags. | ||
| */ | ||
| supportedIn(release: Release): boolean | null { | ||
| let unknown = false; | ||
| for (const s of this.supportStatements(release.browser)) { | ||
| this.assertRealSupportStatement(s, release.browser); | ||
|
|
||
| const supported = s.supportedInDetails(release); | ||
| if (supported.supported && !supported.qualifications) { | ||
| return true; | ||
| } | ||
|
|
||
| if (supported.supported === null) { | ||
| unknown = true; | ||
| } | ||
| } | ||
| if (unknown) { | ||
| return null; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| _supportedBy( | ||
| browser: Browser, | ||
| ): { release: Release; qualifications?: Qualifications }[] { | ||
| const result = []; | ||
| for (const s of this.supportStatements(browser)) { | ||
| this.assertRealSupportStatement(s, browser); | ||
|
|
||
| result.push(...s.supportedBy()); | ||
| } | ||
|
|
@@ -121,4 +175,17 @@ export class Feature { | |
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Throws when a support statement contains non-real values. | ||
| */ | ||
| assertRealSupportStatement( | ||
| statement: SupportStatement, | ||
| browser: Browser, | ||
| ): asserts statement is RealSupportStatement { | ||
| if (!(statement instanceof RealSupportStatement)) | ||
| throw new Error( | ||
| `${this.id} contains non-real values for ${browser.name}. Cannot expand support.`, | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens in a few places, so I consolidated it.