Skip to content

Commit c6460d1

Browse files
authored
fix(3901): handle out-of-bounds pos in skip trivia (#3914)
1 parent 03db8ff commit c6460d1

6 files changed

Lines changed: 34 additions & 0 deletions

File tree

internal/scanner/scanner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,9 @@ func SkipTriviaEx(text string, pos int, options *SkipTriviaOptions) int {
22782278
canConsumeStar := false
22792279
// Keep in sync with couldStartTrivia
22802280
for {
2281+
if pos >= textLen {
2282+
return pos
2283+
}
22812284
ch, size := utf8.DecodeRuneInString(text[pos:])
22822285
switch ch {
22832286
case '\r':
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a.ts(1,3): error TS1109: Expression expected.
2+
3+
4+
==== a.ts (1 errors) ====
5+
do
6+
7+
!!! error TS1109: Expression expected.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [tests/cases/compiler/emitIncompleteDoStatement.ts] ////
2+
3+
//// [a.ts]
4+
do
5+
6+
//// [a.js]
7+
"use strict";
8+
do
9+
;
10+
while ();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [tests/cases/compiler/emitIncompleteDoStatement.ts] ////
2+
3+
=== a.ts ===
4+
5+
do
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [tests/cases/compiler/emitIncompleteDoStatement.ts] ////
2+
3+
=== a.ts ===
4+
do
5+
> : any
6+
> : any
7+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @filename: a.ts
2+
do

0 commit comments

Comments
 (0)