Skip to content

Commit a6e88f8

Browse files
authored
Ensure that BCD keys are only used once (#1174)
This prevents a problem like in #1164 from happening before we have a way to handle it.
1 parent 5dc4b4a commit a6e88f8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ function convertMarkdown(markdown: string) {
110110
return { text, html };
111111
}
112112

113+
// Map from BCD keys/paths to web-features identifiers.
114+
const bcdToFeatureId: Map<string, string> = new Map();
115+
113116
const features: { [key: string]: FeatureData } = {};
114117
for (const [key, data] of yamlEntries('features')) {
115118
// Draft features reserve an identifier but aren't complete yet. Skip them.
@@ -155,6 +158,19 @@ for (const [key, data] of yamlEntries('features')) {
155158
}
156159
}
157160

161+
// Check that no BCD key is used twice until the meaning is made clear in
162+
// https://github.com/web-platform-dx/web-features/issues/1173.
163+
if (data.compat_features) {
164+
for (const bcdKey of data.compat_features) {
165+
const otherKey = bcdToFeatureId.get(bcdKey);
166+
if (otherKey) {
167+
throw new Error(`BCD key ${bcdKey} is used in both ${otherKey} and ${key}, which creates ambiguity for some consumers. Please see https://github.com/web-platform-dx/web-features/issues/1173 and help us find a good solution to allow this.`);
168+
} else {
169+
bcdToFeatureId.set(bcdKey, key);
170+
}
171+
}
172+
}
173+
158174
features[key] = scrub(data);
159175
}
160176

0 commit comments

Comments
 (0)