Skip to content

Commit bbe543e

Browse files
committed
since using the constant groupId there is no need for the group to be stored in a variable and can go directly in the resulting document
1 parent 0b009c6 commit bbe543e

5 files changed

Lines changed: 30 additions & 37 deletions

File tree

src/slang-nodes/FunctionCallExpression.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ export class FunctionCallExpression implements SlangNode {
3939
}
4040

4141
print(path: AstPath<FunctionCallExpression>, print: PrintFunction): Doc {
42-
let operandDoc = path.call(print, 'operand');
43-
let argumentsDoc = path.call(print, 'arguments');
42+
const operandDoc = path.call(print, 'operand');
43+
const argumentsDoc = path.call(print, 'arguments');
4444

4545
// If we are at the end of a MemberAccessChain we should indent the
4646
// arguments accordingly.
4747
if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') {
4848
const groupId = Symbol('Slang.FunctionCallExpression.operand');
49-
operandDoc = group(operandDoc.contents, { id: groupId });
50-
argumentsDoc = indentIfBreak(argumentsDoc, { groupId });
5149
// We wrap the expression in a label in case there is an IndexAccess or
5250
// a FunctionCall following this IndexAccess.
53-
return label('MemberAccessChain', [operandDoc, argumentsDoc]);
51+
return label('MemberAccessChain', [
52+
group(operandDoc.contents, { id: groupId }),
53+
indentIfBreak(argumentsDoc, { groupId })
54+
]);
5455
}
5556

5657
return [operandDoc, argumentsDoc].flat();

src/slang-nodes/IndexAccessExpression.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export class IndexAccessExpression implements SlangNode {
4343
}
4444

4545
print(path: AstPath<IndexAccessExpression>, print: PrintFunction): Doc {
46-
let operandDoc: Doc = path.call(print, 'operand');
47-
let indexDoc: Doc = group([
46+
const operandDoc: Doc = path.call(print, 'operand');
47+
const indexDoc: Doc = group([
4848
'[',
4949
indent([softline, path.call(print, 'start'), path.call(print, 'end')]),
5050
softline,
@@ -55,12 +55,12 @@ export class IndexAccessExpression implements SlangNode {
5555
// arguments accordingly.
5656
if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') {
5757
const groupId = Symbol('Slang.IndexAccessExpression.operand');
58-
operandDoc = group(operandDoc.contents, { id: groupId });
59-
60-
indexDoc = indentIfBreak(indexDoc, { groupId });
6158
// We wrap the expression in a label in case there is an IndexAccess or
6259
// a FunctionCall following this IndexAccess.
63-
return label('MemberAccessChain', [operandDoc, indexDoc]);
60+
return label('MemberAccessChain', [
61+
group(operandDoc.contents, { id: groupId }),
62+
indentIfBreak(indexDoc, { groupId })
63+
]);
6464
}
6565

6666
return [operandDoc, indexDoc].flat();

src/slang-nodes/StateVariableDefinition.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ export class StateVariableDefinition implements SlangNode {
5353

5454
print(path: AstPath<StateVariableDefinition>, print: PrintFunction): Doc {
5555
const groupId = Symbol('Slang.StateVariableDefinition.attributes');
56-
const attributesDoc = group(indent(path.call(print, 'attributes')), {
57-
id: groupId
58-
});
59-
6056
return [
6157
path.call(print, 'typeName'),
62-
attributesDoc,
58+
group(indent(path.call(print, 'attributes')), { id: groupId }),
6359
' ',
6460
path.call(print, 'name'),
6561
this.value ? indentIfBreak(path.call(print, 'value'), { groupId }) : '',

src/slang-nodes/TupleDeconstructionStatement.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ export class TupleDeconstructionStatement implements SlangNode {
4545
print: PrintFunction
4646
): Doc {
4747
const groupId = Symbol('Slang.VariableDeclarationStatement.variables');
48-
const declarationDoc = group(
49-
[this.varKeyword ? 'var (' : '(', path.call(print, 'elements'), ')'],
50-
{ id: groupId }
51-
);
52-
5348
return [
54-
declarationDoc,
49+
group(
50+
[this.varKeyword ? 'var (' : '(', path.call(print, 'elements'), ')'],
51+
{ id: groupId }
52+
),
5553
indentIfBreak([' = ', path.call(print, 'expression'), ';'], { groupId })
5654
];
5755
}

src/slang-nodes/VariableDeclarationStatement.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,20 @@ export class VariableDeclarationStatement implements SlangNode {
5858
print: PrintFunction
5959
): Doc {
6060
const groupId = Symbol('Slang.VariableDeclarationStatement.variables');
61-
const declarationDoc = group(
62-
[
63-
path.call(print, 'variableType'),
64-
indent([
65-
this.storageLocation
66-
? [line, path.call(print, 'storageLocation')]
67-
: '',
68-
' ',
69-
path.call(print, 'name')
70-
])
71-
],
72-
{ id: groupId }
73-
);
74-
7561
return [
76-
declarationDoc,
62+
group(
63+
[
64+
path.call(print, 'variableType'),
65+
indent([
66+
this.storageLocation
67+
? [line, path.call(print, 'storageLocation')]
68+
: '',
69+
' ',
70+
path.call(print, 'name')
71+
])
72+
],
73+
{ id: groupId }
74+
),
7775
indentIfBreak(path.call(print, 'value'), { groupId }),
7876
';'
7977
];

0 commit comments

Comments
 (0)