Skip to content

Commit 7f0bff9

Browse files
authored
fileloader skips files w/unsupported extensions (microsoft#437)
1 parent a3ecec2 commit 7f0bff9

File tree

58 files changed

+453
-2405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+453
-2405
lines changed

internal/compiler/fileloader.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type fileLoader struct {
3030
defaultLibraryPath string
3131
comparePathsOptions tspath.ComparePathsOptions
3232
rootTasks []*parseTask
33+
supportedExtensions []string
3334
}
3435

3536
func processAllProgramFiles(
@@ -40,6 +41,7 @@ func processAllProgramFiles(
4041
rootFiles []string,
4142
libs []string,
4243
) (files []*ast.SourceFile, resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]) {
44+
supportedExtensions := tsoptions.GetSupportedExtensions(compilerOptions, nil /*extraFileExtensions*/)
4345
loader := fileLoader{
4446
host: host,
4547
programOptions: programOptions,
@@ -51,8 +53,9 @@ func processAllProgramFiles(
5153
UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(),
5254
CurrentDirectory: host.GetCurrentDirectory(),
5355
},
54-
wg: core.NewWorkGroup(programOptions.SingleThreaded),
55-
rootTasks: make([]*parseTask, 0, len(rootFiles)+len(libs)),
56+
wg: core.NewWorkGroup(programOptions.SingleThreaded),
57+
rootTasks: make([]*parseTask, 0, len(rootFiles)+len(libs)),
58+
supportedExtensions: core.Flatten(tsoptions.GetSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, supportedExtensions)),
5659
}
5760

5861
loader.addRootTasks(rootFiles, false)
@@ -79,7 +82,9 @@ func processAllProgramFiles(
7982
func (p *fileLoader) addRootTasks(files []string, isLib bool) {
8083
for _, fileName := range files {
8184
absPath := tspath.GetNormalizedAbsolutePath(fileName, p.host.GetCurrentDirectory())
82-
p.rootTasks = append(p.rootTasks, &parseTask{normalizedFilePath: absPath, isLib: isLib})
85+
if core.Tristate.IsTrue(p.compilerOptions.AllowNonTsExtensions) || slices.Contains(p.supportedExtensions, tspath.TryGetExtensionFromPath(absPath)) {
86+
p.rootTasks = append(p.rootTasks, &parseTask{normalizedFilePath: absPath, isLib: isLib})
87+
}
8388
}
8489
}
8590

internal/testutil/baseline/baseline.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ func Run(t *testing.T, fileName string, actual string, opts Options) {
4343
}
4444
}
4545
writeComparison(t, diff, diffFileName, false /*useSubmodule*/, opts)
46-
} else {
47-
writeComparison(t, actual, fileName, false /*useSubmodule*/, opts)
4846
}
47+
writeComparison(t, actual, fileName, false /*useSubmodule*/, opts)
4948
}
5049

