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

Function TryGetJSExtensionForFile

internal/module/util.go:178–197  ·  view source on GitHub ↗

TryGetJSExtensionForFile maps TS/JS/DTS extensions to the output JS-side extension. Returns an empty string if the extension is unsupported.

(fileName string, options *core.CompilerOptions)

Source from the content-addressed store, hash-verified

176// TryGetJSExtensionForFile maps TS/JS/DTS extensions to the output JS-side extension.
177// Returns an empty string if the extension is unsupported.
178func TryGetJSExtensionForFile(fileName string, options *core.CompilerOptions) string {
179 ext := tspath.TryGetExtensionFromPath(fileName)
180 switch ext {
181 case tspath.ExtensionTs, tspath.ExtensionDts:
182 return tspath.ExtensionJs
183 case tspath.ExtensionTsx:
184 if options.Jsx == core.JsxEmitPreserve {
185 return tspath.ExtensionJsx
186 }
187 return tspath.ExtensionJs
188 case tspath.ExtensionJs, tspath.ExtensionJsx, tspath.ExtensionJson:
189 return ext
190 case tspath.ExtensionDmts, tspath.ExtensionMts, tspath.ExtensionMjs:
191 return tspath.ExtensionMjs
192 case tspath.ExtensionDcts, tspath.ExtensionCts, tspath.ExtensionCjs:
193 return tspath.ExtensionCjs
194 default:
195 return ""
196 }
197}

Calls 1

TryGetExtensionFromPathFunction · 0.92

Tested by

no test coverage detected