Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29593,10 +29593,11 @@ namespace ts {
}

function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
const jsdocTypeParameters = isInJavaScriptFile(node) && getJSDocTypeParameterDeclarations(node);
if (node.typeParameters || jsdocTypeParameters && jsdocTypeParameters.length) {
const { pos, end } = node.typeParameters || jsdocTypeParameters && jsdocTypeParameters[0] || node;
return grammarErrorAtPos(node, pos, end - pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
const jsdocTypeParameters = isInJavaScriptFile(node) ? getJSDocTypeParameterDeclarations(node) : undefined;
const range = node.typeParameters || jsdocTypeParameters && firstOrUndefined(jsdocTypeParameters);
if (range) {
const pos = range.pos === range.end ? range.pos : skipTrivia(getSourceFileOfNode(node).text, range.pos);
return grammarErrorAtPos(node, pos, range.end - pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6513,7 +6513,7 @@ namespace ts {
}
}

function skipWhitespaceOrAsterisk(): void {
function skipWhitespaceOrAsterisk(next: () => void = nextJSDocToken): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better (at least slightly) to make next required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about for parseJSDocIdentifierName?

if (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) {
if (lookAhead(isNextNonwhitespaceTokenEndOfFile)) {
return; // Don't skip whitespace prior to EoF (or end of comment) - that shouldn't be included in any node's range
Expand All @@ -6528,7 +6528,7 @@ namespace ts {
else if (token() === SyntaxKind.AsteriskToken) {
precedingLineBreak = false;
}
nextJSDocToken();
next();
}
}

Expand All @@ -6538,8 +6538,9 @@ namespace ts {
atToken.end = scanner.getTextPos();
nextJSDocToken();

const tagName = parseJSDocIdentifierName();
skipWhitespaceOrAsterisk();
// Use 'nextToken' instead of 'nextJsDocToken' so we can parse a type like 'number' in `@enum number`
const tagName = parseJSDocIdentifierName(/*message*/ undefined, nextToken);
skipWhitespaceOrAsterisk(nextToken);

let tag: JSDocTag | undefined;
switch (tagName.escapedText) {
Expand Down Expand Up @@ -7113,7 +7114,7 @@ namespace ts {
return entity;
}

function parseJSDocIdentifierName(message?: DiagnosticMessage): Identifier {
function parseJSDocIdentifierName(message?: DiagnosticMessage, next: () => void = nextJSDocToken): Identifier {
if (!tokenIsIdentifierOrKeyword(token())) {
return createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ !message, message || Diagnostics.Identifier_expected);
}
Expand All @@ -7124,7 +7125,7 @@ namespace ts {
result.escapedText = escapeLeadingUnderscores(scanner.getTokenText());
finishNode(result, end);

nextJSDocToken();
next();
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"0": {
"kind": "JSDocTag",
"pos": 63,
"end": 68,
"end": 67,
"atToken": {
"kind": "AtToken",
"pos": 63,
Expand All @@ -22,7 +22,7 @@
},
"length": 1,
"pos": 63,
"end": 68
"end": 67
},
"comment": "{@link first link}\nInside {@link link text} thing"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typeParameters": {
"0": {
"kind": "TypeParameter",
"pos": 18,
"pos": 17,
"end": 19,
"name": {
"kind": "Identifier",
Expand All @@ -31,7 +31,7 @@
}
},
"length": 1,
"pos": 18,
"pos": 17,
"end": 19
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typeParameters": {
"0": {
"kind": "TypeParameter",
"pos": 18,
"pos": 17,
"end": 19,
"name": {
"kind": "Identifier",
Expand All @@ -42,7 +42,7 @@
}
},
"length": 2,
"pos": 18,
"pos": 17,
"end": 21
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typeParameters": {
"0": {
"kind": "TypeParameter",
"pos": 18,
"pos": 17,
"end": 19,
"name": {
"kind": "Identifier",
Expand All @@ -42,7 +42,7 @@
}
},
"length": 2,
"pos": 18,
"pos": 17,
"end": 22
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typeParameters": {
"0": {
"kind": "TypeParameter",
"pos": 18,
"pos": 17,
"end": 19,
"name": {
"kind": "Identifier",
Expand All @@ -42,7 +42,7 @@
}
},
"length": 2,
"pos": 18,
"pos": 17,
"end": 22
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typeParameters": {
"0": {
"kind": "TypeParameter",
"pos": 18,
"pos": 17,
"end": 19,
"name": {
"kind": "Identifier",
Expand All @@ -42,7 +42,7 @@
}
},
"length": 2,
"pos": 18,
"pos": 17,
"end": 23
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typeParameters": {
"0": {
"kind": "TypeParameter",
"pos": 18,
"pos": 17,
"end": 19,
"name": {
"kind": "Identifier",
Expand All @@ -42,7 +42,7 @@
}
},
"length": 2,
"pos": 18,
"pos": 17,
"end": 24
},
"comment": "Description of type parameters."
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/enumTag.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests/cases/conformance/jsdoc/a.js(37,16): error TS2339: Property 'UNKNOWN' does
/** @type {number} */
OK_I_GUESS: 2
}
/** @enum {number} */
/** @enum number */
const Second = {
MISTAKE: "end",
~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/enumTag.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Target = {
OK_I_GUESS: 2
>OK_I_GUESS : Symbol(OK_I_GUESS, Decl(a.js, 5, 15))
}
/** @enum {number} */
/** @enum number */
const Second = {
>Second : Symbol(Second, Decl(a.js, 10, 5))

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/enumTag.types
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Target = {
>OK_I_GUESS : number
>2 : 2
}
/** @enum {number} */
/** @enum number */
const Second = {
>Second : { MISTAKE: string; OK: number; FINE: number; }
>{ MISTAKE: "end", OK: 1, /** @type {number} */ FINE: 2,} : { MISTAKE: string; OK: number; FINE: number; }
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/paramTagWrapping.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/jsdoc/bad.js(2,11): error TS1003: Identifier expected.
tests/cases/conformance/jsdoc/bad.js(2,11): error TS8024: JSDoc '@param' tag has name '', but there is no parameter with that name.
tests/cases/conformance/jsdoc/bad.js(2,10): error TS1003: Identifier expected.
tests/cases/conformance/jsdoc/bad.js(2,10): error TS8024: JSDoc '@param' tag has name '', but there is no parameter with that name.
tests/cases/conformance/jsdoc/bad.js(5,4): error TS1003: Identifier expected.
tests/cases/conformance/jsdoc/bad.js(5,4): error TS8024: JSDoc '@param' tag has name '', but there is no parameter with that name.
tests/cases/conformance/jsdoc/bad.js(6,19): error TS1003: Identifier expected.
Expand Down Expand Up @@ -27,9 +27,9 @@ tests/cases/conformance/jsdoc/bad.js(9,20): error TS7006: Parameter 'z' implicit
==== tests/cases/conformance/jsdoc/bad.js (9 errors) ====
/**
* @param *

!!! error TS1003: Identifier expected.

!!! error TS8024: JSDoc '@param' tag has name '', but there is no parameter with that name.
* {number} x Arg x.
* @param {number}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/conformance/jsdoc/enumTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Target = {
/** @type {number} */
OK_I_GUESS: 2
}
/** @enum {number} */
/** @enum number */
const Second = {
MISTAKE: "end",
OK: 1,
Expand Down