Skip to content

Commit 7a268da

Browse files
committed
scan over template string ranges in error messages
1 parent e2830ae commit 7a268da

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/logger/logger.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,20 @@ func (s *Source) RangeOfString(loc Loc) Range {
388388
}
389389
}
390390

391+
if quote == '`' {
392+
// Search for the matching quote character
393+
for i := 1; i < len(text); i++ {
394+
c := text[i]
395+
if c == quote {
396+
return Range{Loc: loc, Len: int32(i + 1)}
397+
} else if c == '\\' {
398+
i += 1
399+
} else if c == '$' && i+1 < len(text) && text[i+1] == '{' {
400+
break // Only return the range for no-substitution template literals
401+
}
402+
}
403+
}
404+
391405
return Range{Loc: loc, Len: 0}
392406
}
393407

0 commit comments

Comments
 (0)