Skip to content

Specific diagnostic suggestions for unexpected keyword or identifier #43005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0c967f9
Specific diagnostic suggestions for unexpected keywords or identifier
Feb 28, 2021
107e10d
Don't reach into there, that's not allowed
Mar 4, 2021
12088e9
Improved error when there is already an initializer
Mar 23, 2021
73a9852
Specific module error message for invalid template literal strings
Mar 28, 2021
cc70a1b
Skip 'unexpected keyword or identifier' diagnostics for declare nodes
Mar 28, 2021
23e0acb
Improve error for function calls in type positions
Mar 28, 2021
5cf8606
Merge branch 'master'
Mar 28, 2021
05e8d0f
Switch class properties to old diagnostic
Apr 7, 2021
f547914
Merge branch 'master'
Apr 7, 2021
972da93
Corrected errors in class members and reused existing textToKeywordOb…
Apr 11, 2021
c554519
Merge branch 'master'
Apr 11, 2021
5a0804b
Corrected more baselines from the merge
Apr 11, 2021
182f75a
Update src/compiler/parser.ts
JoshuaKGoldberg Apr 13, 2021
dabe89a
Mostly addressed feedback
Apr 13, 2021
6d40a4c
Clarified function call type message
Apr 17, 2021
7e49aa6
Split up and clarified parsing vs error functions
Apr 17, 2021
a052314
Swap interface name complaints back, and skip new errors on unknown (…
Apr 17, 2021
8e9e46d
Merge branch 'master'
Apr 17, 2021
dd47c39
Used tokenToString, not a raw semicolon
Apr 17, 2021
ad6f591
Merge branch 'master' into jg-unexpected-keyword-identifier-diagnostics
May 28, 2021
cd4d28d
Merge branch 'main'
Jul 14, 2021
b878e74
Inline getExpressionText helper
Jul 14, 2021
b16d5eb
Remove remarks in src/compiler/parser.ts
JoshuaKGoldberg Jul 14, 2021
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
10 changes: 8 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ namespace ts {
"var",
];

function parseSemicolonAfter(expression: Expression | PropertyName) {
function parseSemicolonAfter(expression: Expression | PropertyName, initializer?: Node) {
// Consume the semicolon if it was explicitly provided.
if (canParseSemicolon()) {
if (token() === SyntaxKind.SemicolonToken) {
Expand All @@ -1541,6 +1541,12 @@ namespace ts {
return;
}

// The only way not having a semicolon after an expression when expected shouldn't create an error
// would be if we've there's an initializer, which would indicate the initializer already has an error
if (initializer) {
return;
}

// Tagged template literals are sometimes used in places where only simple strings are allowed, e.g.:
// module `M1` {
// ^^^^^^^^^^^ This block is parsed as a template literal as with module`M1`.
Expand Down Expand Up @@ -1635,7 +1641,7 @@ namespace ts {
return;
}

return parseSemicolonAfter(name);
return parseSemicolonAfter(name, initializer);
}

function getExpressionText(expression: Expression | PropertyName) {
Expand Down
164 changes: 0 additions & 164 deletions tests/baselines/reference/commonMissingSemicolons.js

This file was deleted.

5 changes: 1 addition & 4 deletions tests/baselines/reference/parser0_004152.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,13): error TS1433: Unexpected keyword or identifier.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,28): error TS2304: Cannot find name 'DisplayPosition'.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,45): error TS1137: Expression or comma expected.
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,46): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
Expand Down Expand Up @@ -34,11 +33,9 @@ tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(2,97): error T
tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts(3,25): error TS2304: Cannot find name 'SeedCoords'.


==== tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts (34 errors) ====
==== tests/cases/conformance/parser/ecmascript5/Fuzz/parser0_004152.ts (33 errors) ====
export class Game {
private position = new DisplayPosition([), 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 0], NoMove, 0);
~~~~~~~~
!!! error TS1433: Unexpected keyword or identifier.
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'DisplayPosition'.
~
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(3,6): error TS2304: Cannot find name 'e'.
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(4,6): error TS2304: Cannot find name 'e2'.
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(4,12): error TS1005: ';' expected.
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(4,12): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(5,1): error TS1128: Declaration or statement expected.


Expand All @@ -14,7 +14,7 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedP
~~
!!! error TS2304: Cannot find name 'e2'.
~
!!! error TS1005: ';' expected.
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
}
~
!!! error TS1128: Declaration or statement expected.
3 changes: 3 additions & 0 deletions tests/cases/compiler/commonMissingSemicolons.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// @noEmit: true
// @noTypesAndSymbols: true

async function myAsyncFunction1() {}
asynd function myAsyncFunction2() {}
sasync function myAsyncFunction3() {}
Expand Down