Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/CSSFontFeatureValuesMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
},
"@@iterator": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/CSSFontFeatureValuesMap/Symbol.iterator",
"spec_url": "https://drafts.csswg.org/css-fonts/#cssfontfeaturevaluesmap",
"tags": [
"web-features:font-variant-alternates"
Expand Down
18 changes: 17 additions & 1 deletion utils/mdn-content-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ const slugs = (() => {
return result;
})();

/**
* Returns true if the slug tail and path tail are related enough to link.
* Strips leading `@@` from path tail to handle well-known symbol names
* (e.g. `@@dispose` matches `Symbol.dispose`).
* @param {string} slugTail Last segment of an MDN slug
* @param {string | undefined} pathTail Last segment of a BCD path
* @returns {boolean} Whether the tails are related
*/
export const tailsMatch = (slugTail, pathTail) => {
if (!pathTail) {
return false;
}
const normalized = pathTail.replace(/^@@/, '');
return slugTail.includes(normalized) || normalized.includes(slugTail);
};

/** @type {Map<string, string>} BCD path → MDN slug (only unambiguous mappings) */
const slugByPath = (() => {
/** @type {Map<string, string[]>} */
Expand All @@ -31,7 +47,7 @@ const slugByPath = (() => {
const slugTail = slug.split('/').at(-1);
const pathTail = path.split('.').at(-1);

if (!slugTail.includes(pathTail) && !pathTail?.includes(slugTail)) {
if (!tailsMatch(slugTail, pathTail)) {
// Ignore unrelated pages/features.
continue;
}
Expand Down
36 changes: 36 additions & 0 deletions utils/mdn-content-inventory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */

import assert from 'node:assert/strict';

import { tailsMatch } from './mdn-content-inventory.js';

describe('tailsMatch()', () => {
it('matches identical tails', () => {
assert.ok(tailsMatch('abort', 'abort'));
});

it('matches when slug tail contains path tail', () => {
assert.ok(tailsMatch('Symbol.dispose', 'dispose'));
});

it('matches when path tail contains slug tail', () => {
assert.ok(tailsMatch('bar', 'foobar'));
});

it('matches @@symbol path tail against Symbol.* slug tail', () => {
assert.ok(tailsMatch('Symbol.dispose', '@@dispose'));
assert.ok(tailsMatch('Symbol.iterator', '@@iterator'));
assert.ok(tailsMatch('Symbol.asyncIterator', '@@asyncIterator'));
assert.ok(tailsMatch('Symbol.toPrimitive', '@@toPrimitive'));
});

it('does not match unrelated tails', () => {
assert.ok(!tailsMatch('Symbol.dispose', 'foo'));
assert.ok(!tailsMatch('abort', 'fetch'));
});

it('does not match when path tail is undefined', () => {
assert.ok(!tailsMatch('abort', undefined));
});
});
Loading