@@ -2131,13 +2131,13 @@ namespace ts {
21312131 export function getScriptKindFromFileName ( fileName : string ) : ScriptKind {
21322132 const ext = fileName . substr ( fileName . lastIndexOf ( "." ) ) ;
21332133 switch ( ext . toLowerCase ( ) ) {
2134- case ".js" :
2134+ case Extension . Js :
21352135 return ScriptKind . JS ;
2136- case ".jsx" :
2136+ case Extension . Jsx :
21372137 return ScriptKind . JSX ;
2138- case ".ts" :
2138+ case Extension . Ts :
21392139 return ScriptKind . TS ;
2140- case ".tsx" :
2140+ case Extension . Tsx :
21412141 return ScriptKind . TSX ;
21422142 default :
21432143 return ScriptKind . Unknown ;
@@ -2147,18 +2147,18 @@ namespace ts {
21472147 /**
21482148 * List of supported extensions in order of file resolution precedence.
21492149 */
2150- export const supportedTypeScriptExtensions = [ ".ts" , ".tsx" , ".d.ts" ] ;
2150+ export const supportedTypeScriptExtensions = [ Extension . Ts , Extension . Tsx , Extension . Dts ] ;
21512151 /** Must have ".d.ts" first because if ".ts" goes first, that will be detected as the extension instead of ".d.ts". */
2152- export const supportedTypescriptExtensionsForExtractExtension = [ ".d.ts" , ".ts" , ".tsx" ] ;
2153- export const supportedJavascriptExtensions = [ ".js" , ".jsx" ] ;
2152+ export const supportedTypescriptExtensionsForExtractExtension = [ Extension . Dts , Extension . Ts , Extension . Tsx ] ;
2153+ export const supportedJavascriptExtensions = [ Extension . Js , Extension . Jsx ] ;
21542154 const allSupportedExtensions = supportedTypeScriptExtensions . concat ( supportedJavascriptExtensions ) ;
21552155
21562156 export function getSupportedExtensions ( options ?: CompilerOptions , extraFileExtensions ?: JsFileExtensionInfo [ ] ) : string [ ] {
21572157 const needAllExtensions = options && options . allowJs ;
21582158 if ( ! extraFileExtensions || extraFileExtensions . length === 0 || ! needAllExtensions ) {
21592159 return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions ;
21602160 }
2161- const extensions = allSupportedExtensions . slice ( 0 ) ;
2161+ const extensions : string [ ] = allSupportedExtensions . slice ( 0 ) ;
21622162 for ( const extInfo of extraFileExtensions ) {
21632163 if ( extensions . indexOf ( extInfo . extension ) === - 1 ) {
21642164 extensions . push ( extInfo . extension ) ;
@@ -2237,7 +2237,7 @@ namespace ts {
22372237 }
22382238 }
22392239
2240- const extensionsToRemove = [ ".d.ts" , ".ts" , ".js" , ".tsx" , ".jsx" ] ;
2240+ const extensionsToRemove = [ Extension . Dts , Extension . Ts , Extension . Js , Extension . Tsx , Extension . Jsx ] ;
22412241 export function removeFileExtension ( path : string ) : string {
22422242 for ( const ext of extensionsToRemove ) {
22432243 const extensionless = tryRemoveExtension ( path , ext ) ;
@@ -2491,7 +2491,7 @@ namespace ts {
24912491
24922492 /** True if an extension is one of the supported TypeScript extensions. */
24932493 export function extensionIsTypeScript ( ext : Extension ) : boolean {
2494- return ext <= Extension . LastTypeScriptExtension ;
2494+ return ext === Extension . Ts || ext === Extension . Tsx || ext === Extension . Dts ;
24952495 }
24962496
24972497 /**
@@ -2506,21 +2506,7 @@ namespace ts {
25062506 Debug . fail ( `File ${ path } has unknown extension.` ) ;
25072507 }
25082508 export function tryGetExtensionFromPath ( path : string ) : Extension | undefined {
2509- if ( fileExtensionIs ( path , ".d.ts" ) ) {
2510- return Extension . Dts ;
2511- }
2512- if ( fileExtensionIs ( path , ".ts" ) ) {
2513- return Extension . Ts ;
2514- }
2515- if ( fileExtensionIs ( path , ".tsx" ) ) {
2516- return Extension . Tsx ;
2517- }
2518- if ( fileExtensionIs ( path , ".js" ) ) {
2519- return Extension . Js ;
2520- }
2521- if ( fileExtensionIs ( path , ".jsx" ) ) {
2522- return Extension . Jsx ;
2523- }
2509+ return find ( supportedTypescriptExtensionsForExtractExtension , e => fileExtensionIs ( path , e ) ) || find ( supportedJavascriptExtensions , e => fileExtensionIs ( path , e ) ) ;
25242510 }
25252511
25262512 export function isCheckJsEnabledForFile ( sourceFile : SourceFile , compilerOptions : CompilerOptions ) {
0 commit comments