5150
func getBaselineDiff(t *testing.T, actual string, fileName string) string {
@@ -116,19 +115,23 @@ func writeComparison(t *testing.T, actual string, relativeFileName string, useSu
116115

117116
if _, err := os.Stat(localFileName); err == nil {
118117
if err := os.Remove(localFileName); err != nil {
119-
t.Fatal(fmt.Errorf("failed to remove the local baseline file %s: %w", localFileName, err))
118+
t.Error(fmt.Errorf("failed to remove the local baseline file %s: %w", localFileName, err))
119+
return
120120
}
121121
}
122122
if actual != expected {
123123
if err := os.MkdirAll(filepath.Dir(localFileName), 0o755); err != nil {
124-
t.Fatal(fmt.Errorf("failed to create directories for the local baseline file %s: %w", localFileName, err))
124+
t.Error(fmt.Errorf("failed to create directories for the local baseline file %s: %w", localFileName, err))
125+
return
125126
}
126127
if actual == NoContent {
127128
if err := os.WriteFile(localFileName+".delete", []byte{}, 0o644); err != nil {
128-
t.Fatal(fmt.Errorf("failed to write the local baseline file %s: %w", localFileName+".delete", err))
129+
t.Error(fmt.Errorf("failed to write the local baseline file %s: %w", localFileName+".delete", err))
130+
return
129131
}
130132
} else if err := os.WriteFile(localFileName, []byte(actual), 0o644); err != nil {
131-
t.Fatal(fmt.Errorf("failed to write the local baseline file %s: %w", localFileName, err))
133+
t.Error(fmt.Errorf("failed to write the local baseline file %s: %w", localFileName, err))
134+
return
132135
}
133136

134137
if _, err := os.Stat(referenceFileName); err != nil {

internal/testutil/tsbaseline/type_symbol_baseline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func generateBaseline(
128128
if result.Len() > 0 {
129129
return fmt.Sprintf("//// [%s] ////\r\n\r\n%s%s", header, strings.Join(perfLines, "\n"), result.String())
130130
}
131-
return result.String()
131+
return baseline.NoContent
132132
}
133133

134134
func iterateBaseline(allFiles []*harnessutil.TestFile, fullWalker *typeWriterWalker, isSymbolBaseline bool) []string {

internal/tsoptions/tsconfigparsing.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,8 @@ func getFileNamesFromConfigSpecs(
14511451
validatedExcludeSpecs := configFileSpecs.validatedExcludeSpecs
14521452
// Rather than re-query this for each file and filespec, we query the supported extensions
14531453
// once and store it on the expansion context.
1454-
supportedExtensions := getSupportedExtensions(options, extraFileExtensions)
1455-
supportedExtensionsWithJsonIfResolveJsonModule := getSupportedExtensionsWithJsonIfResolveJsonModule(options, supportedExtensions)
1454+
supportedExtensions := GetSupportedExtensions(options, extraFileExtensions)
1455+
supportedExtensionsWithJsonIfResolveJsonModule := GetSupportedExtensionsWithJsonIfResolveJsonModule(options, supportedExtensions)
14561456
// Literal files are always included verbatim. An "include" or "exclude" specification cannot
14571457
// remove a literal file.
14581458
for _, fileName := range validatedFilesSpec {
@@ -1518,7 +1518,7 @@ func getFileNamesFromConfigSpecs(
15181518
return files
15191519
}
15201520

1521-
func getSupportedExtensions(options *core.CompilerOptions, extraFileExtensions []fileExtensionInfo) [][]string {
1521+
func GetSupportedExtensions(options *core.CompilerOptions, extraFileExtensions []fileExtensionInfo) [][]string {
15221522
needJsExtensions := options.GetAllowJs()
15231523
if len(extraFileExtensions) == 0 {
15241524
if needJsExtensions {
@@ -1544,7 +1544,7 @@ func getSupportedExtensions(options *core.CompilerOptions, extraFileExtensions [
15441544
return extensions
15451545
}
15461546

1547-
func getSupportedExtensionsWithJsonIfResolveJsonModule(options *core.CompilerOptions, supportedExtensions [][]string) [][]string {
1547+
func GetSupportedExtensionsWithJsonIfResolveJsonModule(options *core.CompilerOptions, supportedExtensions [][]string) [][]string {
15481548
if options == nil || !options.GetResolveJsonModule() {
15491549
return supportedExtensions
15501550
}

testdata/baselines/reference/submodule/compiler/checkJsFiles6.symbols

Lines changed: 0 additions & 6 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/checkJsFiles6.symbols.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJs.symbols

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ class c {
55
>c : Symbol(c, Decl(a.ts, 0, 0))
66
}
77

8-
=== b.js.map ===
9-
function foo() {
10-
>foo : Symbol(foo, Decl(b.js.map, 0, 0))
11-
}
12-
138
=== b.js ===
149
function bar() {
1510
>bar : Symbol(bar, Decl(b.js, 0, 0))

testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJs.symbols.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.symbols

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ class c {
55
>c : Symbol(c, Decl(a.ts, 0, 0))
66
}
77

8-
=== b.js.map ===
9-
function foo() {
10-
>foo : Symbol(foo, Decl(b.js.map, 0, 0))
11-
}
12-
138
=== b.js ===
149
function bar() {
1510
>bar : Symbol(bar, Decl(b.js, 0, 0))

testdata/baselines/reference/submodule/compiler/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.symbols.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)