Skip to content

Commit bcbce9a

Browse files
committed
style: move parameter range to the end
Follow the existing AST convention that Range is the last constructor field and the last factory/helper parameter. This updates ParameterNode and Node.createParameter accordingly, and adjusts all call sites.
1 parent 53dc57c commit bcbce9a

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/ast.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,10 @@ export abstract class Node {
181181
name: IdentifierExpression,
182182
type: TypeNode,
183183
initializer: Expression | null,
184-
range: Range,
185-
decorators: DecoratorNode[] | null = null
184+
decorators: DecoratorNode[] | null,
185+
range: Range
186186
): ParameterNode {
187-
let parameter = new ParameterNode(parameterKind, name, type, initializer, range);
188-
parameter.decorators = decorators;
189-
return parameter;
187+
return new ParameterNode(parameterKind, name, type, initializer, decorators, range);
190188
}
191189

192190
// special
@@ -971,14 +969,13 @@ export class ParameterNode extends Node {
971969
public type: TypeNode,
972970
/** Initializer expression, if any. */
973971
public initializer: Expression | null,
972+
/** Decorators, if any, preserved so transforms can rewrite them before validation. */
973+
public decorators: DecoratorNode[] | null,
974974
/** Source range. */
975975
range: Range
976976
) {
977977
super(NodeKind.Parameter, range);
978978
}
979-
980-
/** Decorators, if any, preserved so transforms can rewrite them before validation. */
981-
decorators: DecoratorNode[] | null = null;
982979
/** Implicit field declaration, if applicable. */
983980
implicitFieldDeclaration: FieldDeclaration | null = null;
984981
/** Common flags indicating specific traits. */

src/parser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ export class Parser extends DiagnosticEmitter {
803803
return null;
804804
}
805805
this.reportInvalidParameterDecorators(tn);
806-
let param = Node.createParameter(kind, name, type, null, tn.range(paramStart, tn.pos), decorators);
806+
let param = Node.createParameter(kind, name, type, null, decorators, tn.range(paramStart, tn.pos));
807807
if (!parameters) parameters = [ param ];
808808
else parameters.push(param);
809809
} else {
@@ -815,7 +815,7 @@ export class Parser extends DiagnosticEmitter {
815815
}
816816
}
817817
if (isSignature) {
818-
let param = Node.createParameter(kind, name, Node.createOmittedType(tn.range(tn.pos)), null, tn.range(paramStart, tn.pos), decorators);
818+
let param = Node.createParameter(kind, name, Node.createOmittedType(tn.range(tn.pos)), null, decorators, tn.range(paramStart, tn.pos));
819819
if (!parameters) parameters = [ param ];
820820
else parameters.push(param);
821821
this.error(
@@ -869,6 +869,7 @@ export class Parser extends DiagnosticEmitter {
869869
firstParamNameNoType,
870870
Node.createOmittedType(firstParamNameNoType.range.atEnd),
871871
null,
872+
null,
872873
firstParamNameNoType.range
873874
);
874875
if (!parameters) parameters = [ param ];
@@ -1506,8 +1507,8 @@ export class Parser extends DiagnosticEmitter {
15061507
identifier,
15071508
type,
15081509
initializer,
1509-
Range.join(assert(startRange), tn.range()),
1510-
decorators
1510+
decorators,
1511+
Range.join(assert(startRange), tn.range())
15111512
);
15121513
param.flags |= accessFlags;
15131514
return param;
@@ -4040,6 +4041,7 @@ export class Parser extends DiagnosticEmitter {
40404041
identifier,
40414042
Node.createOmittedType(identifier.range.atEnd),
40424043
null,
4044+
null,
40434045
identifier.range
40444046
)
40454047
],

src/program.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,7 @@ export class Program extends DiagnosticEmitter {
27802780
declaration.name,
27812781
typeNode,
27822782
null,
2783+
null,
27832784
declaration.name.range
27842785
)
27852786
],
@@ -4096,7 +4097,10 @@ export class PropertyPrototype extends DeclaredElement {
40964097
new ParameterNode(
40974098
ParameterKind.Default,
40984099
fieldDeclaration.name,
4099-
typeNode, null, nativeRange
4100+
typeNode,
4101+
null,
4102+
null,
4103+
nativeRange
41004104
)
41014105
],
41024106
new NamedTypeNode(

0 commit comments

Comments
 (0)