From 9db35b6d9683aa0ee612ce3e079c5560bce6acf8 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:36:09 -0800 Subject: [PATCH 1/3] Add test that verifies all of TS parses --- internal/compiler/parser_test.go | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/internal/compiler/parser_test.go b/internal/compiler/parser_test.go index 880dc6834b..6bb4900cda 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") + + err := filepath.WalkDir(srcDir, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.IsDir() { + return nil + } + + if ext := tspath.TryExtractTSExtension(path); ext == "" { + 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) +} From 9289724cc04cbfa2c6014e1ed4c527cd6429d7ae Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:49:09 -0800 Subject: [PATCH 2/3] Skip --- internal/compiler/parser_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/compiler/parser_test.go b/internal/compiler/parser_test.go index 6bb4900cda..16f78cd0d9 100644 --- a/internal/compiler/parser_test.go +++ b/internal/compiler/parser_test.go @@ -32,6 +32,10 @@ func TestParseTypeScriptSrc(t *testing.T) { 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 From 53fc873ae0522bd559a8ec898d1095db9afcf69d Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:51:55 -0800 Subject: [PATCH 3/3] Simplify --- internal/compiler/parser_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/compiler/parser_test.go b/internal/compiler/parser_test.go index 16f78cd0d9..ad06ebf025 100644 --- a/internal/compiler/parser_test.go +++ b/internal/compiler/parser_test.go @@ -41,11 +41,7 @@ func TestParseTypeScriptSrc(t *testing.T) { return err } - if d.IsDir() { - return nil - } - - if ext := tspath.TryExtractTSExtension(path); ext == "" { + if d.IsDir() || tspath.TryExtractTSExtension(path) == "" { return nil }