MCPcopy Create free account
hub / github.com/microsoft/typescript-go / loadSourceFileMetaData

Method loadSourceFileMetaData

internal/compiler/fileloader.go:341–362  ·  view source on GitHub ↗
(fileName string)

Source from the content-addressed store, hash-verified

339}
340
341func (p *fileLoader) loadSourceFileMetaData(fileName string) ast.SourceFileMetaData {
342 packageJsonScope := p.resolver.GetPackageScopeForPath(tspath.GetDirectoryPath(fileName))
343 moduleResolutionKind := p.opts.Config.CompilerOptions().GetModuleResolutionKind()
344
345 var packageJsonType, packageJsonDirectory string
346 if packageJsonScope.Exists() {
347 packageJsonDirectory = packageJsonScope.PackageDirectory
348 if value, ok := packageJsonScope.Contents.Type.GetValue(); ok {
349 if !tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMts, tspath.ExtensionCts, tspath.ExtensionMjs, tspath.ExtensionCjs}) &&
350 core.ModuleResolutionKindNode16 <= moduleResolutionKind && moduleResolutionKind <= core.ModuleResolutionKindNodeNext || strings.Contains(fileName, "/node_modules/") {
351 packageJsonType = value
352 }
353 }
354 }
355
356 impliedNodeFormat := ast.GetImpliedNodeFormatForFile(fileName, packageJsonType)
357 return ast.SourceFileMetaData{
358 PackageJsonType: packageJsonType,
359 PackageJsonDirectory: packageJsonDirectory,
360 ImpliedNodeFormat: impliedNodeFormat,
361 }
362}
363
364func (p *fileLoader) parseSourceFile(t *parseTask) *ast.SourceFile {
365 if p.opts.Tracing != nil {

Callers 1

loadMethod · 0.80

Calls 9

GetDirectoryPathFunction · 0.92
FileExtensionIsOneOfFunction · 0.92
GetValueMethod · 0.80
CompilerOptionsMethod · 0.65
ContainsMethod · 0.65
ExistsMethod · 0.45

Tested by

no test coverage detected