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
3 changes: 2 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,6 @@ namespace ts {
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
return token = getIdentifierToken();
}
error(Diagnostics.Invalid_character);
pos++;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also be ignoring errors on invalid Unicode escapes, like \u{1010101010}? That'll require passing a flag into scanIdentifierParts and the other callers of scanExtendedUnicodeEscape.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can't get any error with the current code! I compared

/**
 * unicode-escape = \u{abcdefghi} -- should not have error for invalid unicode escape
 */
var hi = "\u{00fa}\u{abcdefghi}"

There's an error for the second abcdefghi but not the first.

I'll add a test to make sure it stays that way.

Copy link
Copy Markdown
Member

@weswigham weswigham Aug 9, 2019

Choose a reason for hiding this comment

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

You should also check, just in case, the scenario when the unicode escape is the second character in the identifier eg, q\u{abcdefghi} - The first character is handled inline in scanJsDocToken with a non-erroring peek (so it can fallback to the Invalid character error you just removed), while the second character (and beyond) is handled in scanIdentifierParts which, could always behave different.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

return token = SyntaxKind.Unknown;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 127,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 66,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 44,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 49,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 23,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "* @type {number}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 112,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 5,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 61,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 20,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 34,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 59,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 61,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 66,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 34,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 46,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 23,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 29,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 54,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 30,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 24,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 26,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 28,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 60,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 7,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 60,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 56,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 27,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"kind": "JSDocComment",
"pos": 0,
"end": 102,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/jsdocInvalidTokens.symbols
Original file line number Diff line number Diff line change
@@ -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))

13 changes: 13 additions & 0 deletions tests/baselines/reference/jsdocInvalidTokens.types
Original file line number Diff line number Diff line change
@@ -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

15 changes: 15 additions & 0 deletions tests/cases/conformance/scanner/jsdocInvalidTokens.ts
Original file line number Diff line number Diff line change
@@ -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