From 234e2db2e61fd4bd74f934a2de641401f05ed054 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 30 Aug 2025 20:00:30 +0200 Subject: [PATCH] removing all `typeof x === 'undefined'` in favour of `x === undefined` --- src/index.ts | 2 +- src/slang-nodes/ContractSpecifiers.ts | 4 ++-- src/slang-nodes/SlangNode.ts | 4 ++-- src/slang-printers/print-comments.ts | 2 +- src/slang-utils/loc.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index e42f9c9a8..9c5dd15dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,7 +55,7 @@ const antlrCanAttachComment = ({ type }: { type: string }): boolean => typeof type === 'string' && type !== 'BlockComment' && type !== 'LineComment'; const canAttachComment = (node: AstNode): boolean => typeof node !== 'string' && - typeof node !== 'undefined' && + node !== undefined && node.kind && // Make sure it's not Location !isComment(node); diff --git a/src/slang-nodes/ContractSpecifiers.ts b/src/slang-nodes/ContractSpecifiers.ts index 94bc74d58..116ce672d 100644 --- a/src/slang-nodes/ContractSpecifiers.ts +++ b/src/slang-nodes/ContractSpecifiers.ts @@ -28,9 +28,9 @@ export class ContractSpecifiers extends SlangNode { print(path: AstPath, print: PrintFunction): Doc { const [specifier1, specifier2] = path.map(print, 'items'); - if (typeof specifier1 === 'undefined') return ''; + if (specifier1 === undefined) return ''; - if (typeof specifier2 === 'undefined') return [' ', specifier1]; + if (specifier2 === undefined) return [' ', specifier1]; const groupId = Symbol('Slang.ContractSpecifiers.inheritance'); return printSeparatedList( diff --git a/src/slang-nodes/SlangNode.ts b/src/slang-nodes/SlangNode.ts index 1c581abd4..e0adb83a6 100644 --- a/src/slang-nodes/SlangNode.ts +++ b/src/slang-nodes/SlangNode.ts @@ -126,7 +126,7 @@ export class SlangNode { // calculate correct loc object if (loc.leadingOffset === 0) { for (const childNode of childNodes) { - if (typeof childNode === 'undefined') continue; + if (childNode === undefined) continue; const { leadingOffset, start } = childNode.loc; if (start - leadingOffset === loc.start) { @@ -139,7 +139,7 @@ export class SlangNode { if (loc.trailingOffset === 0) { for (const childNode of reversedIterator(childNodes)) { - if (typeof childNode === 'undefined') continue; + if (childNode === undefined) continue; const { trailingOffset, end } = childNode.loc; if (end + trailingOffset === loc.end) { diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index 1b07f187a..0fc905dc1 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -20,7 +20,7 @@ export function printComments( path: AstPath, options: ParserOptions ): Doc[] { - if (typeof path.node.comments === 'undefined') return []; + if (path.node.comments === undefined) return []; return joinExisting( line, path.map((commentPath, index, comments: Comment[]) => { diff --git a/src/slang-utils/loc.ts b/src/slang-utils/loc.ts index a0ea0e5ec..308341ea6 100644 --- a/src/slang-utils/loc.ts +++ b/src/slang-utils/loc.ts @@ -1,11 +1,11 @@ import type { AstNode } from '../slang-nodes/types.d.ts'; export function locStart(node: AstNode): number { - if (typeof node === 'string' || typeof node === 'undefined') return -1; + if (typeof node === 'string' || node === undefined) return -1; return node.loc.start; } export function locEnd(node: AstNode): number { - if (typeof node === 'string' || typeof node === 'undefined') return -1; + if (typeof node === 'string' || node === undefined) return -1; return node.loc.end; }