-
Notifications
You must be signed in to change notification settings - Fork 634
Set implied node format during source file creation #637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
66f4788
48873eb
fb0f304
3e7b92c
8bba782
d1f5959
e5645d2
e825898
1f3b470
1a66c19
0112b00
8366e88
d33133b
b81a9d1
406918a
44d6aff
54fc786
0644fd3
8d1f096
344710a
f6fcb49
a1d63f5
3c902b8
08333cf
ba527ba
4f740f1
d1e2b2e
7da5ddc
e2c7a77
3099425
1697b75
d86780d
ac71490
286beed
ed015b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ type fileLoader struct { | |
resolvedModulesMutex sync.Mutex | ||
resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule] | ||
|
||
sourceFileMetaDatasMutex sync.Mutex | ||
sourceFileMetaDatas map[string]*ast.SourceFileMetaData | ||
|
||
mu sync.Mutex | ||
wg core.WorkGroup | ||
tasksByFileName map[string]*parseTask | ||
|
@@ -40,7 +43,7 @@ func processAllProgramFiles( | |
resolver *module.Resolver, | ||
rootFiles []string, | ||
libs []string, | ||
) (files []*ast.SourceFile, resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]) { | ||
) (files []*ast.SourceFile, resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule], sourceFileMetaDatas map[string]*ast.SourceFileMetaData) { | ||
supportedExtensions := tsoptions.GetSupportedExtensions(compilerOptions, nil /*extraFileExtensions*/) | ||
loader := fileLoader{ | ||
host: host, | ||
|
@@ -76,7 +79,7 @@ func processAllProgramFiles( | |
} | ||
loader.sortLibs(libFiles) | ||
|
||
return append(libFiles, files...), loader.resolvedModules | ||
return append(libFiles, files...), loader.resolvedModules, loader.sourceFileMetaDatas | ||
} | ||
|
||
func (p *fileLoader) addRootTasks(files []string, isLib bool) { | ||
|
@@ -221,9 +224,31 @@ func (t *parseTask) start(loader *fileLoader) { | |
}) | ||
} | ||
|
||
func (p *fileLoader) CacheSourceFileMetaData(path string) { | ||
p.sourceFileMetaDatasMutex.Lock() | ||
defer p.sourceFileMetaDatasMutex.Unlock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lock is held for the entire call, so I don't think we're gaining any parallelism here, no? The "fix" would be to only hold the lock for the check at the top, unlock it, then relock it at the bottom (moving the make call down too). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which, also indicates that this should be a RWMutex. |
||
if _, ok := p.sourceFileMetaDatas[path]; ok { | ||
return | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if p.sourceFileMetaDatas == nil { | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
p.sourceFileMetaDatas = make(map[string]*ast.SourceFileMetaData) | ||
} | ||
|
||
packageJsonType := p.resolver.GetPackageJsonTypeIfApplicable(path) | ||
impliedNodeFormat := ast.GetImpliedNodeFormatForFile(path, packageJsonType) | ||
metadata := &ast.SourceFileMetaData{ | ||
PackageJsonType: packageJsonType, | ||
ImpliedNodeFormat: impliedNodeFormat, | ||
} | ||
|
||
p.sourceFileMetaDatas[path] = metadata | ||
} | ||
|
||
func (p *fileLoader) parseSourceFile(fileName string) *ast.SourceFile { | ||
path := tspath.ToPath(fileName, p.host.GetCurrentDirectory(), p.host.FS().UseCaseSensitiveFileNames()) | ||
sourceFile := p.host.GetSourceFile(fileName, path, p.compilerOptions.GetEmitScriptTarget()) | ||
p.CacheSourceFileMetaData(string(path)) | ||
return sourceFile | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.