Skip to content

JSDocTag#comment has CRLF newlines as CR #35511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsherret opened this issue Dec 5, 2019 · 3 comments · Fixed by #38036 or #39351
Closed

JSDocTag#comment has CRLF newlines as CR #35511

dsherret opened this issue Dec 5, 2019 · 3 comments · Fixed by #38036 or #39351
Assignees
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fix Available A PR has been opened for this issue

Comments

@dsherret
Copy link
Contributor

dsherret commented Dec 5, 2019

TypeScript Version: 3.8.0-dev.20191128

Search Terms: JSDocTag newlines comment

Code

import * as ts from "typescript";

console.log(ts.version); // 3.8.0-dev.20191128

const testFilePath = "/file.ts";
const testFileText = `
/**
 * @example
 * Some\n * text\r\n * with newlines.
 */
function test() {}`;

const testSourceFile = ts.createSourceFile(testFilePath, testFileText, ts.ScriptTarget.Latest, true);
const funcDec = testSourceFile.statements.find(ts.isFunctionDeclaration)!;
const tags = ts.getJSDocTags(funcDec);

console.log(JSON.stringify(tags[0].comment)); // "Some\ntext\rwith newlines."

Expected behavior:

Either:

  • "Some\ntext\r\nwith newlines." <-- probably as-is?
  • "Some\ntext\nwith newlines."

Actual behavior:

Outputs: "Some\ntext\rwith newlines."

@dsherret dsherret changed the title JSDocTag#comment parses CRLF newlines as CR JSDocTag#comment has CRLF newlines as CR Dec 5, 2019
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation labels Jan 15, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.9.0 milestone Jan 15, 2020
@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Jan 15, 2020
@sandersn
Copy link
Member

I don't think I'll have time to fix this for 3.9, so I'm moving to 4.0.

Reminder: It's still help wanted in case anybody else wants to look at it.

@sandersn
Copy link
Member

The problem is in the interaction between the scanner and the jsdoc comment parser; the scanner treats \r and \n as two newlines in a row. The parser only includes the first newline in a sequence of multiple empty newlines.

Either of those rules could be incorrect. The scanner one feels wrong to me — \r\n should really be one newline — but there may be compatibility concerns with changing it.

Squashing completely empty newlines makes sense, although it's kind of a corner case. I suspect there are additional reasons for the rule though.

@sandersn sandersn added Fix Available A PR has been opened for this issue and removed Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Jun 30, 2020
@sandersn
Copy link
Member

Turns out it was the jsdoc scanner at fault, so I'm pretty confident in changing it; I think only API users will already depend on its current newline treatment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fix Available A PR has been opened for this issue
Projects
None yet
4 participants