@@ -698,12 +698,13 @@ export class Parser extends DiagnosticEmitter {
698698 // Indicates whether tryParseSignature determined that it is handling a Signature
699699 private tryParseSignatureIsSignature : bool = false ;
700700
701- /** Parses a function type, as used in type declarations . */
701+ /** Parses a function type, preserving parameter decorators for transforms . */
702702 tryParseFunctionType (
703703 tn : Tokenizer
704704 ) : FunctionTypeNode | null {
705705
706- // at '(': ('...'? Identifier '?'? ':' Type (',' '...'? Identifier '?'? ':' Type)* )? ')' '=>' Type
706+ // at '(': (Decorator* ('...'? Identifier '?'? ':' Type | this ':' Type)
707+ // (',' Decorator* ('...'? Identifier '?'? ':' Type | this ':' Type))* )? ')' '=>' Type
707708
708709 let state = tn . mark ( ) ;
709710 let startPos = tn . tokenPos ;
@@ -937,6 +938,7 @@ export class Parser extends DiagnosticEmitter {
937938 private parseParameterDecorators (
938939 tn : Tokenizer
939940 ) : DecoratorNode [ ] | null {
941+ // Preserve parameter decorators in the AST so transforms can inspect or remove them later.
940942 let decorators : DecoratorNode [ ] | null = null ;
941943 while ( tn . skip ( Token . At ) ) {
942944 let decorator = this . parseDecorator ( tn ) ;
@@ -1249,23 +1251,25 @@ export class Parser extends DiagnosticEmitter {
12491251 return null ;
12501252 }
12511253
1254+ /** Explicit `this` parameter captured by the current parseParameters call, if any. */
12521255 private parseParametersThis : NamedTypeNode | null = null ;
1256+ /** Decorators on the explicit `this` parameter, preserved for transforms. */
12531257 private parseParametersThisDecorators : DecoratorNode [ ] | null = null ;
12541258
12551259 parseParameters (
12561260 tn : Tokenizer ,
12571261 isConstructor : bool = false
12581262 ) : ParameterNode [ ] | null {
12591263
1260- // at '(': (Parameter (',' Parameter)*)? ')'
1264+ // at '(': (Decorator* Parameter (',' Decorator* Parameter)*)? ')'
12611265
12621266 let parameters = new Array < ParameterNode > ( ) ;
12631267 let seenRest : ParameterNode | null = null ;
12641268 let seenOptional = false ;
12651269 let reportedRest = false ;
12661270 let thisType : TypeNode | null = null ;
12671271
1268- // check if there is a leading `this` parameter
1272+ // check if there is a leading `this` parameter, preserving any decorators on it
12691273 this . parseParametersThis = null ;
12701274 this . parseParametersThisDecorators = null ;
12711275
@@ -1361,7 +1365,8 @@ export class Parser extends DiagnosticEmitter {
13611365 decorators : DecoratorNode [ ] | null = null
13621366 ) : ParameterNode | null {
13631367
1364- // before: ('public' | 'private' | 'protected' | '...')? Identifier '?'? (':' Type)? ('=' Expression)?
1368+ // before: Decorator* ('public' | 'private' | 'protected' | 'readonly')? '...'? Identifier
1369+ // '?'? (':' Type)? ('=' Expression)?
13651370
13661371 let isRest = false ;
13671372 let isOptional = false ;
0 commit comments