Fix Component Browser aliases (#9163)

- Fix #9107
- Allow matching initials of aliases
- Allow matching spaces instead of underscores (aliases use spaces, not underscores)
- Fix only the first alias being detected. This is due to incorrect docs parsing keeping the leading space - `foo, bar` turns into `["foo", " bar"]`

# Important Notes
None
This commit is contained in:
somebody1234 2024-02-29 01:33:22 +10:00 committed by GitHub
parent c69ba4ee70
commit fecdd534b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -59,7 +59,9 @@ class FilteringWithPattern {
// - The unmatched rest of the word, up to, but excluding, the next underscore
// - The unmatched words before the next matched word, including any underscores
this.wordMatchRegex = new RegExp(
'(^|.*?_)(' + escapeStringRegexp(pattern).replace(/_/g, ')([^_]*)(.*?)(_') + ')([^_]*)(.*)',
'(^|.*?_)(' +
escapeStringRegexp(pattern).replace(/_/g, ')([^_]*)(.*?)([_ ]') +
')([^_]*)(.*)',
'i',
)
if (pattern.length > 1 && !/_/.test(pattern)) {
@ -72,7 +74,7 @@ class FilteringWithPattern {
const regex = pattern
.split('')
.map((c) => `(${c})`)
.join('([^_]*?_)')
.join('([^_]*?[_ ])')
this.initialsMatchRegex = new RegExp('(^|.*?_)' + regex + '(.*)', 'i')
}
}

View File

@ -57,7 +57,10 @@ export function documentationData(
documentation: parsed,
...(iconName != null ? { iconName } : {}),
...(groupIndex != null ? { groupIndex } : {}),
aliases: tagValue(parsed, 'Alias')?.split(',') ?? [],
aliases:
tagValue(parsed, 'Alias')
?.trim()
.split(/\s*,\s*/g) ?? [],
isPrivate: isSome(tagValue(parsed, 'Private')),
isUnstable: isSome(tagValue(parsed, 'Unstable')) || isSome(tagValue(parsed, 'Advanced')),
}