forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
createSourceFile.ts
28 lines (23 loc) · 842 Bytes
/
createSourceFile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import debug from 'debug';
import * as ts from 'typescript';
import type { ParseSettings } from '../parseSettings';
import { isSourceFile } from '../source-files';
import { getScriptKind } from './getScriptKind';
const log = debug('typescript-eslint:typescript-estree:createSourceFile');
function createSourceFile(parseSettings: ParseSettings): ts.SourceFile {
log(
'Getting AST without type information in %s mode for: %s',
parseSettings.jsx ? 'TSX' : 'TS',
parseSettings.filePath,
);
return isSourceFile(parseSettings.code)
? parseSettings.code
: ts.createSourceFile(
parseSettings.filePath,
parseSettings.codeFullText,
ts.ScriptTarget.Latest,
/* setParentNodes */ true,
getScriptKind(parseSettings.filePath, parseSettings.jsx),
);
}
export { createSourceFile };