Skip to content

Commit ba37601

Browse files
committed
style: include explicit this decorators in function types
Account for explicit-this parameter decorators in the same way as parameter decorators: wire explicitThisDecorators through FunctionTypeNode and Node.createFunctionType, keep it adjacent to explicitThisType, and leave range as the last constructor/helper parameter. Update all call sites accordingly.
1 parent bcbce9a commit ba37601

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/ast.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ export abstract class Node {
155155
parameters: ParameterNode[],
156156
returnType: TypeNode,
157157
explicitThisType: NamedTypeNode | null,
158+
explicitThisDecorators: DecoratorNode[] | null,
158159
isNullable: bool,
159160
range: Range
160161
): FunctionTypeNode {
161-
return new FunctionTypeNode(parameters, returnType, explicitThisType, isNullable, range);
162+
return new FunctionTypeNode(parameters, returnType, explicitThisType, explicitThisDecorators, isNullable, range);
162163
}
163164

164165
static createOmittedType(
@@ -920,16 +921,15 @@ export class FunctionTypeNode extends TypeNode {
920921
public returnType: TypeNode,
921922
/** Explicitly provided this type, if any. */
922923
public explicitThisType: NamedTypeNode | null, // can't be a function
924+
/** Decorators on an explicit `this` parameter, if any, preserved for transforms. */
925+
public explicitThisDecorators: DecoratorNode[] | null,
923926
/** Whether nullable or not. */
924927
isNullable: bool,
925928
/** Source range. */
926929
range: Range
927930
) {
928931
super(NodeKind.FunctionType, isNullable, range);
929932
}
930-
931-
/** Decorators on an explicit `this` parameter, if any, preserved for transforms. */
932-
explicitThisDecorators: DecoratorNode[] | null = null;
933933
}
934934

935935
/** Represents a type parameter. */

src/parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,10 @@ export class Parser extends DiagnosticEmitter {
905905
parameters,
906906
returnType,
907907
thisType,
908+
thisDecorators,
908909
false,
909910
tn.range(startPos, tn.pos)
910911
);
911-
functionType.explicitThisDecorators = thisDecorators;
912912
this.noteFunctionTypeParameterDecorators(functionType);
913913
return functionType;
914914
}
@@ -1617,10 +1617,10 @@ export class Parser extends DiagnosticEmitter {
16171617
parameters,
16181618
returnType,
16191619
thisType,
1620+
this.parseParametersThisDecorators,
16201621
false,
16211622
tn.range(signatureStart, tn.pos)
16221623
);
1623-
signature.explicitThisDecorators = this.parseParametersThisDecorators;
16241624
this.noteFunctionTypeParameterDecorators(signature);
16251625

16261626
let body: Statement | null = null;
@@ -1743,10 +1743,10 @@ export class Parser extends DiagnosticEmitter {
17431743
parameters,
17441744
returnType,
17451745
explicitThis,
1746+
explicitThisDecorators,
17461747
false,
17471748
tn.range(signatureStart, tn.pos)
17481749
);
1749-
signature.explicitThisDecorators = explicitThisDecorators;
17501750
this.noteFunctionTypeParameterDecorators(signature);
17511751

17521752
let body: Statement | null = null;
@@ -2390,10 +2390,10 @@ export class Parser extends DiagnosticEmitter {
23902390
parameters,
23912391
returnType,
23922392
thisType,
2393+
this.parseParametersThisDecorators,
23932394
false,
23942395
tn.range(signatureStart, tn.pos)
23952396
);
2396-
signature.explicitThisDecorators = this.parseParametersThisDecorators;
23972397
this.noteFunctionTypeParameterDecorators(signature);
23982398

23992399
let body: Statement | null = null;

src/program.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,10 @@ export class Program extends DiagnosticEmitter {
933933
Node.createSimpleTypeName(CommonNames.void_, range),
934934
null, false, range
935935
),
936-
null, false, range
936+
null,
937+
null,
938+
false,
939+
range
937940
);
938941
}
939942
return Node.createFunctionDeclaration(
@@ -2758,6 +2761,7 @@ export class Program extends DiagnosticEmitter {
27582761
[],
27592762
typeNode,
27602763
null,
2764+
null,
27612765
false,
27622766
declaration.range
27632767
),
@@ -2786,6 +2790,7 @@ export class Program extends DiagnosticEmitter {
27862790
],
27872791
Node.createOmittedType(declaration.name.range.atEnd),
27882792
null,
2793+
null,
27892794
false,
27902795
declaration.range
27912796
),
@@ -4083,7 +4088,7 @@ export class PropertyPrototype extends DeclaredElement {
40834088
fieldDeclaration.decorators,
40844089
fieldDeclaration.flags | CommonFlags.Instance | CommonFlags.Get,
40854090
null,
4086-
new FunctionTypeNode([], typeNode, null, false, nativeRange),
4091+
new FunctionTypeNode([], typeNode, null, null, false, nativeRange),
40874092
null,
40884093
nativeRange
40894094
);
@@ -4110,7 +4115,10 @@ export class PropertyPrototype extends DeclaredElement {
41104115
),
41114116
null, false, nativeRange
41124117
),
4113-
null, false, nativeRange
4118+
null,
4119+
null,
4120+
false,
4121+
nativeRange
41144122
),
41154123
null, nativeRange
41164124
);

0 commit comments

Comments
 (0)