File tree Expand file tree Collapse file tree 3 files changed +5
-13
lines changed Expand file tree Collapse file tree 3 files changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -2114,14 +2114,14 @@ namespace ts {
2114
2114
return absolute . substring ( 0 , absolute . lastIndexOf ( directorySeparator , wildcardOffset ) ) ;
2115
2115
}
2116
2116
2117
- export function ensureScriptKind ( fileName : string , scriptKind ? : ScriptKind ) : ScriptKind {
2117
+ export function ensureScriptKind ( fileName : string , scriptKind : ScriptKind | undefined ) : ScriptKind {
2118
2118
// Using scriptKind as a condition handles both:
2119
2119
// - 'scriptKind' is unspecified and thus it is `undefined`
2120
2120
// - 'scriptKind' is set and it is `Unknown` (0)
2121
2121
// If the 'scriptKind' is 'undefined' or 'Unknown' then we attempt
2122
2122
// to get the ScriptKind from the file name. If it cannot be resolved
2123
2123
// from the file name then the default 'TS' script kind is returned.
2124
- return ( scriptKind || getScriptKindFromFileName ( fileName ) ) || ScriptKind . TS ;
2124
+ return scriptKind || getScriptKindFromFileName ( fileName ) || ScriptKind . TS ;
2125
2125
}
2126
2126
2127
2127
export function getScriptKindFromFileName ( fileName : string ) : ScriptKind {
Original file line number Diff line number Diff line change @@ -71,8 +71,7 @@ namespace ts.JsTyping {
71
71
// Only infer typings for .js and .jsx files
72
72
fileNames = mapDefined ( fileNames , fileName => {
73
73
const path = normalizePath ( fileName ) ;
74
- const kind = ensureScriptKind ( path , getScriptKindFromFileName ( path ) ) ;
75
- if ( kind === ScriptKind . JS || kind === ScriptKind . JSX ) {
74
+ if ( hasJavaScriptFileExtension ( path ) ) {
76
75
return path ;
77
76
}
78
77
} ) ;
@@ -191,7 +190,7 @@ namespace ts.JsTyping {
191
190
}
192
191
}
193
192
194
- const hasJsxFile = forEach ( fileNames , f => ensureScriptKind ( f , getScriptKindFromFileName ( f ) ) === ScriptKind . JSX ) ;
193
+ const hasJsxFile = some ( fileNames , f => fileExtensionIs ( f , Extension . Jsx ) ) ;
195
194
if ( hasJsxFile ) {
196
195
addInferredTyping ( "react" ) ;
197
196
}
Original file line number Diff line number Diff line change @@ -1310,14 +1310,7 @@ namespace ts {
1310
1310
export function getScriptKind ( fileName : string , host ?: LanguageServiceHost ) : ScriptKind {
1311
1311
// First check to see if the script kind was specified by the host. Chances are the host
1312
1312
// may override the default script kind for the file extension.
1313
- let scriptKind : ScriptKind ;
1314
- if ( host && host . getScriptKind ) {
1315
- scriptKind = host . getScriptKind ( fileName ) ;
1316
- }
1317
- if ( ! scriptKind ) {
1318
- scriptKind = getScriptKindFromFileName ( fileName ) ;
1319
- }
1320
- return ensureScriptKind ( fileName , scriptKind ) ;
1313
+ return ensureScriptKind ( fileName , host && host . getScriptKind && host . getScriptKind ( fileName ) ) ;
1321
1314
}
1322
1315
1323
1316
export function getFirstNonSpaceCharacterPosition ( text : string , position : number ) {
You can’t perform that action at this time.
0 commit comments