Skip to content

Commit 729924a

Browse files
fix(web): keep pasted decorators as text (#8415)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 0d23829 commit 729924a

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎packages/shared/src/composerInlineTokens.test.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,30 @@ describe("collectComposerInlineTokens", () => {
125125
expect(collectComposerInlineTokens("入力 @expo/ui を追加")).toEqual([]);
126126
});
127127

128-
it("keeps bare non-scoped file paths as mentions", () => {
129-
expect(collectComposerInlineTokens("Inspect @README.md next")).toEqual([
128+
it.each(["@namespace.foo(bar)", "@écrire(option)", "@e\u0301crire(option)"])(
129+
"keeps decorator call %s as plain text",
130+
(reference) => {
131+
expect(collectComposerInlineTokens(`${reference}\nclass Example {}`)).toEqual([]);
132+
},
133+
);
134+
135+
it.each(['@"foo(bar)"', "[foo(bar)](foo%28bar%29)"])(
136+
"keeps an explicit decorator-shaped file reference as a mention: %s",
137+
(reference) => {
138+
expect(collectComposerInlineTokens(`${reference} `)).toEqual([
139+
{
140+
type: "mention",
141+
value: "foo(bar)",
142+
source: reference,
143+
start: 0,
144+
end: reference.length,
145+
},
146+
]);
147+
},
148+
);
149+
150+
it("keeps bare file mentions before whitespace-separated parentheses", () => {
151+
expect(collectComposerInlineTokens("Inspect @README.md (notes)")).toEqual([
130152
{
131153
type: "mention",
132154
value: "README.md",

‎packages/shared/src/composerInlineTokens.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const URI_SCHEME_REGEX = /^[A-Za-z][A-Za-z0-9+.-]*:/;
4040
const WINDOWS_DRIVE_PATH_REGEX = /^[A-Za-z]:[\\/]/;
4141
const SCOPED_PACKAGE_REFERENCE_REGEX =
4242
/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*(?:\/[^\s@"]+)*$/;
43+
const DECORATOR_CALL_REFERENCE_REGEX = /^[\p{ID_Start}_$][\p{ID_Continue}.$\u200c\u200d]*\(/u;
4344

4445
function collectMentionTokens(text: string): ComposerInlineToken[] {
4546
const matches: ComposerInlineToken[] = [];
@@ -75,7 +76,11 @@ function collectMentionTokens(text: string): ComposerInlineToken[] {
7576
const prefix = match[1] ?? "";
7677
const quotedPath = match[2];
7778
const path = quotedPath !== undefined ? quotedPath.replace(/\\(.)/g, "$1") : (match[3] ?? "");
78-
if (!path || (quotedPath === undefined && SCOPED_PACKAGE_REFERENCE_REGEX.test(path))) {
79+
if (
80+
!path ||
81+
(quotedPath === undefined &&
82+
(SCOPED_PACKAGE_REFERENCE_REGEX.test(path) || DECORATOR_CALL_REFERENCE_REGEX.test(path)))
83+
) {
7984
continue;
8085
}
8186
const start = (match.index ?? 0) + prefix.length;

0 commit comments

Comments
 (0)