Skip to content

Commit 67aaff4

Browse files
committed
miscelaneous: some correctness in the use or || operator
1 parent 9c1f96a commit 67aaff4

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/slang-comments/handlers/handle-else-branch-comments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function handleElseBranchComments({
1111
followingNode,
1212
comment
1313
}: HandlerParams): boolean {
14-
if (enclosingNode?.kind !== NonterminalKind.ElseBranch || !followingNode) {
14+
if (enclosingNode?.kind !== NonterminalKind.ElseBranch) {
1515
return false;
1616
}
1717

src/slang-comments/handlers/handle-if-statement-comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function handleIfStatementComments({
1414
followingNode,
1515
comment
1616
}: HandlerParams): boolean {
17-
if (enclosingNode?.kind !== NonterminalKind.IfStatement || !followingNode) {
17+
if (enclosingNode?.kind !== NonterminalKind.IfStatement) {
1818
return false;
1919
}
2020

@@ -43,7 +43,7 @@ export default function handleIfStatementComments({
4343
return true;
4444
}
4545

46-
if (followingNode.kind === NonterminalKind.IfStatement) {
46+
if (followingNode?.kind === NonterminalKind.IfStatement) {
4747
if (followingNode.body.kind === NonterminalKind.Block) {
4848
addCollectionFirstComment(followingNode.body.statements, comment);
4949
} else {

src/slang-comments/handlers/handle-while-statement-comments.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ export default function handleWhileStatementComments({
1414
followingNode,
1515
comment
1616
}: HandlerParams): boolean {
17-
if (
18-
enclosingNode?.kind !== NonterminalKind.WhileStatement ||
19-
!followingNode
20-
) {
17+
if (enclosingNode?.kind !== NonterminalKind.WhileStatement) {
2118
return false;
2219
}
2320

src/slang-nodes/SlangNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export abstract class SlangNode {
4444
enclosePeripheralComments = false
4545
) {
4646
if (ast instanceof SlangTerminalNode) {
47-
const start = collected.offsets.get(ast.id) || 0;
47+
const start = collected.offsets.get(ast.id) ?? 0;
4848
const end = start + ast.textLength.utf16;
4949
this.loc = {
5050
outerStart: start,
@@ -56,7 +56,7 @@ export abstract class SlangNode {
5656
}
5757
const cst = ast.cst;
5858

59-
const initialOffset = collected.offsets.get(cst.id) || 0;
59+
const initialOffset = collected.offsets.get(cst.id) ?? 0;
6060
let offset = initialOffset;
6161
let triviaLength = 0;
6262
let leadingOffset;

0 commit comments

Comments
 (0)