Skip to content
Merged
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
26 changes: 24 additions & 2 deletions packages/shared/src/composerInlineTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,30 @@ describe("collectComposerInlineTokens", () => {
expect(collectComposerInlineTokens("入力 @expo/ui を追加")).toEqual([]);
});

it("keeps bare non-scoped file paths as mentions", () => {
expect(collectComposerInlineTokens("Inspect @README.md next")).toEqual([
it.each(["@namespace.foo(bar)", "@écrire(option)", "@e\u0301crire(option)"])(
"keeps decorator call %s as plain text",
(reference) => {
expect(collectComposerInlineTokens(`${reference}\nclass Example {}`)).toEqual([]);
},
);

it.each(['@"foo(bar)"', "[foo(bar)](foo%28bar%29)"])(
"keeps an explicit decorator-shaped file reference as a mention: %s",
(reference) => {
expect(collectComposerInlineTokens(`${reference} `)).toEqual([
{
type: "mention",
value: "foo(bar)",
source: reference,
start: 0,
end: reference.length,
},
]);
},
);

it("keeps bare file mentions before whitespace-separated parentheses", () => {
expect(collectComposerInlineTokens("Inspect @README.md (notes)")).toEqual([
{
type: "mention",
value: "README.md",
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/composerInlineTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const URI_SCHEME_REGEX = /^[A-Za-z][A-Za-z0-9+.-]*:/;
const WINDOWS_DRIVE_PATH_REGEX = /^[A-Za-z]:[\\/]/;
const SCOPED_PACKAGE_REFERENCE_REGEX =
/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*(?:\/[^\s@"]+)*$/;
const DECORATOR_CALL_REFERENCE_REGEX = /^[\p{ID_Start}_$][\p{ID_Continue}.$\u200c\u200d]*\(/u;

function collectMentionTokens(text: string): ComposerInlineToken[] {
const matches: ComposerInlineToken[] = [];
Expand Down Expand Up @@ -75,7 +76,11 @@ function collectMentionTokens(text: string): ComposerInlineToken[] {
const prefix = match[1] ?? "";
const quotedPath = match[2];
const path = quotedPath !== undefined ? quotedPath.replace(/\\(.)/g, "$1") : (match[3] ?? "");
if (!path || (quotedPath === undefined && SCOPED_PACKAGE_REFERENCE_REGEX.test(path))) {
if (
!path ||
(quotedPath === undefined &&
(SCOPED_PACKAGE_REFERENCE_REGEX.test(path) || DECORATOR_CALL_REFERENCE_REGEX.test(path)))
) {
continue;
}
const start = (match.index ?? 0) + prefix.length;
Expand Down
Loading