Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
synthesize positions when splitting import paths; fixes #55
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <denis.smirnov.91@gmail.com>
  • Loading branch information
dennwc committed Oct 17, 2019
1 parent 9d76380 commit fde3c79
Show file tree
Hide file tree
Showing 10 changed files with 2,566 additions and 1 deletion.
27 changes: 26 additions & 1 deletion driver/normalizer/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,34 @@ func (op pathSplit) Check(st *State, n nodes.Node) (bool, error) {
if err := uast.NodeAs(obj, &path); err != nil {
return false, err
}
var spos uast.Position
if p := path.Positions.Start(); p != nil {
// make a copy
spos = *p
// the position is from a string, so we should exclude "
// when reconstructing positions for identifiers in the import path
spos.Offset++
spos.Col++
}
var idents []uast.Identifier
for _, name := range strings.Split(path.Value, "/") {
idents = append(idents, uast.Identifier{Name: name})
id := uast.Identifier{Name: name}
if spos.Valid() {
p := spos
// reconstruct the position
pe := p
pe.Offset += uint32(len(name))
pe.Col += uint32(len(name))
id.Positions = uast.Positions{
uast.KeyStart: p,
uast.KeyEnd: pe,
}
// skip "/"
pe.Offset++
pe.Col++
spos = pe
}
idents = append(idents, id)
}
var out interface{}
if len(idents) == 1 {
Expand Down
Loading

0 comments on commit fde3c79

Please sign in to comment.