Skip to content

Commit 24bea0e

Browse files
committed
update compat-table (note: regexp unicode 15.1)
1 parent ea9c644 commit 24bea0e

6 files changed

Lines changed: 156 additions & 32 deletions

File tree

compat-table/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compat-table/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"githubDependencies": {
3-
"kangax/compat-table": "fe0a67bc1e7b237d5271219529aee695ddfe9e9c",
4-
"williamkapke/node-compat-table": "9cacd46dbb63fc8ec5ebceb165cbfdd3ae8d03fa"
3+
"kangax/compat-table": "d5e9c83b96b23f15318e6b2dc3f5bf51314aa340",
4+
"williamkapke/node-compat-table": "e59188734a19f7595d29dd91643720bcbf0d0647"
55
},
66
"dependencies": {
7-
"@mdn/browser-compat-data": "5.3.15",
7+
"@mdn/browser-compat-data": "5.3.16",
88
"@types/caniuse-lite": "1.0.1",
99
"@types/node": "20.3.2",
1010
"caniuse-lite": "1.0.30001534"

compat-table/src/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const cssProperties = {
129129
export interface Support {
130130
force?: boolean
131131
passed?: number
132-
failed?: number
132+
failed?: Set<string>
133133
}
134134

135135
export interface VersionRange {
@@ -145,6 +145,7 @@ export interface PrefixData {
145145

146146
export type SupportMap<F extends string> = Record<F, Partial<Record<Engine, Record<string, Support>>>>
147147
export type VersionRangeMap<F extends string> = Partial<Record<F, Partial<Record<Engine, VersionRange[]>>>>
148+
export type WhyNotMap<F extends string> = Partial<Record<F, Partial<Record<Engine, string[]>>>>
148149
export type CSSPrefixMap = Partial<Record<CSSProperty, PrefixData[]>>
149150

150151
const compareVersions = (a: number[], b: number[]): number => {
@@ -187,12 +188,14 @@ const mergePrefixMaps = (to: CSSPrefixMap, from: CSSPrefixMap): void => {
187188
}
188189
}
189190

190-
const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>): VersionRangeMap<F> => {
191+
const supportMapToVersionRanges = <F extends string>(supportMap: SupportMap<F>): [VersionRangeMap<F>, WhyNotMap<F>] => {
191192
const versionRangeMap: VersionRangeMap<F> = {}
193+
const whyNotMap: WhyNotMap<F> = {}
192194

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

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

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

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

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

233+
if (sortedVersions.length) {
234+
const last = sortedVersions[sortedVersions.length - 1]
235+
if (last.failed) whyNotByEngine[engine as Engine] = [...last.failed].sort()
236+
}
237+
229238
const versionRanges: VersionRange[] = []
230239
let i = 0
231240

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

272281
versionRangeMap[feature as F] = featureMap
282+
whyNotMap[feature as F] = whyNotByEngine
273283
}
274284

275-
return versionRangeMap
285+
return [versionRangeMap, whyNotMap]
276286
}
277287

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

472-
generateTableForJS(supportMapToVersionRanges(js))
482+
const [jsVersionRanges, jsWhyNot] = supportMapToVersionRanges(js)
483+
generateTableForJS(jsVersionRanges, jsWhyNot)
473484
})
474485

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

484-
generateTableForCSS(supportMapToVersionRanges(css), cssPrefix)
495+
const [cssVersionRanges] = supportMapToVersionRanges(css)
496+
generateTableForCSS(cssVersionRanges, cssPrefix)

compat-table/src/js_table.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file generates "internal/compat/js_table.go"
22

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

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

24-
const jsTableMap = (map: Partial<Record<Engine, VersionRange[]>>) => {
24+
const jsTableMap = (map: Partial<Record<Engine, VersionRange[]>>, whyNot: Partial<Record<Engine, string[]>>) => {
25+
const lines: string[] = []
26+
const whyNotKeys = (Object.keys(whyNot) as Engine[]).sort(compareEngines)
27+
for (const engine of whyNotKeys) {
28+
const failedTests = whyNot[engine]!
29+
lines.push(`\t\t// Note: The latest version of ${JSON.stringify(engine)} failed ` + (failedTests.length === 1
30+
? `this test: ${failedTests[0]}` : `${failedTests.length} tests including: ${failedTests[0]}`))
31+
}
32+
2533
const engineKeys = (Object.keys(map) as Engine[]).sort(compareEngines)
2634
const maxLength = engineKeys.reduce((a, b) => Math.max(a, b.length + 1), 0)
27-
if (engineKeys.length === 0) return '{}'
28-
return `{\n${engineKeys.map(engine => {
35+
for (const engine of engineKeys) {
2936
const items = map[engine]!.map(range => {
3037
return `{start: v{${range.start.concat(0, 0).slice(0, 3).join(', ')
3138
}}${range.end ? `, end: v{${range.end.concat(0, 0).slice(0, 3).join(', ')}}` : ''}}`
3239
})
33-
return `\t\t${(engine + ':').padEnd(maxLength)} {${items.join(', ')}},`
34-
}).join('\n')}\n\t}`
40+
lines.push(`\t\t${(engine + ':').padEnd(maxLength)} {${items.join(', ')}},`)
41+
}
42+
43+
if (lines.length === 0) return '{}'
44+
return `{\n${lines.join('\n')}\n\t}`
3545
}
3646

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

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

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

5060
fs.writeFileSync(__dirname + '/../internal/compat/js_table.go',
@@ -92,7 +102,7 @@ func (features JSFeature) ApplyOverrides(overrides JSFeature, mask JSFeature) JS
92102
}
93103
94104
var jsTable = map[JSFeature]map[Engine][]versionRange{
95-
${Object.keys(map).sort().map(feature => `\t${feature}: ${jsTableMap(map[feature as JSFeature]!)},`).join('\n')}
105+
${Object.keys(map).sort().map(feature => `\t${feature}: ${jsTableMap(map[feature as JSFeature]!, whyNot[feature as JSFeature]!)},`).join('\n')}
96106
}
97107
98108
// Return all features that are not available in at least one environment

compat-table/src/kangax.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ const updateMap = (map: SupportMap<JSFeature>, feature: JSFeature, engine: Engin
144144
const engines = map[feature] || (map[feature] = {})
145145
const versions = engines[engine] || (engines[engine] = {})
146146
const support = versions[version] || (versions[version] = {})
147-
if (passed) support.passed = (support.passed || 0) + 1
148-
else support.failed = (support.failed || 0) + 1
147+
if (passed) {
148+
support.passed = (support.passed || 0) + 1
149+
} else {
150+
support.failed ||= new Set
151+
support.failed.add(testName)
152+
}
149153
}
150154

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

0 commit comments

Comments
 (0)