1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
|
4 | const analyze_scope_1 = require("./analyze-scope");
|
5 |
|
6 | const packageJSON = require('../package.json');
|
7 | function validateBoolean(value, fallback = false) {
|
8 | if (typeof value !== 'boolean') {
|
9 | return fallback;
|
10 | }
|
11 | return value;
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 | exports.version = packageJSON.version;
|
17 | exports.Syntax = Object.freeze(typescript_estree_1.AST_NODE_TYPES);
|
18 | function parse(code, options) {
|
19 | return parseForESLint(code, options).ast;
|
20 | }
|
21 | exports.parse = parse;
|
22 | function parseForESLint(code, options) {
|
23 | if (!options || typeof options !== 'object') {
|
24 | options = {};
|
25 | }
|
26 |
|
27 |
|
28 | if (options.sourceType !== 'module' && options.sourceType !== 'script') {
|
29 | options.sourceType = 'script';
|
30 | }
|
31 | if (typeof options.ecmaFeatures !== 'object') {
|
32 | options.ecmaFeatures = {};
|
33 | }
|
34 | const parserOptions = {};
|
35 | Object.assign(parserOptions, options, {
|
36 | useJSXTextNode: validateBoolean(options.useJSXTextNode, true),
|
37 | jsx: validateBoolean(options.ecmaFeatures.jsx),
|
38 | });
|
39 | if (typeof options.filePath === 'string') {
|
40 | const tsx = options.filePath.endsWith('.tsx');
|
41 | if (tsx || options.filePath.endsWith('.ts')) {
|
42 | parserOptions.jsx = tsx;
|
43 | }
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 | const warnOnUnsupportedTypeScriptVersion = validateBoolean(options.warnOnUnsupportedTypeScriptVersion, true);
|
50 | if (!warnOnUnsupportedTypeScriptVersion) {
|
51 | parserOptions.loggerFn = false;
|
52 | }
|
53 | const { ast, services } = typescript_estree_1.parseAndGenerateServices(code, parserOptions);
|
54 | ast.sourceType = options.sourceType;
|
55 | typescript_estree_1.simpleTraverse(ast, {
|
56 | enter(node) {
|
57 | switch (node.type) {
|
58 |
|
59 | case typescript_estree_1.AST_NODE_TYPES.FunctionExpression:
|
60 | if (!node.body) {
|
61 |
|
62 | node.type = `TSEmptyBody${node.type}`;
|
63 | }
|
64 | break;
|
65 |
|
66 | }
|
67 | },
|
68 | });
|
69 | const scopeManager = analyze_scope_1.analyzeScope(ast, options);
|
70 | return { ast, services, scopeManager, visitorKeys: typescript_estree_1.visitorKeys };
|
71 | }
|
72 | exports.parseForESLint = parseForESLint;
|
73 | var typescript_estree_2 = require("@typescript-eslint/typescript-estree");
|
74 | exports.clearCaches = typescript_estree_2.clearCaches;
|
75 |
|
\ | No newline at end of file |