diff --git a/internal/compiler/parser_test.go b/internal/compiler/parser_test.go index 880dc6834b..ad06ebf025 100644 --- a/internal/compiler/parser_test.go +++ b/internal/compiler/parser_test.go @@ -1,9 +1,15 @@ package compiler import ( + "io/fs" + "os" + "path/filepath" "testing" "github.com/microsoft/typescript-go/internal/core" + "github.com/microsoft/typescript-go/internal/repo" + "github.com/microsoft/typescript-go/internal/tspath" + "gotest.tools/v3/assert" ) func BenchmarkParse(b *testing.B) { @@ -20,3 +26,40 @@ func BenchmarkParse(b *testing.B) { }) } } + +func TestParseTypeScriptSrc(t *testing.T) { + t.Parallel() + + srcDir := filepath.Join(repo.TypeScriptSubmodulePath, "src") + + if _, err := os.Stat(srcDir); os.IsNotExist(err) { + t.Skipf("TypeScript submodule not found at %s", srcDir) + } + + err := filepath.WalkDir(srcDir, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.IsDir() || tspath.TryExtractTSExtension(path) == "" { + return nil + } + + testName, err := filepath.Rel(srcDir, path) + assert.NilError(t, err) + testName = filepath.ToSlash(testName) + + t.Run(testName, func(t *testing.T) { + t.Parallel() + + sourceText, err := os.ReadFile(path) + assert.NilError(t, err) + + sourceFile := ParseSourceFile(path, string(sourceText), core.ScriptTargetESNext) + assert.Equal(t, len(sourceFile.Diagnostics()), 0) + }) + + return nil + }) + assert.NilError(t, err) +}