Skip to content

Commit 9121d78

Browse files
Allow hyphenated JSDoc tags
JSDoc tags may contain hyphens. For example, `@TJS-type`, which is used by [`typescript-json-schema`](https://www.npmjs.com/package/typescript-json-schema).
1 parent e8b6df3 commit 9121d78

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

src/lib/converter/comments/blockLexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function* lexBlockComment2(
263263
if (lookahead !== pos + 1) {
264264
while (
265265
lookahead < end &&
266-
/[a-z0-9]/i.test(file[lookahead])
266+
/[a-z0-9-]/i.test(file[lookahead])
267267
) {
268268
lookahead++;
269269
}

src/lib/converter/comments/lineLexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function* lexLineComments2(
179179
if (lookahead !== pos + 1) {
180180
while (
181181
lookahead < end &&
182-
/[a-z0-9]/i.test(file[lookahead])
182+
/[a-z0-9-]/i.test(file[lookahead])
183183
) {
184184
lookahead++;
185185
}

src/lib/converter/comments/rawLexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function* lexCommentString2(
176176
if (lookahead !== pos + 1) {
177177
while (
178178
lookahead < end &&
179-
/[a-z0-9]/i.test(file[lookahead])
179+
/[a-z0-9-]/i.test(file[lookahead])
180180
) {
181181
lookahead++;
182182
}

src/lib/utils-common/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ export function optional<T extends Schema>(x: T): Optional<T> {
120120
}
121121

122122
export function isTagString(x: unknown): x is `@${string}` {
123-
return typeof x === "string" && /^@[a-zA-Z][a-zA-Z0-9]*$/.test(x);
123+
return typeof x === "string" && /^@[a-z][a-z0-9-]*$/i.test(x);
124124
}

src/test/comments.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ describe("Block Comment Lexer", () => {
186186
});
187187

188188
it("Should recognize tags", () => {
189-
const tokens = lex("/* @tag @a @abc234 */");
189+
const tokens = lex("/* @tag @a @abc234 @abc-234 */");
190190

191191
equal(tokens, [
192192
{ kind: TokenSyntaxKind.Tag, text: "@tag", pos: 3 },
193193
{ kind: TokenSyntaxKind.Text, text: " ", pos: 7 },
194194
{ kind: TokenSyntaxKind.Tag, text: "@a", pos: 8 },
195195
{ kind: TokenSyntaxKind.Text, text: " ", pos: 10 },
196196
{ kind: TokenSyntaxKind.Tag, text: "@abc234", pos: 11 },
197+
{ kind: TokenSyntaxKind.Text, text: " ", pos: 18 },
198+
{ kind: TokenSyntaxKind.Tag, text: "@abc-234", pos: 19 },
197199
]);
198200
});
199201

@@ -641,14 +643,16 @@ describe("Line Comment Lexer", () => {
641643
});
642644

643645
it("Should recognize tags", () => {
644-
const tokens = lex("// @tag @a @abc234");
646+
const tokens = lex("// @tag @a @abc234 @abc-234");
645647

646648
equal(tokens, [
647649
{ kind: TokenSyntaxKind.Tag, text: "@tag", pos: 3 },
648650
{ kind: TokenSyntaxKind.Text, text: " ", pos: 7 },
649651
{ kind: TokenSyntaxKind.Tag, text: "@a", pos: 8 },
650652
{ kind: TokenSyntaxKind.Text, text: " ", pos: 10 },
651653
{ kind: TokenSyntaxKind.Tag, text: "@abc234", pos: 11 },
654+
{ kind: TokenSyntaxKind.Text, text: " ", pos: 18 },
655+
{ kind: TokenSyntaxKind.Tag, text: "@abc-234", pos: 19 },
652656
]);
653657
});
654658

@@ -993,12 +997,12 @@ describe("Raw Lexer", () => {
993997
});
994998

995999
it("Should not recognize tags", () => {
996-
const tokens = lex("@123 @@ @ @tag @a @abc234");
1000+
const tokens = lex("@123 @@ @ @tag @a @abc234 @abc-234");
9971001

9981002
equal(tokens, [
9991003
{
10001004
kind: TokenSyntaxKind.Text,
1001-
text: "@123 @@ @ @tag @a @abc234",
1005+
text: "@123 @@ @ @tag @a @abc234 @abc-234",
10021006
pos: 0,
10031007
},
10041008
]);

src/test/utils/options/default-options.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,15 @@ describe("Default Options", () => {
161161

162162
describe("blockTags", () => {
163163
it("Should disallow non-tags", () => {
164-
throws(() => opts.setValue("blockTags", ["@bad-non-tag"]));
164+
throws(() => opts.setValue("blockTags", ["@bad_tag"]));
165+
throws(() => opts.setValue("blockTags", ["@2bad"]));
165166
});
166167

167168
it("Should allow tags", () => {
168169
doesNotThrow(() => opts.setValue("blockTags", ["@good"]));
170+
doesNotThrow(() => opts.setValue("blockTags", ["@good2"]));
171+
doesNotThrow(() => opts.setValue("blockTags", ["@Good"]));
172+
doesNotThrow(() => opts.setValue("blockTags", ["@good-tag"]));
169173
});
170174
});
171175

0 commit comments

Comments
 (0)