typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

feat: move nil check to call sites

Open SoulPancake opened this issue 9 months ago • 5 comments

This addresses

// TODO(rbuckton): Move node != niltest to call sites @rbuckton Can you please review this I can undo the stylistic whitespace changes in the internal/ast/utilities.g but I think they're for the better, LMK what you think

SoulPancake avatar Mar 18 '25 07:03 SoulPancake

@rbuckton Can you take a look at this?

SoulPancake avatar Apr 25 '25 05:04 SoulPancake

@SoulPancake Sorry for jumping on here for a slightly tangential issue, but I noticed that nil checks are inconsistent throughout the codebase. For example,

https://github.com/microsoft/typescript-go/blob/main/internal%2Fast%2Fast.go#L15-L31

type Visitor func(*Node) bool

func visit(v Visitor, node *Node) bool {
        if node != nil {
                return v(node)
        }
        return false
}

func visitNodes(v Visitor, nodes []*Node) bool {
        for _, node := range nodes {
                if v(node) {
                        return true
                }
        }
        return false
}

visit checks for nils, but the for loop doesn't check if node is nil. Do you have clear documentation on whether Visitors are supposed to handle nils? Because visit assumes they don't, and visitNodes assumes they do, which are mutually incompatible assumptions.

SaadiSave avatar May 07 '25 01:05 SaadiSave

@SaadiSave Agreed, I will add the nil check in the loop

SoulPancake avatar May 08 '25 06:05 SoulPancake

@SoulPancake is there a lint to enforce nil checks?

SaadiSave avatar May 08 '25 13:05 SaadiSave

Don't think so @SaadiSave

SoulPancake avatar May 20 '25 10:05 SoulPancake

This PR has gotten out of date as main changed. Could you update it, or close it if you don't plan on working on this anymore?

jakebailey avatar Jun 24 '25 23:06 jakebailey

I will update it asap @jakebailey

SoulPancake avatar Jun 25 '25 03:06 SoulPancake

@jakebailey Done, Can you take a look at this?

SoulPancake avatar Jun 25 '25 05:06 SoulPancake

I feel like most of these are redundant; I would think we'd only want ones that correspond to undefined checks in the original code.

jakebailey avatar Jun 27 '25 06:06 jakebailey

@jakebailey I guess these aren't needed or helpful as you mentioned, do you suggest I remove the TODO comments and remove the changes?

SoulPancake avatar Aug 18 '25 10:08 SoulPancake

Otherwise I am happy to close this PR @jakebailey

SoulPancake avatar Aug 18 '25 10:08 SoulPancake