Skip to content

Review ported code from formatter #2450

@DanielRosenwasser

Description

@DanielRosenwasser

Original code:

const parent = findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)?.parent || previousParent!;

https://github.com/microsoft/TypeScript/blob/9d364978d3e8e4de01bb2bec8083b58c1f710232/src/services/formatting/formatting.ts#L567

New code:

parent := astnav.FindPrecedingToken(w.sourceFile, tokenInfo.Loc.End())
if parent == nil {
	parent = w.previousParent
}

parent := astnav.FindPrecedingToken(w.sourceFile, tokenInfo.Loc.End())
if parent == nil {
parent = w.previousParent
}

Looks like we at least need something like

- parent := astnav.FindPrecedingToken(w.sourceFile, tokenInfo.Loc.End())
+ var parent *ast.Node
+ prevToken := astnav.FindPrecedingToken(w.sourceFile, tokenInfo.Loc.End())
+ if prevToken != nil {
+ 	parent = prevToken.Parent
+ }
  if parent == nil {
  	parent = w.previousParent
  }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions