Skip to content

Commit

Permalink
update compat-table (note: regexp unicode 15.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Sep 15, 2023
1 parent ea9c644 commit 24bea0e
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 32 deletions.
8 changes: 4 additions & 4 deletions compat-table/package-lock.json

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

6 changes: 3 additions & 3 deletions compat-table/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"githubDependencies": {
"kangax/compat-table": "fe0a67bc1e7b237d5271219529aee695ddfe9e9c",
"williamkapke/node-compat-table": "9cacd46dbb63fc8ec5ebceb165cbfdd3ae8d03fa"
"kangax/compat-table": "d5e9c83b96b23f15318e6b2dc3f5bf51314aa340",
"williamkapke/node-compat-table": "e59188734a19f7595d29dd91643720bcbf0d0647"
},
"dependencies": {
"@mdn/browser-compat-data": "5.3.15",
"@mdn/browser-compat-data": "5.3.16",
"@types/caniuse-lite": "1.0.1",
"@types/node": "20.3.2",
"caniuse-lite": "1.0.30001534"
Expand Down
24 changes: 18 additions & 6 deletions compat-table/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const cssProperties = {
export interface Support {
force?: boolean
passed?: number
failed?: number
failed?: Set<string>
}

export interface VersionRange {
Expand All @@ -145,6 +145,7 @@ export interface PrefixData {

export type SupportMap<F extends string> = Record<F, Partial<Record<Engine, Record<string, Support>>>>
export type VersionRangeMap<F extends string> = Partial<Record<F, Partial<Record<Engine, VersionRange[]>>>>
export type WhyNotMap<F extends string> = Partial<Record<F, Partial<Record<Engine, string[]>>>>
export type CSSPrefixMap = Partial<Record<CSSProperty, PrefixData[]>>

const compareVersions = (a: number[], b: number[]): number => {
Expand Down Expand Up @@ -187,12 +188,14 @@ const mergePrefixMaps = (to: CSSPrefixMap, from: CSSPrefixMap): void => {
}
}

const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>): VersionRangeMap<F> => {
const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>): [VersionRangeMap<F>, WhyNotMap<F>] => {
const versionRangeMap: VersionRangeMap<F> = {}
const whyNotMap: WhyNotMap<F> = {}

for (const feature in supportMap) {
const engines = supportMap[feature as F]
const featureMap: Partial<Record<Engine, VersionRange[]>> = {}
const whyNotByEngine: Partial<Record<Engine, string[]>> = {}

// Compute the maximum number of tests that any one engine has passed
let maxPassed = 0
Expand All @@ -206,7 +209,7 @@ const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>):

for (const engine in engines) {
const versions = engines[engine as Engine]
const sortedVersions: { version: number[], supported: boolean }[] = []
const sortedVersions: { version: number[], supported: boolean, failed?: Set<string> }[] = []

for (const version in versions) {
const { force, passed, failed } = versions[version]
Expand All @@ -221,11 +224,17 @@ const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>):
// feature to be unsupported if not all tests were run, since it could
// be dangerous to assume otherwise.
!failed && passed === maxPassed,
failed,
})
}

sortedVersions.sort((a, b) => compareVersions(a.version, b.version))

if (sortedVersions.length) {
const last = sortedVersions[sortedVersions.length - 1]
if (last.failed) whyNotByEngine[engine as Engine] = [...last.failed].sort()
}

const versionRanges: VersionRange[] = []
let i = 0

Expand Down Expand Up @@ -270,9 +279,10 @@ const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>):
}

versionRangeMap[feature as F] = featureMap
whyNotMap[feature as F] = whyNotByEngine
}

return versionRangeMap
return [versionRangeMap, whyNotMap]
}

const updateGithubDependencies = (): void => {
Expand Down Expand Up @@ -469,7 +479,8 @@ import('./kangax').then(kangax => {
// MDN data is wrong here: https://www.chromestatus.com/feature/6482797915013120
js.ClassStaticBlocks.Chrome = { 91: { force: true } }

generateTableForJS(supportMapToVersionRanges(js))
const [jsVersionRanges, jsWhyNot] = supportMapToVersionRanges(js)
generateTableForJS(jsVersionRanges, jsWhyNot)
})

const css: SupportMap<CSSFeature> = {} as SupportMap<CSSFeature>
Expand All @@ -481,4 +492,5 @@ mergeSupportMaps(css, mdn.css)
mergePrefixMaps(cssPrefix, caniuse.cssPrefix)
mergePrefixMaps(cssPrefix, mdn.cssPrefix)

generateTableForCSS(supportMapToVersionRanges(css), cssPrefix)
const [cssVersionRanges] = supportMapToVersionRanges(css)
generateTableForCSS(cssVersionRanges, cssPrefix)
26 changes: 18 additions & 8 deletions compat-table/src/js_table.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file generates "internal/compat/js_table.go"

import fs = require('fs')
import { Engine, JSFeature, VersionRange, VersionRangeMap, engines } from './index'
import { Engine, JSFeature, VersionRange, VersionRangeMap, WhyNotMap, engines } from './index'

const jsFeatureString = (feature: string): string => {
return feature.replace(/([A-Z])/g, '-$1').slice(1).toLowerCase()
Expand All @@ -21,17 +21,27 @@ const compareEngines = (a: Engine, b: Engine): number => {
return lowerA < lowerB ? -1 : lowerA > lowerB ? 1 : 0
}

const jsTableMap = (map: Partial<Record<Engine, VersionRange[]>>) => {
const jsTableMap = (map: Partial<Record<Engine, VersionRange[]>>, whyNot: Partial<Record<Engine, string[]>>) => {
const lines: string[] = []
const whyNotKeys = (Object.keys(whyNot) as Engine[]).sort(compareEngines)
for (const engine of whyNotKeys) {
const failedTests = whyNot[engine]!
lines.push(`\t\t// Note: The latest version of ${JSON.stringify(engine)} failed ` + (failedTests.length === 1
? `this test: ${failedTests[0]}` : `${failedTests.length} tests including: ${failedTests[0]}`))
}

const engineKeys = (Object.keys(map) as Engine[]).sort(compareEngines)
const maxLength = engineKeys.reduce((a, b) => Math.max(a, b.length + 1), 0)
if (engineKeys.length === 0) return '{}'
return `{\n${engineKeys.map(engine => {
for (const engine of engineKeys) {
const items = map[engine]!.map(range => {
return `{start: v{${range.start.concat(0, 0).slice(0, 3).join(', ')
}}${range.end ? `, end: v{${range.end.concat(0, 0).slice(0, 3).join(', ')}}` : ''}}`
})
return `\t\t${(engine + ':').padEnd(maxLength)} {${items.join(', ')}},`
}).join('\n')}\n\t}`
lines.push(`\t\t${(engine + ':').padEnd(maxLength)} {${items.join(', ')}},`)
}

if (lines.length === 0) return '{}'
return `{\n${lines.join('\n')}\n\t}`
}

const jsTableValidEnginesMap = (engines: Engine[]) => {
Expand All @@ -44,7 +54,7 @@ const jsTableValidEnginesMap = (engines: Engine[]) => {

const generatedByComment = `// This file was automatically generated by "js_table.ts"`

export const generateTableForJS = (map: VersionRangeMap<JSFeature>): void => {
export const generateTableForJS = (map: VersionRangeMap<JSFeature>, whyNot: WhyNotMap<JSFeature>): void => {
const enginesKeys = (Object.keys(engines) as Engine[]).sort(compareEngines)

fs.writeFileSync(__dirname + '/../internal/compat/js_table.go',
Expand Down Expand Up @@ -92,7 +102,7 @@ func (features JSFeature) ApplyOverrides(overrides JSFeature, mask JSFeature) JS
}
var jsTable = map[JSFeature]map[Engine][]versionRange{
${Object.keys(map).sort().map(feature => `\t${feature}: ${jsTableMap(map[feature as JSFeature]!)},`).join('\n')}
${Object.keys(map).sort().map(feature => `\t${feature}: ${jsTableMap(map[feature as JSFeature]!, whyNot[feature as JSFeature]!)},`).join('\n')}
}
// Return all features that are not available in at least one environment
Expand Down
8 changes: 6 additions & 2 deletions compat-table/src/kangax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ const updateMap = (map: SupportMap<JSFeature>, feature: JSFeature, engine: Engin
const engines = map[feature] || (map[feature] = {})
const versions = engines[engine] || (engines[engine] = {})
const support = versions[version] || (versions[version] = {})
if (passed) support.passed = (support.passed || 0) + 1
else support.failed = (support.failed || 0) + 1
if (passed) {
support.passed = (support.passed || 0) + 1
} else {
support.failed ||= new Set
support.failed.add(testName)
}
}

const mergeIndividualTestResults = (map: SupportMap<JSFeature>, feature: JSFeature, testName: string, res: Record<string, boolean | { val: boolean }>, omit: Engine[]): void => {
Expand Down
Loading

0 comments on commit 24bea0e

Please sign in to comment.