-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.ts
42 lines (35 loc) · 1.36 KB
/
index.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { ESLintExtendedProgram } from "..";
import type { NormalizedParserOptions } from "../parser-options";
import { parseScript, parseScriptInSvelte } from "../script";
import type { AnalyzeTypeScriptContext } from "./analyze";
import { analyzeTypeScript, analyzeTypeScriptInSvelte } from "./analyze";
import { setParent } from "./set-parent";
import type { TSESParseForESLintResult } from "./types";
/**
* Parse for TypeScript in <script>
*/
export function parseTypeScriptInSvelte(
code: { script: string; render: string },
attrs: Record<string, string | undefined>,
parserOptions: NormalizedParserOptions,
context: AnalyzeTypeScriptContext,
): ESLintExtendedProgram {
const tsCtx = analyzeTypeScriptInSvelte(code, attrs, parserOptions, context);
const result = parseScriptInSvelte(tsCtx.script, attrs, parserOptions);
tsCtx.restoreContext.restore(result as unknown as TSESParseForESLintResult);
return result;
}
/**
* Parse for TypeScript
*/
export function parseTypeScript(
code: string,
attrs: Record<string, string | undefined>,
parserOptions: NormalizedParserOptions,
): ESLintExtendedProgram {
const tsCtx = analyzeTypeScript(code, attrs, parserOptions);
const result = parseScript(tsCtx.script, attrs, parserOptions);
setParent(result);
tsCtx.restoreContext.restore(result as unknown as TSESParseForESLintResult);
return result;
}