Skip to content

Commit f860d65

Browse files
authored
small refactor (#1496)
1 parent 5144882 commit f860d65

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/slang-nodes/ConditionalExpression.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ export class ConditionalExpression extends SlangNode {
141141
// We can remove parentheses only because we are sure that the
142142
// `condition` must be a single `bool` value.
143143
const operandLoc = this.operand.loc;
144-
for (
145-
let operandSingleExpression = getOperandSingleExpression(this.operand);
146-
operandSingleExpression &&
147-
operandSingleExpression.kind !== NonterminalKind.ConditionalExpression;
148-
operandSingleExpression = getOperandSingleExpression(this.operand)
149-
) {
144+
for (let operandSingleExpression; ; ) {
145+
operandSingleExpression = getOperandSingleExpression(this.operand);
146+
if (
147+
operandSingleExpression === undefined ||
148+
operandSingleExpression.kind === NonterminalKind.ConditionalExpression
149+
)
150+
break;
151+
150152
this.operand = operandSingleExpression;
151153
}
152154
this.operand.loc = operandLoc;

src/slang-nodes/ModifierInvocation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export class ModifierInvocation extends SlangNode {
3535

3636
cleanModifierInvocationArguments(): void {
3737
if (
38-
this.arguments &&
39-
this.arguments.kind === NonterminalKind.PositionalArgumentsDeclaration &&
38+
this.arguments?.kind === NonterminalKind.PositionalArgumentsDeclaration &&
4039
this.arguments.isEmpty
4140
) {
4241
delete this.arguments;

src/slang-printers/print-comments.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { doc, util } from 'prettier';
22
import { printComment } from '../slang-comments/printer.js';
33
import { joinExisting } from '../slang-utils/join-existing.js';
4-
54
import { locEnd } from '../slang-utils/loc.js';
5+
66
import type { AstPath, Doc, ParserOptions } from 'prettier';
77
import type {
88
AstNode,
@@ -21,8 +21,10 @@ export function printComments(
2121
path: AstPath<StrictAstNode>,
2222
options: ParserOptions<AstNode>
2323
): Doc[] {
24-
if (node.comments === undefined) return [];
25-
const lastPrintableIndex = node.comments.findLastIndex(isPrintable);
24+
const lastPrintableIndex = (node.comments ?? []).findLastIndex(isPrintable);
25+
if (lastPrintableIndex === -1) {
26+
return [];
27+
}
2628
return joinExisting(
2729
line,
2830
path.map(({ node: comment }, index) => {

0 commit comments

Comments
 (0)