Skip to content

Commit b3e136e

Browse files
committed
removing unnecessary non-null assertions
1 parent 43831c0 commit b3e136e

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/slang-nodes/FunctionCallExpression.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ export class FunctionCallExpression implements SlangNode {
4545
// If we are at the end of a MemberAccessChain we should indent the
4646
// arguments accordingly.
4747
if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') {
48-
operandDoc = group(operandDoc.contents, {
49-
id: Symbol('FunctionCallExpression.operand')
50-
});
51-
argumentsDoc = indentIfBreak(argumentsDoc, { groupId: operandDoc.id! });
48+
const groupId = Symbol('Slang.FunctionCallExpression.operand');
49+
operandDoc = group(operandDoc.contents, { id: groupId });
50+
argumentsDoc = indentIfBreak(argumentsDoc, { groupId });
5251
// We wrap the expression in a label in case there is an IndexAccess or
5352
// a FunctionCall following this IndexAccess.
5453
return label('MemberAccessChain', [operandDoc, argumentsDoc]);

src/slang-nodes/IndexAccessExpression.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ export class IndexAccessExpression implements SlangNode {
5454
// If we are at the end of a MemberAccessChain we should indent the
5555
// arguments accordingly.
5656
if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') {
57-
operandDoc = group(operandDoc.contents, {
58-
id: Symbol('IndexAccessExpression.operand')
59-
});
57+
const groupId = Symbol('Slang.IndexAccessExpression.operand');
58+
operandDoc = group(operandDoc.contents, { id: groupId });
6059

61-
indexDoc = indentIfBreak(indexDoc, { groupId: operandDoc.id! });
60+
indexDoc = indentIfBreak(indexDoc, { groupId });
6261
// We wrap the expression in a label in case there is an IndexAccess or
6362
// a FunctionCall following this IndexAccess.
6463
return label('MemberAccessChain', [operandDoc, indexDoc]);

src/slang-nodes/StateVariableDefinition.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,17 @@ export class StateVariableDefinition implements SlangNode {
5252
}
5353

5454
print(path: AstPath<StateVariableDefinition>, print: PrintFunction): Doc {
55+
const groupId = Symbol('Slang.StateVariableDefinition.attributes');
5556
const attributesDoc = group(indent(path.call(print, 'attributes')), {
56-
id: Symbol('Slang.StateVariableDefinition.attributes')
57+
id: groupId
5758
});
5859

5960
return [
6061
path.call(print, 'typeName'),
6162
attributesDoc,
6263
' ',
6364
path.call(print, 'name'),
64-
this.value
65-
? indentIfBreak(path.call(print, 'value'), {
66-
groupId: attributesDoc.id!
67-
})
68-
: '',
65+
this.value ? indentIfBreak(path.call(print, 'value'), { groupId }) : '',
6966
';'
7067
];
7168
}

src/slang-nodes/TupleDeconstructionStatement.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ export class TupleDeconstructionStatement implements SlangNode {
4444
path: AstPath<TupleDeconstructionStatement>,
4545
print: PrintFunction
4646
): Doc {
47+
const groupId = Symbol('Slang.VariableDeclarationStatement.variables');
4748
const declarationDoc = group(
4849
[this.varKeyword ? 'var (' : '(', path.call(print, 'elements'), ')'],
49-
{ id: Symbol('Slang.VariableDeclarationStatement.variables') }
50+
{ id: groupId }
5051
);
5152

5253
return [
5354
declarationDoc,
54-
indentIfBreak([' = ', path.call(print, 'expression'), ';'], {
55-
groupId: declarationDoc.id!
56-
})
55+
indentIfBreak([' = ', path.call(print, 'expression'), ';'], { groupId })
5756
];
5857
}
5958
}

src/slang-nodes/VariableDeclarationStatement.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class VariableDeclarationStatement implements SlangNode {
5757
path: AstPath<VariableDeclarationStatement>,
5858
print: PrintFunction
5959
): Doc {
60+
const groupId = Symbol('Slang.VariableDeclarationStatement.variables');
6061
const declarationDoc = group(
6162
[
6263
path.call(print, 'variableType'),
@@ -68,12 +69,12 @@ export class VariableDeclarationStatement implements SlangNode {
6869
path.call(print, 'name')
6970
])
7071
],
71-
{ id: Symbol('Slang.VariableDeclarationStatement.variables') }
72+
{ id: groupId }
7273
);
7374

7475
return [
7576
declarationDoc,
76-
indentIfBreak(path.call(print, 'value'), { groupId: declarationDoc.id! }),
77+
indentIfBreak(path.call(print, 'value'), { groupId }),
7778
';'
7879
];
7980
}

0 commit comments

Comments
 (0)