From 515e8b7636945f5956e17ed4945f0ce1163877a1 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 6 May 2023 09:33:16 -0600 Subject: [PATCH] Fix inline tag parsing Ref: #2273 --- CHANGELOG.md | 1 + src/lib/converter/comments/blockLexer.ts | 2 +- src/lib/converter/comments/lineLexer.ts | 2 +- src/lib/converter/comments/rawLexer.ts | 2 +- src/test/comments.test.ts | 30 ++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec42a8c00..002f545fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/lib/converter/comments/blockLexer.ts b/src/lib/converter/comments/blockLexer.ts index 977487a03..1cd2021df 100644 --- a/src/lib/converter/comments/blockLexer.ts +++ b/src/lib/converter/comments/blockLexer.ts @@ -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( diff --git a/src/lib/converter/comments/lineLexer.ts b/src/lib/converter/comments/lineLexer.ts index 0cd20f46d..1f7c0d7b6 100644 --- a/src/lib/converter/comments/lineLexer.ts +++ b/src/lib/converter/comments/lineLexer.ts @@ -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); diff --git a/src/lib/converter/comments/rawLexer.ts b/src/lib/converter/comments/rawLexer.ts index 81a5d866f..cffec39cd 100644 --- a/src/lib/converter/comments/rawLexer.ts +++ b/src/lib/converter/comments/rawLexer.ts @@ -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); diff --git a/src/test/comments.test.ts b/src/test/comments.test.ts index 6f4bda23e..d61102ced 100644 --- a/src/test/comments.test.ts +++ b/src/test/comments.test.ts @@ -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", () => { @@ -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", () => { @@ -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", () => {