Remove error on invalid jsdoc tokens (#32769)

* Remove error on invalid jsdoc tokens

In JSDoc:

1. In the scanner, don't issue an error, even for invalid identifiers.
2. In the binder, don't issue an error for reserved (but otherwise valid)
identifiers.

/**
 * Example of 1: "\"
 * Example of 2: @private
 */

* Update baselines

* Add invalid unicode escape test for JSDoc

* Add quotes around invalid unicode escape

* Add another unicode escape JSDoc test
This commit is contained in:
Nathan Shively-Sanders 2019-08-09 12:53:15 -07:00 committed by GitHub
parent b24050aefd
commit 85b8d27ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 77 additions and 5 deletions

View File

@ -1842,7 +1842,8 @@ namespace ts {
node.originalKeywordKind! >= SyntaxKind.FirstFutureReservedWord &&
node.originalKeywordKind! <= SyntaxKind.LastFutureReservedWord &&
!isIdentifierName(node) &&
!(node.flags & NodeFlags.Ambient)) {
!(node.flags & NodeFlags.Ambient) &&
!(node.flags & NodeFlags.JSDoc)) {
// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length) {

View File

@ -6434,7 +6434,7 @@ namespace ts {
export function parseIsolatedJSDocComment(content: string, start: number | undefined, length: number | undefined): { jsDoc: JSDoc, diagnostics: Diagnostic[] } | undefined {
initializeState(content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
sourceFile = <SourceFile>{ languageVariant: LanguageVariant.Standard, text: content }; // tslint:disable-line no-object-literal-type-assertion
const jsDoc = parseJSDocCommentWorker(start, length);
const jsDoc = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
const diagnostics = parseDiagnostics;
clearState();
@ -6446,7 +6446,7 @@ namespace ts {
const saveParseDiagnosticsLength = parseDiagnostics.length;
const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
const comment = parseJSDocCommentWorker(start, length);
const comment = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
if (comment) {
comment.parent = parent;
}
@ -6477,7 +6477,7 @@ namespace ts {
CallbackParameter = 1 << 2,
}
export function parseJSDocCommentWorker(start = 0, length: number | undefined): JSDoc | undefined {
function parseJSDocCommentWorker(start = 0, length: number | undefined): JSDoc | undefined {
const content = sourceText;
const end = length === undefined ? content.length : start + length;
length = end - start;

View File

@ -2159,7 +2159,6 @@ namespace ts {
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
return token = getIdentifierToken();
}
error(Diagnostics.Invalid_character);
pos++;
return token = SyntaxKind.Unknown;
}

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 127,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 66,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 44,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 49,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 23,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "* @type {number}"

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 112,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 5,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0
}

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 61,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 20,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 34,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 59,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 61,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 66,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 34,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 46,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 23,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 29,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 54,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 30,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 24,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 26,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 28,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 60,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 7,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "*"

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 60,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 56,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 102,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {

View File

@ -0,0 +1,12 @@
=== tests/cases/conformance/scanner/jsdocInvalidTokens.js ===
/**
*
* unicode-escape = "\u{abcdefghi}" -- should not have error for invalid unicode escape
* unicode-escape2 = "qq\u{abcdefghi}" -- no error here either
* quoted-pair = "\" -- should not have error for invalid quote sequence
* or for the tag below:
* @private
*/
var hi = 1
>hi : Symbol(hi, Decl(jsdocInvalidTokens.js, 8, 3))

View File

@ -0,0 +1,13 @@
=== tests/cases/conformance/scanner/jsdocInvalidTokens.js ===
/**
*
* unicode-escape = "\u{abcdefghi}" -- should not have error for invalid unicode escape
* unicode-escape2 = "qq\u{abcdefghi}" -- no error here either
* quoted-pair = "\" -- should not have error for invalid quote sequence
* or for the tag below:
* @private
*/
var hi = 1
>hi : number
>1 : 1

View File

@ -0,0 +1,15 @@
// @Filename: jsdocInvalidTokens.js
// @strict: true
// @allowJs: true
// @checkJs: true
// @noEmit: true
/**
*
* unicode-escape = "\u{abcdefghi}" -- should not have error for invalid unicode escape
* unicode-escape2 = "qq\u{abcdefghi}" -- no error here either
* quoted-pair = "\" -- should not have error for invalid quote sequence
* or for the tag below:
* @private
*/
var hi = 1