diff --git a/src/common/jsdoc.ts b/src/common/jsdoc.ts index e8ae22f..b53eead 100644 --- a/src/common/jsdoc.ts +++ b/src/common/jsdoc.ts @@ -62,13 +62,15 @@ export namespace JsDoc { return yield* ParseContent(rest) } for (let i = 0; i < content.length; i++) { - if (content[i] === '\n' || content[i] === '-') { + if (content[i] === '\n' || (content[i] === '-' && i > 0)) { const value = content.slice(0, i).trim() const rest = content.slice(i) yield [key, Decode(value)] return yield* ParseContent(rest) } } + // If we reach the end without finding a delimiter, yield the entire content + yield [key, Decode(content.trim())] } function* ParseKey(content: string): IterableIterator<[string, any]> { for (let i = 1; i < content.length; i++) { diff --git a/test/ts2typebox/index.ts b/test/ts2typebox/index.ts index da59c96..2c6e817 100644 --- a/test/ts2typebox/index.ts +++ b/test/ts2typebox/index.ts @@ -575,5 +575,47 @@ describe('ts2typebox - Typescript to Typebox', () => { ` expectEqualIgnoreFormatting(generatedTypebox, expectedResult) }) + test('negative numbers in jsdoc tags', () => { + const generatedTypebox = TypeScriptToTypeBox.Generate(` + /** + * @minimum -10 + * @maximum -5 + * @default -7 + */ + type T = number; + `) + const expectedResult = ` + import { Type, Static } from "@sinclair/typebox"; + + type T = Static; + const T = Type.Number({ minimum: -10, maximum: -5, default: -7 }); + ` + expectEqualIgnoreFormatting(generatedTypebox, expectedResult) + }) + test('negative numbers with description and dash comment', () => { + const generatedTypebox = TypeScriptToTypeBox.Generate(` + type T = { + /** + * @minimum -10 + * @maximum -5 + * @description "A negative range" - this is a comment + */ + value: number; + } + `) + const expectedResult = ` + import { Type, Static } from "@sinclair/typebox"; + + type T = Static; + const T = Type.Object({ + value: Type.Number({ + minimum: -10, + maximum: -5, + description: "A negative range", + }), + }); + ` + expectEqualIgnoreFormatting(generatedTypebox, expectedResult) + }) }) })