Skip to content

Commit 7ceda7b

Browse files
committed
Require whitespace after a tag name
As discussed in #1990
1 parent c6e9bf9 commit 7ceda7b

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Bug Fixes
44

5+
- Tags must now contain whitespace after the tag name to be parsed as a tag, `@jest/globals` in a comment will no longer be parsed as a tag #1990.
56
- The private member visibility option will now be respected in generated sites, #1992.
67
- Overload rendering will no longer be broken if JavaScript is disabled, #453.
78
- All overloads are now shown at once rather than requiring clicks to see the documentation for each signature, #1100.

src/lib/converter/comments/blockLexer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ function* lexBlockComment2(
201201
}
202202
}
203203

204-
if (lookahead !== pos + 1) {
204+
if (
205+
lookahead !== pos + 1 &&
206+
(lookahead === end || /\s/.test(file[lookahead]))
207+
) {
205208
braceStartsType = true;
206209
yield makeToken(TokenSyntaxKind.Tag, lookahead - pos);
207210
break;

src/lib/converter/comments/lineLexer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ function* lexLineComments2(
167167
}
168168
}
169169

170-
if (lookahead !== pos + 1) {
170+
if (
171+
lookahead !== pos + 1 &&
172+
(lookahead === end || /\s/.test(file[lookahead]))
173+
) {
171174
braceStartsType = true;
172175
yield makeToken(TokenSyntaxKind.Tag, lookahead - pos);
173176
break;

src/lib/converter/comments/rawLexer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ function* lexCommentString2(
165165
}
166166
}
167167

168-
if (lookahead !== pos + 1) {
168+
if (
169+
lookahead !== pos + 1 &&
170+
(lookahead === end || /\s/.test(file[lookahead]))
171+
) {
169172
braceStartsType = true;
170173
yield makeToken(TokenSyntaxKind.Tag, lookahead - pos);
171174
break;

src/test/comments.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ describe("Block Comment Lexer", () => {
253253
]);
254254
});
255255

256+
it("Should not mistake a scoped package for a tag", () => {
257+
const tokens = lex("/* @typescript-eslint/parser @jest/globals */");
258+
equal(tokens, [
259+
{
260+
kind: TokenSyntaxKind.Text,
261+
text: "@typescript-eslint/parser @jest/globals",
262+
pos: 3,
263+
},
264+
]);
265+
});
266+
256267
it("Should allow escaping @ in an email", () => {
257268
const tokens = lex("/* test\\@example.com */");
258269
equal(tokens, [
@@ -651,6 +662,17 @@ describe("Line Comment Lexer", () => {
651662
]);
652663
});
653664

665+
it("Should not mistake a scoped package for a tag", () => {
666+
const tokens = lex("// @typescript-eslint/parser @jest/globals");
667+
equal(tokens, [
668+
{
669+
kind: TokenSyntaxKind.Text,
670+
text: "@typescript-eslint/parser @jest/globals",
671+
pos: 3,
672+
},
673+
]);
674+
});
675+
654676
it("Should allow escaping @ in an email", () => {
655677
const tokens = lex("// test\\@example.com");
656678
equal(tokens, [
@@ -949,6 +971,17 @@ describe("Raw Lexer", () => {
949971
]);
950972
});
951973

974+
it("Should not mistake a scoped package for a tag", () => {
975+
const tokens = lex("@typescript-eslint/parser @jest/globals");
976+
equal(tokens, [
977+
{
978+
kind: TokenSyntaxKind.Text,
979+
text: "@typescript-eslint/parser @jest/globals",
980+
pos: 0,
981+
},
982+
]);
983+
});
984+
952985
it("Should allow escaping @ in an email", () => {
953986
const tokens = lex("test\\@example.com");
954987
equal(tokens, [

0 commit comments

Comments
 (0)