diff --git a/tsc/internal/api/encoder/encoder_test.go b/tsc/internal/api/encoder/encoder_test.go index 2652a44212051..4f8b72a037953 100644 --- a/tsc/internal/api/encoder/encoder_test.go +++ b/tsc/internal/api/encoder/encoder_test.go @@ -215,3 +215,15 @@ func formatEncodedSourceFile(encoded []byte) string { } return result.String() } + +func TestEncodeSourceFileWithNormalizedNumericLiterals(t *testing.T) { + t.Parallel() + for _, text := range []string{".1", "1e3", "1e9", "1e2", "1", "0"} { + sourceFile := parser.ParseSourceFile(ast.SourceFileParseOptions{ + FileName: "/test.ts", + PathKey: "/test.ts", + }, text, core.ScriptKindTS) + _, _, err := encoder.EncodeSourceFile(sourceFile) + assert.NilError(t, err, "text %q", text) + } +} diff --git a/tsc/internal/api/encoder/stringtable.go b/tsc/internal/api/encoder/stringtable.go index 46cd674f32444..e0e047862f502 100644 --- a/tsc/internal/api/encoder/stringtable.go +++ b/tsc/internal/api/encoder/stringtable.go @@ -38,10 +38,12 @@ func (t *stringTable) add(text string, kind ast.Kind, pos int, end int) uint32 { } end = end - endOffset start := end - length - fileSlice := t.fileText[start:end] - if fileSlice == text { - t.offsets = append(t.offsets, uint32(start), uint32(end)) - return index + if start >= 0 { + fileSlice := t.fileText[start:end] + if fileSlice == text { + t.offsets = append(t.offsets, uint32(start), uint32(end)) + return index + } } } // no exact match, so we need to add it to the string table