mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
Use nextToken() after parsing a tag name so we can parse type keywords (#26915)
* Use nextToken() after parsing a tag name so we can parse type keywords * Make callback to skipWhitespaceOrAsterisk non-optional
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -6532,7 +6532,7 @@ namespace ts {
|
||||
else if (token() === SyntaxKind.AsteriskToken) {
|
||||
precedingLineBreak = false;
|
||||
}
|
||||
nextJSDocToken();
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -6687,7 +6688,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function tryParseTypeExpression(): JSDocTypeExpression | undefined {
|
||||
skipWhitespaceOrAsterisk();
|
||||
skipWhitespaceOrAsterisk(nextJSDocToken);
|
||||
return token() === SyntaxKind.OpenBraceToken ? parseJSDocTypeExpression() : undefined;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -7125,7 +7126,7 @@ namespace ts {
|
||||
result.escapedText = escapeLeadingUnderscores(scanner.getTokenText());
|
||||
finishNode(result, end);
|
||||
|
||||
nextJSDocToken();
|
||||
next();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"0": {
|
||||
"kind": "JSDocTag",
|
||||
"pos": 63,
|
||||
"end": 68,
|
||||
"end": 67,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 63,
|
||||
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"length": 1,
|
||||
"pos": 63,
|
||||
"end": 68
|
||||
"end": 67
|
||||
},
|
||||
"comment": "{@link first link}\nInside {@link link text} thing"
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
"typeParameters": {
|
||||
"0": {
|
||||
"kind": "TypeParameter",
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19,
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
@@ -31,7 +31,7 @@
|
||||
}
|
||||
},
|
||||
"length": 1,
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"typeParameters": {
|
||||
"0": {
|
||||
"kind": "TypeParameter",
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19,
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
},
|
||||
"length": 2,
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 21
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"typeParameters": {
|
||||
"0": {
|
||||
"kind": "TypeParameter",
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19,
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
},
|
||||
"length": 2,
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 22
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"typeParameters": {
|
||||
"0": {
|
||||
"kind": "TypeParameter",
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19,
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
},
|
||||
"length": 2,
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 22
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"typeParameters": {
|
||||
"0": {
|
||||
"kind": "TypeParameter",
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19,
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
},
|
||||
"length": 2,
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 23
|
||||
}
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"typeParameters": {
|
||||
"0": {
|
||||
"kind": "TypeParameter",
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 19,
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
@@ -42,7 +42,7 @@
|
||||
}
|
||||
},
|
||||
"length": 2,
|
||||
"pos": 18,
|
||||
"pos": 17,
|
||||
"end": 24
|
||||
},
|
||||
"comment": "Description of type parameters."
|
||||
|
||||
@@ -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",
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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.
|
||||
@@ -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}
|
||||
|
||||
@@ -11,7 +11,7 @@ const Target = {
|
||||
/** @type {number} */
|
||||
OK_I_GUESS: 2
|
||||
}
|
||||
/** @enum {number} */
|
||||
/** @enum number */
|
||||
const Second = {
|
||||
MISTAKE: "end",
|
||||
OK: 1,
|
||||
|
||||
Reference in New Issue
Block a user