Skip to content

findFirstNodeAbove should check original node #1622

Open
@pilaoda

Description

@pilaoda

export function findFirstNodeAbove<T extends ts.Node>(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined {
let current = node;
while (current.parent) {
if (callback(current.parent)) {
return current.parent;
} else {
current = current.parent;
}
}
}

current may be a Synthesized node and has no parent attribute. This cause isInAsyncFunction return false incorrectly.

a possible fix:

export function findFirstNodeAbove<T extends ts.Node>(node: ts.Node, callback: (n: ts.Node) => n is T): T | undefined {
    let current = ts.getOriginalNode(node);
    while (current.parent) {
        if (callback(current.parent)) {
            return current.parent;
        } else {
            current = ts.getOriginalNode(current.parent);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions