Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e7b24c
commit 3292002
Showing
18 changed files
with
125 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
packages/typescript-estree/src/create-program/createProjectProgram.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/typescript-estree/src/create-program/getScriptKind.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import path from 'path'; | ||
import * as ts from 'typescript'; | ||
|
||
function getScriptKind(filePath: string, jsx: boolean): ts.ScriptKind { | ||
const extension = path.extname(filePath).toLowerCase(); | ||
// note - we respect the user's extension when it is known we could override it and force it to match their | ||
// jsx setting, but that could create weird situations where we throw parse errors when TSC doesn't | ||
// https://github.com/microsoft/TypeScript/blob/da00ba67ed1182ad334f7c713b8254fba174aeba/src/compiler/utilities.ts#L6948-L6968 | ||
switch (extension) { | ||
case ts.Extension.Js: | ||
case ts.Extension.Cjs: | ||
case ts.Extension.Mjs: | ||
return ts.ScriptKind.JS; | ||
|
||
case ts.Extension.Jsx: | ||
return ts.ScriptKind.JSX; | ||
|
||
case ts.Extension.Ts: | ||
case ts.Extension.Cts: | ||
case ts.Extension.Mts: | ||
return ts.ScriptKind.TS; | ||
|
||
case ts.Extension.Tsx: | ||
return ts.ScriptKind.TSX; | ||
|
||
case ts.Extension.Json: | ||
return ts.ScriptKind.JSON; | ||
|
||
default: | ||
// unknown extension, force typescript to ignore the file extension, and respect the user's setting | ||
return jsx ? ts.ScriptKind.TSX : ts.ScriptKind.TS; | ||
} | ||
} | ||
|
||
function getLanguageVariant(scriptKind: ts.ScriptKind): ts.LanguageVariant { | ||
// https://github.com/microsoft/TypeScript/blob/d6e483b8dabd8fd37c00954c3f2184bb7f1eb90c/src/compiler/utilities.ts#L6281-L6285 | ||
switch (scriptKind) { | ||
case ts.ScriptKind.TSX: | ||
case ts.ScriptKind.JSX: | ||
case ts.ScriptKind.JS: | ||
case ts.ScriptKind.JSON: | ||
return ts.LanguageVariant.JSX; | ||
|
||
default: | ||
return ts.LanguageVariant.Standard; | ||
} | ||
} | ||
|
||
export { getScriptKind, getLanguageVariant }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.