You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSDoc stripping leading whitespace in code blocks #15749
The problem is that the code currently only handle indentations of the form
/** * @example if (true) { * foo() * } */
The code starts off parsing @example's comment with the wrong indentation because it doesn't reset the indent level after parsing @example followed by newline.
Edit: the code is wrong for Larry Gordon (@psyrendust)'s last example, not for the oddly-indented example I just gave.
Reacted by Christian Svensson, Nathan Diddle, JongChan Choi (Rieul), Bartosz Łaniewski and Alisson Nunes
Doubling what @tulio-coppola said, <caption> seems to break things. <caption> requires an initial indentation, whereas, without <caption> (second example below) no initial indentation is required
Example:
/** * Create a new type which has the properties of `Base` that match `Condition` * * @example <caption>This example extracts properties of `foo` that have a value type of `string`</caption> * // `fooT` is now { a: string, d: string } * // `fooKT` is now ` 'a' | 'd' ` * interface foo { * a: string; * b: number; * c: string[]; * d: string; * } * type fooT = SubType<foo, string>; * type fooKT = keyof fooT ; * @example * interface foo { * prop: string; * } */exporttypeSubType<Base,Condition>=Pick<Base,AllowedNames<Base,Condition>>;
results in:
This is 1.45.1 on Windows
Reacted by David Wheatley, Daniel Farlow and marvinderksen
Activity
mjbvz commentedon May 10, 2017
This does not happen if you have an extra newlines before the code block:
jiayihu commentedon Jul 10, 2018
The issue is still there, where should I have a look in order to fix it and open a PR?
mhegazy commentedon Jul 10, 2018
Nathan Shively-Sanders (@sandersn), can you point Jiayi Hu (@jiayihu) to where this change needs to be made
sandersn commentedon Jul 10, 2018
Take a look at
parseTagComments, although the bug might be in the initial state when calling the function, since there's an initialindentpassed in.[-]JSDoc Stripping Leading WhiteSpace in CodeBlocks[/-][+]JSDoc stripping leading whitespace in code blocks[/+]psyrendust commentedon Oct 31, 2018
I'm getting a slightly different results in vscode Version 1.28.2 (1.28.2)
with newline after
@exampleno newline after
@exampleno fenced code blocks
sandersn commentedon Mar 13, 2019
In summary, the original issue is fixed, but unfenced code blocks still squash leading white space as in Larry Gordon (@psyrendust)'s last example.
The parser doesn't know about markdown, so I suspect this is caused later in the pipeline. Needs investigation.
sandersn commentedon Apr 8, 2019
The problem is that the code currently only handle indentations of the form
The code starts off parsing
@example's comment with the wrong indentation because it doesn't reset the indent level after parsing@examplefollowed by newline.Edit: the code is wrong for Larry Gordon (@psyrendust)'s last example, not for the oddly-indented example I just gave.
justinmchase commentedon Feb 26, 2020
I see that this is closed but it appears to still be a bug in the latest release.
mjbvz commentedon Feb 26, 2020
The original example works for me in VS Code 1.43:
justinmchase commentedon Feb 26, 2020
False alarm. It wasn't working for me I swear, but just trying it again its now fine... Please ignore.
tuliocoppola commentedon May 11, 2020
A related issue still occurring on version 1.44.0
The original example works:

But if you use the

<caption>tag on the@exampleit breaks again and trims the whitespaces:erichiller commentedon Jun 8, 2020
Doubling what @tulio-coppola said,
<caption>seems to break things.<caption>requires an initial indentation, whereas, without<caption>(second example below) no initial indentation is requiredExample:
results in:

This is 1.45.1 on Windows
davwheat commentedon May 1, 2021
This issue is still present in the latest version of TS and VSCode.
sandersn commentedon May 4, 2021
Please open a new issue; this one has been closed a long time.