mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Specific diagnostic suggestions for unexpected keyword or identifier (#43005)
Error message improvement for unexpected tokens in the following situations: * A word was parsed that seems to have a low edit distance from a known common keyword * A word was parsed that seems to be a known common keyword and a name _without_ a space in-between * Parsing in a particular type of node (mostly a class property declaration) got a different word or token than expected ___ * Specific diagnostic suggestions for unexpected keywords or identifier * Don't reach into there, that's not allowed * Improved error when there is already an initializer * Specific module error message for invalid template literal strings * Skip 'unexpected keyword or identifier' diagnostics for declare nodes * Improve error for function calls in type positions * Switch class properties to old diagnostic * Corrected errors in class members and reused existing textToKeywordObj map * Corrected more baselines from the merge * Update src/compiler/parser.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Mostly addressed feedback * Clarified function call type message * Split up and clarified parsing vs error functions * Swap interface name complaints back, and skip new errors on unknown (invalid) tokens * Used tokenToString, not a raw semicolon * Inline getExpressionText helper * Remove remarks in src/compiler/parser.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
co-authored by
Daniel Rosenwasser
parent
3358f137c6
commit
541e553163
@@ -0,0 +1,81 @@
|
||||
// @noEmit: true
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
async function myAsyncFunction1() {}
|
||||
asynd function myAsyncFunction2() {}
|
||||
sasync function myAsyncFunction3() {}
|
||||
|
||||
// Arrow functions don't (yet?) parse as nicely as standalone functions.
|
||||
// Eventually it would be good to get them the same "did you mean" for typos such as "asyncd".
|
||||
const myAsyncArrow1 = async () => 3;
|
||||
const myAsyncArrow2 = asyncd () => 3;
|
||||
|
||||
class MyClass1 {}
|
||||
clasd MyClass2 {}
|
||||
classs MyClass3 {}
|
||||
|
||||
const myConst1 = 1;
|
||||
consd myConst2 = 1;
|
||||
constd myConst3 = 1;
|
||||
|
||||
declare const myDeclareConst1: 1;
|
||||
declared const myDeclareConst2: 1;
|
||||
declare constd myDeclareConst3: 1;
|
||||
declared constd myDeclareConst4: 1;
|
||||
declareconst myDeclareConst5;
|
||||
|
||||
function myFunction1() { }
|
||||
functiond myFunction2() { }
|
||||
function function() { }
|
||||
functionMyFunction;
|
||||
|
||||
interface myInterface1 { }
|
||||
interfaced myInterface2 { }
|
||||
interface interface { }
|
||||
interface { }
|
||||
interface void { }
|
||||
interfaceMyInterface { }
|
||||
|
||||
let let = 1;
|
||||
let let1 = 1;
|
||||
letd let2 = 1;
|
||||
letMyLet;
|
||||
|
||||
type type;
|
||||
type type1 = {};
|
||||
type type2 = type;
|
||||
type type3 = {};
|
||||
typed type4 = {}
|
||||
typed type5 = type;
|
||||
typeMyType;
|
||||
|
||||
var myVar1 = 1;
|
||||
vard myVar2 = 1;
|
||||
varMyVar;
|
||||
|
||||
class NoSemicolonClassA {
|
||||
['a'] = 0
|
||||
{}
|
||||
}
|
||||
|
||||
class NoSemicolonClassB {
|
||||
['a'] = 0
|
||||
{}
|
||||
}
|
||||
|
||||
class NoSemicolonClassC {
|
||||
['a'] = 0;
|
||||
{}
|
||||
}
|
||||
|
||||
class NoSemicolonClassD {
|
||||
['a'] = 0
|
||||
['b']() {}
|
||||
}
|
||||
|
||||
class NoSemicolonClassE {
|
||||
['a'] = 0
|
||||
['b']() {
|
||||
c: true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user