.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / parser / dist / parser.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.parseForESLint = exports.parse = void 0;
4 const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
5 const analyze_scope_1 = require("./analyze-scope");
6 function validateBoolean(value, fallback = false) {
7     if (typeof value !== 'boolean') {
8         return fallback;
9     }
10     return value;
11 }
12 function parse(code, options) {
13     return parseForESLint(code, options).ast;
14 }
15 exports.parse = parse;
16 function parseForESLint(code, options) {
17     if (!options || typeof options !== 'object') {
18         options = {};
19     }
20     // https://eslint.org/docs/user-guide/configuring#specifying-parser-options
21     // if sourceType is not provided by default eslint expect that it will be set to "script"
22     if (options.sourceType !== 'module' && options.sourceType !== 'script') {
23         options.sourceType = 'script';
24     }
25     if (typeof options.ecmaFeatures !== 'object') {
26         options.ecmaFeatures = {};
27     }
28     const parserOptions = {};
29     Object.assign(parserOptions, options, {
30         useJSXTextNode: validateBoolean(options.useJSXTextNode, true),
31         jsx: validateBoolean(options.ecmaFeatures.jsx),
32     });
33     if (typeof options.filePath === 'string') {
34         const tsx = options.filePath.endsWith('.tsx');
35         if (tsx || options.filePath.endsWith('.ts')) {
36             parserOptions.jsx = tsx;
37         }
38     }
39     /**
40      * Allow the user to suppress the warning from typescript-estree if they are using an unsupported
41      * version of TypeScript
42      */
43     const warnOnUnsupportedTypeScriptVersion = validateBoolean(options.warnOnUnsupportedTypeScriptVersion, true);
44     if (!warnOnUnsupportedTypeScriptVersion) {
45         parserOptions.loggerFn = false;
46     }
47     const { ast, services } = typescript_estree_1.parseAndGenerateServices(code, parserOptions);
48     ast.sourceType = options.sourceType;
49     const scopeManager = analyze_scope_1.analyzeScope(ast, options);
50     return { ast, services, scopeManager, visitorKeys: typescript_estree_1.visitorKeys };
51 }
52 exports.parseForESLint = parseForESLint;
53 //# sourceMappingURL=parser.js.map