|
6 | 6 | SupportBlock, |
7 | 7 | } from "@mdn/browser-compat-data/types"; |
8 | 8 | import { camelToHyphenCase } from "./utils/css.js"; |
9 | | -import { filterMapRecord, isEmptyRecord } from "./utils/record.js"; |
10 | | -import { mapDefined } from "./helpers.js"; |
11 | 9 | import { forceKeepAlive } from "./bcd/keep-alive.js"; |
| 10 | +import { mapToBcdCompat } from "./bcd/mapper.js"; |
12 | 11 |
|
13 | 12 | function hasMultipleImplementations(support: SupportBlock, prefix?: string) { |
14 | 13 | function hasStableImplementation( |
@@ -126,73 +125,6 @@ export function getRemovalData(webidl: Browser.WebIdl): Browser.WebIdl { |
126 | 125 | }) as Browser.WebIdl; |
127 | 126 | } |
128 | 127 |
|
129 | | -interface DataToMap { |
130 | | - key: string; |
131 | | - compat?: CompatStatement; |
132 | | - webkit?: boolean; |
133 | | - mixin: boolean; |
134 | | - parentKey?: string; |
135 | | -} |
136 | | - |
137 | | -function mapToBcdCompat( |
138 | | - webidl: Browser.WebIdl, |
139 | | - mapper: (data: DataToMap) => any |
140 | | -): Browser.WebIdl | undefined { |
141 | | - function mapInterfaceLike(name: string, i: Browser.Interface) { |
142 | | - const intCompat = bcd.api[name]?.__compat; |
143 | | - const mapped = mapper({ key: name, compat: intCompat, mixin: !!i.mixin }); |
144 | | - if (!intCompat) { |
145 | | - if (mapped) { |
146 | | - return { name: i.name, ...mapped }; |
147 | | - } |
148 | | - return; |
149 | | - } |
150 | | - const result = { ...mapped }; |
151 | | - |
152 | | - const recordMapper = (key: string) => { |
153 | | - const compat = bcd.api[name][key]?.__compat; |
154 | | - return mapper({ |
155 | | - key, |
156 | | - parentKey: name, |
157 | | - webkit: key.startsWith("webkit"), |
158 | | - compat, |
159 | | - mixin: !!i.mixin, |
160 | | - }); |
161 | | - }; |
162 | | - const methods = filterMapRecord(i.methods?.method, recordMapper); |
163 | | - const properties = filterMapRecord(i.properties?.property, recordMapper); |
164 | | - if (!isEmptyRecord(methods)) { |
165 | | - result.methods = { method: methods! }; |
166 | | - } |
167 | | - if (!isEmptyRecord(properties)) { |
168 | | - result.properties = { property: properties! }; |
169 | | - } |
170 | | - if (!isEmptyRecord(result)) { |
171 | | - return { name: i.name, ...result }; |
172 | | - } |
173 | | - } |
174 | | - |
175 | | - const interfaces = filterMapRecord( |
176 | | - webidl.interfaces?.interface, |
177 | | - mapInterfaceLike |
178 | | - ); |
179 | | - const mixins = filterMapRecord(webidl.mixins?.mixin, mapInterfaceLike); |
180 | | - const namespaces = mapDefined(webidl.namespaces, (n) => |
181 | | - mapInterfaceLike(n.name, n) |
182 | | - ); |
183 | | - if ( |
184 | | - !isEmptyRecord(interfaces) || |
185 | | - !isEmptyRecord(mixins) || |
186 | | - !isEmptyRecord(namespaces) |
187 | | - ) { |
188 | | - return { |
189 | | - interfaces: interfaces && { interface: interfaces }, |
190 | | - mixins: mixins && { mixin: mixins }, |
191 | | - namespaces, |
192 | | - }; |
193 | | - } |
194 | | -} |
195 | | - |
196 | 128 | export function getDeprecationData(webidl: Browser.WebIdl): Browser.WebIdl { |
197 | 129 | const webkitExceptions = ["webkitLineClamp"]; |
198 | 130 | return mapToBcdCompat(webidl, ({ key, compat, webkit }) => { |
|
0 commit comments