1- import { CompatData , CompatStatement } from "@mdn/browser-compat-data/types" ;
1+ import {
2+ CompatStatement ,
3+ Identifier ,
4+ SimpleSupportStatement ,
5+ } from "bcd-idl-mapper" ;
6+ import api from "bcd-idl-mapper" ;
27import * as Browser from "../types" ;
38import { filterMapRecord , isEmptyRecord } from "../utils/record.js" ;
49import { mapDefined } from "../helpers.js" ;
5- import resolveMixinSupportData from "./resolve-mixin .js" ;
10+ import { hasStableImplementation } from "./stable .js" ;
611
712interface DataToMap {
813 key : string ;
@@ -12,15 +17,47 @@ interface DataToMap {
1217 parentKey ?: string ;
1318}
1419
20+ function mergeCompatStatements ( data ?: Identifier ) : CompatStatement | undefined {
21+ if ( ! data ) {
22+ return ;
23+ }
24+ if ( data ?. __compat ) {
25+ return data . __compat ;
26+ }
27+
28+ // Some items have no top level __compat and instead have contexts with compat data for each
29+
30+ const statements = Object . values ( data )
31+ . map ( ( d ) => d . __compat )
32+ . filter ( ( n ) => n ) as CompatStatement [ ] ;
33+
34+ const base = Object . fromEntries (
35+ Object . keys ( statements [ 0 ] . support ) . map ( ( key ) => {
36+ return [ key , [ ] as SimpleSupportStatement [ ] ] ;
37+ } )
38+ ) ;
39+
40+ for ( const statement of statements ) {
41+ for ( const key of Object . keys ( statement . support ) ) {
42+ const support = statement . support [ key ] ;
43+ if ( support && hasStableImplementation ( support ) ) {
44+ base [ key ] . push ( ...( Array . isArray ( support ) ? support : [ support ] ) ) ;
45+ }
46+ }
47+ }
48+
49+ return { ...statements [ 0 ] , support : base } ;
50+ }
51+
1552function mapInterfaceLike (
1653 name : string ,
1754 i : Browser . Interface ,
18- bcdResolved : CompatData ,
1955 mapper : ( data : DataToMap ) => any
2056) {
21- const intCompat = bcdResolved . api [ name ] ?. __compat ;
57+ const data = i . mixin ? api . __mixins [ name ] : api [ name ] ;
58+ const intCompat = data ?. __compat ;
2259 const mapped = mapper ( { key : name , compat : intCompat , mixin : ! ! i . mixin } ) ;
23- if ( ! intCompat ) {
60+ if ( ! data ) {
2461 if ( mapped ) {
2562 return { name : i . name , ...mapped } ;
2663 }
@@ -29,11 +66,10 @@ function mapInterfaceLike(
2966 const result = { ...mapped } ;
3067
3168 const recordMapper = ( key : string ) => {
32- const compat = bcdResolved . api [ name ] [ key ] ?. __compat ;
69+ const compat = mergeCompatStatements ( data [ key ] ) ;
3370 return mapper ( {
3471 key,
3572 parentKey : name ,
36- webkit : key . startsWith ( "webkit" ) ,
3773 compat,
3874 mixin : ! ! i . mixin ,
3975 } ) ;
@@ -55,14 +91,13 @@ export function mapToBcdCompat(
5591 webidl : Browser . WebIdl ,
5692 mapper : ( data : DataToMap ) => any
5793) : Browser . WebIdl | undefined {
58- const bcdResolved = resolveMixinSupportData ( webidl ) ;
5994 const map = ( name : string , i : Browser . Interface ) =>
60- mapInterfaceLike ( name , i , bcdResolved , mapper ) ;
95+ mapInterfaceLike ( name , i , mapper ) ;
6196
6297 const interfaces = filterMapRecord ( webidl . interfaces ?. interface , map ) ;
6398 const mixins = filterMapRecord ( webidl . mixins ?. mixin , map ) ;
6499 const namespaces = mapDefined ( webidl . namespaces , ( n ) =>
65- mapInterfaceLike ( n . name , n , bcdResolved , mapper )
100+ mapInterfaceLike ( n . name , n , mapper )
66101 ) ;
67102 if (
68103 ! isEmptyRecord ( interfaces ) ||
0 commit comments