mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
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:
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user