Skip to content

Error in ts.findAncestor caused by ASIΒ #61905

Closed
@tzengshinfu

Description

@tzengshinfu

πŸ”Ž Search Terms

semicolon findAncestor
asi findAncestor

πŸ•— Version & Regression Information

5.8.3

⏯ Playground Link

No response

πŸ’» Code

// Reference to the VSCode extension
import * as ts from 'typescript'

// The target JS code to analyze
const a = 1
const b = 2
const c = 3
(a + b) - c
//        β–²
//        β”‚
//      node: ts.Node

// Get the parent binary expression
ts.findAncestor(node, ts.isBinaryExpression).getFullText()

πŸ™ Actual behavior

It shouldn't include 3.
β”‚
β–Ό
' 3
(a + b) - c'

πŸ™‚ Expected behavior

'
(a + b) - c'

Additional information about the issue

I'm planning to develop a VSCode extension, and one of its features involves parsing the AST of JavaScript code.
Most of the target JavaScript code uses ASI (Automatic Semicolon Insertion), which causes unexpected behavior when calling ts.findAncestor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions