Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -29938,10 +29938,11 @@ namespace ts {
}

function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
const jsdocTypeParameters = isInJSFile(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 = isInJSFile(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
19 changes: 10 additions & 9 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6517,7 +6517,7 @@ namespace ts {
}
}

function skipWhitespaceOrAsterisk(): void {
function skipWhitespaceOrAsterisk(next: () => void): void {
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 @@ -6532,7 +6532,7 @@ namespace ts {
else if (token() === SyntaxKind.AsteriskToken) {
precedingLineBreak = false;
}
nextJSDocToken();
next();
}
}

Expand All @@ -6542,8 +6542,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 @@ -6687,7 +6688,7 @@ namespace ts {
}

function tryParseTypeExpression(): JSDocTypeExpression | undefined {
skipWhitespaceOrAsterisk();
skipWhitespaceOrAsterisk(nextJSDocToken);
return token() === SyntaxKind.OpenBraceToken ? parseJSDocTypeExpression() : undefined;
}

Expand Down Expand Up @@ -6727,7 +6728,7 @@ namespace ts {
function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, target: PropertyLikeParse, indent: number): JSDocParameterTag | JSDocPropertyTag {
let typeExpression = tryParseTypeExpression();
let isNameFirst = !typeExpression;
skipWhitespaceOrAsterisk();
skipWhitespaceOrAsterisk(nextJSDocToken);

const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
skipWhitespace();
Expand Down Expand Up @@ -6861,7 +6862,7 @@ namespace ts {

function parseTypedefTag(atToken: AtToken, tagName: Identifier, indent: number): JSDocTypedefTag {
const typeExpression = tryParseTypeExpression();
skipWhitespaceOrAsterisk();
skipWhitespaceOrAsterisk(nextJSDocToken);

const typedefTag = <JSDocTypedefTag>createNode(SyntaxKind.JSDocTypedefTag, atToken.pos);
typedefTag.atToken = atToken;
Expand Down Expand Up @@ -7114,7 +7115,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 @@ -7125,7 +7126,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