Skip to content

Commit db83f53

Browse files
committed
Fix parser and removing clamping logic
1 parent d13bd8d commit db83f53

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

internal/parser/parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ func (p *Parser) parseExpectedMatchingBrackets(openKind ast.Kind, closeKind ast.
863863
return
864864
}
865865
if lastError != nil {
866-
related := ast.NewDiagnostic(nil, core.NewTextRange(openPosition, openPosition+1), diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, scanner.TokenToString(openKind), scanner.TokenToString(closeKind))
866+
related := ast.NewDiagnostic(nil, core.NewTextRange(openPosition, openPosition), diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, scanner.TokenToString(openKind), scanner.TokenToString(closeKind))
867867
lastError.AddRelatedInfo(related)
868868
}
869869
}
@@ -2925,7 +2925,7 @@ func (p *Parser) parseImportType() *ast.Node {
29252925
if len(p.diagnostics) != 0 {
29262926
lastDiagnostic := p.diagnostics[len(p.diagnostics)-1]
29272927
if lastDiagnostic.Code() == diagnostics.X_0_expected.Code() {
2928-
related := ast.NewDiagnostic(nil, core.NewTextRange(openBracePosition, openBracePosition+1), diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, "{", "}")
2928+
related := ast.NewDiagnostic(nil, core.NewTextRange(openBracePosition, openBracePosition), diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, "{", "}")
29292929
lastDiagnostic.AddRelatedInfo(related)
29302930
}
29312931
}
@@ -2972,7 +2972,7 @@ func (p *Parser) parseImportAttributes(token ast.Kind, skipKeyword bool) *ast.No
29722972
if len(p.diagnostics) != 0 {
29732973
lastDiagnostic := p.diagnostics[len(p.diagnostics)-1]
29742974
if lastDiagnostic.Code() == diagnostics.X_0_expected.Code() {
2975-
related := ast.NewDiagnostic(nil, core.NewTextRange(openBracePosition, openBracePosition+1), diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, "{", "}")
2975+
related := ast.NewDiagnostic(nil, core.NewTextRange(openBracePosition, openBracePosition), diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, "{", "}")
29762976
lastDiagnostic.AddRelatedInfo(related)
29772977
}
29782978
}

internal/scanner/scanner.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,16 +2442,14 @@ func GetECMALineStarts(sourceFile ast.SourceFileLike) []core.TextPos {
24422442

24432443
func GetECMALineOfPosition(sourceFile ast.SourceFileLike, pos int) int {
24442444
lineMap := GetECMALineStarts(sourceFile)
2445-
return ComputeLineOfPosition(lineMap, max(0, min(pos, len(sourceFile.Text()))))
2445+
return ComputeLineOfPosition(lineMap, pos)
24462446
}
24472447

24482448
func GetECMALineAndCharacterOfPosition(sourceFile ast.SourceFileLike, pos int) (line int, character int) {
24492449
lineMap := GetECMALineStarts(sourceFile)
2450-
text := sourceFile.Text()
2451-
pos = max(0, min(pos, len(text)))
24522450
line = ComputeLineOfPosition(lineMap, pos)
24532451
// !!! TODO: this is suspect; these are rune counts, not UTF-8 _or_ UTF-16 offsets.
2454-
character = utf8.RuneCountInString(text[lineMap[line]:pos])
2452+
character = utf8.RuneCountInString(sourceFile.Text()[lineMap[line]:pos])
24552453
return line, character
24562454
}
24572455

0 commit comments

Comments
 (0)