fix(plugin): emit @throws descriptions as proper string literals#3872
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Apr 22, 2026
Merged
Conversation
getTsDocErrorsOfNode stored the parsed @throws description pre-wrapped in double quotes and the caller then fed that already-quoted text into factory.createNumericLiteral. That accidentally produced a valid-looking string literal for the common case but fell apart as soon as the description contained a character that needs escaping inside a double-quoted string. For example, a controller annotated as: /** * create * @throws {400} foo "bar". */ @post() a() {} transpiled to: openapi.ApiResponse({ status: 400, description: "foo "bar"." }) which is a syntax error when the generated file is later executed. Store the raw description text and status number in the tag record, then emit them with createStringLiteral / createNumericLiteral so the TypeScript printer escapes them correctly. The transpiled output for regular descriptions (and numeric statuses) is byte-identical, but descriptions containing quotes, backslashes, and the like now round-trip through the plugin cleanly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix (plugin / TSDoc @throws handling).
What is the current behavior?
getTsDocErrorsOfNodestored the parsed@throwsdescription pre-wrapped in double quotes and the caller fed that already-quoted text intofactory.createNumericLiteral. That accidentally produced a valid-looking string literal for the common case, but broke as soon as the description contained a character that needs escaping inside a double-quoted string.Minimal repro:
Transpiles to:
…which is a syntax error when the generated file is executed (the
\"bar\"closes the string early). The same class of failure hits any@throwsdescription with a\", a control character, or similar.What is the new behavior?
getTsDocErrorsOfNodenow returns the raw description text and the status as a number.factory.createStringLiteral, so the TypeScript printer escapes the text correctly.After the fix the same input becomes:
Regular descriptions (and numeric statuses) produce byte-identical output; the existing
app.controllerfixture is unchanged.Additional context
Added a dedicated fixture
test/plugin/fixtures/app.controller-throws-quotes.tsand a new test case incontroller-class-visitor.spec.tsto cover the embedded-quote / multi-line@throwspath.