Skip to content

Commit

Permalink
Fix inline tag parsing
Browse files Browse the repository at this point in the history
Ref: #2273
  • Loading branch information
Gerrit0 committed May 6, 2023
1 parent 26df2ac commit 515e8b7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug Fixes

- Category children are now sorted according to the `sort` option, #2272.
- Inline tags no longer require a space after the tag name to be parsed as a tag, #2273.

## v0.24.6 (2023-04-24)

Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/blockLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function* lexBlockComment2(

if (
lookahead !== pos + 1 &&
(lookahead === end || /\s/.test(file[lookahead]))
(lookahead === end || /[\s}]/.test(file[lookahead]))
) {
braceStartsType = true;
const token = makeToken(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/lineLexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function* lexLineComments2(

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

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

it("Should allow inline tags directly next to braces", () => {
const tokens = lex("/** {@inline} */");

equal(tokens, [
{ kind: TokenSyntaxKind.OpenBrace, text: "{", pos: 4 },
{ kind: TokenSyntaxKind.Tag, text: "@inline", pos: 5 },
{ kind: TokenSyntaxKind.CloseBrace, text: "}", pos: 12 },
]);
});
});

describe("Line Comment Lexer", () => {
Expand Down Expand Up @@ -881,6 +891,16 @@ describe("Line Comment Lexer", () => {
{ kind: TokenSyntaxKind.CloseBrace, text: "}", pos: 21 },
]);
});

it("Should allow inline tags directly next to braces", () => {
const tokens = lex("// {@inline}");

equal(tokens, [
{ kind: TokenSyntaxKind.OpenBrace, text: "{", pos: 3 },
{ kind: TokenSyntaxKind.Tag, text: "@inline", pos: 4 },
{ kind: TokenSyntaxKind.CloseBrace, text: "}", pos: 11 },
]);
});
});

describe("Raw Lexer", () => {
Expand Down Expand Up @@ -1197,6 +1217,16 @@ describe("Raw Lexer", () => {
{ kind: TokenSyntaxKind.CloseBrace, text: "}", pos: 18 },
]);
});

it("Should allow inline tags directly next to braces", () => {
const tokens = lex("{@inline}");

equal(tokens, [
{ kind: TokenSyntaxKind.OpenBrace, text: "{", pos: 0 },
{ kind: TokenSyntaxKind.Tag, text: "@inline", pos: 1 },
{ kind: TokenSyntaxKind.CloseBrace, text: "}", pos: 8 },
]);
});
});

describe("Comment Parser", () => {
Expand Down

0 comments on commit 515e8b7

Please sign in to comment.