diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ff32f48e65e..001401a8a96 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2094,4 +2094,33 @@ namespace ts { // pos === undefined || pos === null || isNaN(pos) || pos < 0; return !(pos >= 0); } + + /** True if an extension is one of the supported TypeScript extensions. */ + export function extensionIsTypeScript(ext: Extension): boolean { + return ext <= Extension.LastTypeScriptExtension; + } + + /** + * Gets the extension from a path. + * Path must have a valid extension. + */ + export function extensionFromPath(path: string): Extension { + if (fileExtensionIs(path, ".d.ts")) { + return Extension.Dts; + } + if (fileExtensionIs(path, ".ts")) { + return Extension.Ts; + } + if (fileExtensionIs(path, ".tsx")) { + return Extension.Tsx; + } + if (fileExtensionIs(path, ".js")) { + return Extension.Js; + } + if (fileExtensionIs(path, ".jsx")) { + return Extension.Jsx; + } + Debug.fail(`File ${path} has unknown extension.`); + return Extension.Js; + } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a29007edc01..5f7c91b3b1c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -118,35 +118,6 @@ namespace ts { oldResolution.resolvedFileName === newResolution.resolvedFileName; } - /** True if an extension is one of the supported TypeScript extensions. */ - export function extensionIsTypeScript(ext: Extension): boolean { - return ext <= Extension.LastTypeScriptExtension; - } - - /** - * Gets the extension from a path. - * Path must have a valid extension. - */ - export function extensionFromPath(path: string): Extension { - if (fileExtensionIs(path, ".d.ts")) { - return Extension.Dts; - } - if (fileExtensionIs(path, ".ts")) { - return Extension.Ts; - } - if (fileExtensionIs(path, ".tsx")) { - return Extension.Tsx; - } - if (fileExtensionIs(path, ".js")) { - return Extension.Js; - } - if (fileExtensionIs(path, ".jsx")) { - return Extension.Jsx; - } - Debug.fail(`File ${path} has unknown extension.`); - return Extension.Js; - } - /* @internal */ export function typeDirectiveIsEqualTo(oldResolution: ResolvedTypeReferenceDirective, newResolution: ResolvedTypeReferenceDirective): boolean { return oldResolution.resolvedFileName === newResolution.resolvedFileName && oldResolution.primary === newResolution.primary;