Corrected parsing for decorators on 'this' parameters (#43175)

* Corrected parsing for decorators on 'this' parameters

* Moved checking to parser and added a specific test

* Remove unrelated checker.ts blank line

* Missed some baseeline updates...
This commit is contained in:
Josh Goldberg
2021-04-07 14:21:28 -04:00
committed by GitHub
parent 2484210a00
commit 905a1fea39
15 changed files with 175 additions and 33 deletions

View File

@@ -1360,6 +1360,10 @@
"category": "Error",
"code": 1432
},
"Decorators may not be applied to 'this' parameters.": {
"category": "Error",
"code": 1433
},
"The types of '{0}' are incompatible between these types.": {
"category": "Error",

View File

@@ -2991,9 +2991,16 @@ namespace ts {
function parseParameterWorker(inOuterAwaitContext: boolean): ParameterDeclaration {
const pos = getNodePos();
const hasJSDoc = hasPrecedingJSDocComment();
// FormalParameter [Yield,Await]:
// BindingElement[?Yield,?Await]
// Decorators are parsed in the outer [Await] context, the rest of the parameter is parsed in the function's [Await] context.
const decorators = inOuterAwaitContext ? doInAwaitContext(parseDecorators) : parseDecorators();
if (token() === SyntaxKind.ThisKeyword) {
const node = factory.createParameterDeclaration(
/*decorators*/ undefined,
decorators,
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
createIdentifier(/*isIdentifier*/ true),
@@ -3001,14 +3008,14 @@ namespace ts {
parseTypeAnnotation(),
/*initializer*/ undefined
);
if (decorators) {
parseErrorAtRange(decorators[0], Diagnostics.Decorators_may_not_be_applied_to_this_parameters);
}
return withJSDoc(finishNode(node, pos), hasJSDoc);
}
// FormalParameter [Yield,Await]:
// BindingElement[?Yield,?Await]
// Decorators are parsed in the outer [Await] context, the rest of the parameter is parsed in the function's [Await] context.
const decorators = inOuterAwaitContext ? doInAwaitContext(parseDecorators) : parseDecorators();
const savedTopLevel = topLevel;
topLevel = false;
const modifiers = parseModifiers();