Skip to content

Commit

Permalink
scan over template string ranges in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 27, 2022
1 parent e2830ae commit 7a268da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,20 @@ func (s *Source) RangeOfString(loc Loc) Range {
}
}

if quote == '`' {
// Search for the matching quote character
for i := 1; i < len(text); i++ {
c := text[i]
if c == quote {
return Range{Loc: loc, Len: int32(i + 1)}
} else if c == '\\' {
i += 1
} else if c == '$' && i+1 < len(text) && text[i+1] == '{' {
break // Only return the range for no-substitution template literals
}
}
}

return Range{Loc: loc, Len: 0}
}

Expand Down

0 comments on commit 7a268da

Please sign in to comment.