Skip to content

Commit

Permalink
Require whitespace after a tag name
Browse files Browse the repository at this point in the history
As discussed in #1990
  • Loading branch information
Gerrit0 committed Jul 9, 2022
1 parent c6e9bf9 commit 7ceda7b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Bug Fixes

- 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.
- The private member visibility option will now be respected in generated sites, #1992.
- Overload rendering will no longer be broken if JavaScript is disabled, #453.
- All overloads are now shown at once rather than requiring clicks to see the documentation for each signature, #1100.
Expand Down
5 changes: 4 additions & 1 deletion src/lib/converter/comments/blockLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ function* lexBlockComment2(
}
}

if (lookahead !== pos + 1) {
if (
lookahead !== pos + 1 &&
(lookahead === end || /\s/.test(file[lookahead]))
) {
braceStartsType = true;
yield makeToken(TokenSyntaxKind.Tag, lookahead - pos);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/converter/comments/lineLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ function* lexLineComments2(
}
}

if (lookahead !== pos + 1) {
if (
lookahead !== pos + 1 &&
(lookahead === end || /\s/.test(file[lookahead]))
) {
braceStartsType = true;
yield makeToken(TokenSyntaxKind.Tag, lookahead - pos);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/converter/comments/rawLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ function* lexCommentString2(
}
}

if (lookahead !== pos + 1) {
if (
lookahead !== pos + 1 &&
(lookahead === end || /\s/.test(file[lookahead]))
) {
braceStartsType = true;
yield makeToken(TokenSyntaxKind.Tag, lookahead - pos);
break;
Expand Down
33 changes: 33 additions & 0 deletions src/test/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ describe("Block Comment Lexer", () => {
]);
});

it("Should not mistake a scoped package for a tag", () => {
const tokens = lex("/* @typescript-eslint/parser @jest/globals */");
equal(tokens, [
{
kind: TokenSyntaxKind.Text,
text: "@typescript-eslint/parser @jest/globals",
pos: 3,
},
]);
});

it("Should allow escaping @ in an email", () => {
const tokens = lex("/* test\\@example.com */");
equal(tokens, [
Expand Down Expand Up @@ -651,6 +662,17 @@ describe("Line Comment Lexer", () => {
]);
});

it("Should not mistake a scoped package for a tag", () => {
const tokens = lex("// @typescript-eslint/parser @jest/globals");
equal(tokens, [
{
kind: TokenSyntaxKind.Text,
text: "@typescript-eslint/parser @jest/globals",
pos: 3,
},
]);
});

it("Should allow escaping @ in an email", () => {
const tokens = lex("// test\\@example.com");
equal(tokens, [
Expand Down Expand Up @@ -949,6 +971,17 @@ describe("Raw Lexer", () => {
]);
});

it("Should not mistake a scoped package for a tag", () => {
const tokens = lex("@typescript-eslint/parser @jest/globals");
equal(tokens, [
{
kind: TokenSyntaxKind.Text,
text: "@typescript-eslint/parser @jest/globals",
pos: 0,
},
]);
});

it("Should allow escaping @ in an email", () => {
const tokens = lex("test\\@example.com");
equal(tokens, [
Expand Down

0 comments on commit 7ceda7b

Please sign in to comment.