mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
JSDoc uses same newlines as normal scanner (#39351)
* JSDoc uses same newlines as normal scanner Previously, scanJsDocToken treated each newline character separately, so the sequence \r\n would be treated as two lines. This is unexpected, and not the way the normal scanner does it. This change makes the jsdoc scanner behave the same as the normal scanner. * fix lint in test
This commit is contained in:
committed by
GitHub
parent
e2c5a90cc3
commit
0f9d4c78d4
@@ -2352,8 +2352,12 @@ namespace ts {
|
||||
return token = SyntaxKind.WhitespaceTrivia;
|
||||
case CharacterCodes.at:
|
||||
return token = SyntaxKind.AtToken;
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.carriageReturn:
|
||||
if (text.charCodeAt(pos) === CharacterCodes.lineFeed) {
|
||||
pos++;
|
||||
}
|
||||
// falls through
|
||||
case CharacterCodes.lineFeed:
|
||||
tokenFlags |= TokenFlags.PrecedingLineBreak;
|
||||
return token = SyntaxKind.NewLineTrivia;
|
||||
case CharacterCodes.asterisk:
|
||||
|
||||
@@ -53,6 +53,24 @@ describe("unittests:: Public APIs:: createPrivateIdentifier", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("unittests:: Public APIs:: JSDoc newlines", () => {
|
||||
it("are preserved verbatim", () => {
|
||||
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, /*setParentNodes*/ true);
|
||||
const funcDec = testSourceFile.statements.find(ts.isFunctionDeclaration)!;
|
||||
const tags = ts.getJSDocTags(funcDec);
|
||||
assert.isDefined(tags[0].comment);
|
||||
assert.equal(tags[0].comment, "Some\n text\r\n with newlines.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("unittests:: Public APIs:: isPropertyName", () => {
|
||||
it("checks if a PrivateIdentifier is a valid property name", () => {
|
||||
const prop = ts.factory.createPrivateIdentifier("#foo");
|
||||
|
||||
Reference in New Issue
Block a user