Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / typescript-estree / dist / semantic-or-syntactic-errors.js
1 "use strict";
2 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3     if (k2 === undefined) k2 = k;
4     Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 }) : (function(o, m, k, k2) {
6     if (k2 === undefined) k2 = k;
7     o[k2] = m[k];
8 }));
9 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10     Object.defineProperty(o, "default", { enumerable: true, value: v });
11 }) : function(o, v) {
12     o["default"] = v;
13 });
14 var __importStar = (this && this.__importStar) || function (mod) {
15     if (mod && mod.__esModule) return mod;
16     var result = {};
17     if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18     __setModuleDefault(result, mod);
19     return result;
20 };
21 Object.defineProperty(exports, "__esModule", { value: true });
22 exports.getFirstSemanticOrSyntacticError = void 0;
23 const ts = __importStar(require("typescript"));
24 /**
25  * By default, diagnostics from the TypeScript compiler contain all errors - regardless of whether
26  * they are related to generic ECMAScript standards, or TypeScript-specific constructs.
27  *
28  * Therefore, we filter out all diagnostics, except for the ones we explicitly want to consider when
29  * the user opts in to throwing errors on semantic issues.
30  */
31 function getFirstSemanticOrSyntacticError(program, ast) {
32     try {
33         const supportedSyntacticDiagnostics = whitelistSupportedDiagnostics(program.getSyntacticDiagnostics(ast));
34         if (supportedSyntacticDiagnostics.length) {
35             return convertDiagnosticToSemanticOrSyntacticError(supportedSyntacticDiagnostics[0]);
36         }
37         const supportedSemanticDiagnostics = whitelistSupportedDiagnostics(program.getSemanticDiagnostics(ast));
38         if (supportedSemanticDiagnostics.length) {
39             return convertDiagnosticToSemanticOrSyntacticError(supportedSemanticDiagnostics[0]);
40         }
41         return undefined;
42     }
43     catch (e) {
44         /**
45          * TypeScript compiler has certain Debug.fail() statements in, which will cause the diagnostics
46          * retrieval above to throw.
47          *
48          * E.g. from ast-alignment-tests
49          * "Debug Failure. Shouldn't ever directly check a JsxOpeningElement"
50          *
51          * For our current use-cases this is undesired behavior, so we just suppress it
52          * and log a a warning.
53          */
54         /* istanbul ignore next */
55         console.warn(`Warning From TSC: "${e.message}`); // eslint-disable-line no-console
56         /* istanbul ignore next */
57         return undefined;
58     }
59 }
60 exports.getFirstSemanticOrSyntacticError = getFirstSemanticOrSyntacticError;
61 function whitelistSupportedDiagnostics(diagnostics) {
62     return diagnostics.filter(diagnostic => {
63         switch (diagnostic.code) {
64             case 1013: // "A rest parameter or binding pattern may not have a trailing comma."
65             case 1014: // "A rest parameter must be last in a parameter list."
66             case 1044: // "'{0}' modifier cannot appear on a module or namespace element."
67             case 1045: // "A '{0}' modifier cannot be used with an interface declaration."
68             case 1048: // "A rest parameter cannot have an initializer."
69             case 1049: // "A 'set' accessor must have exactly one parameter."
70             case 1070: // "'{0}' modifier cannot appear on a type member."
71             case 1071: // "'{0}' modifier cannot appear on an index signature."
72             case 1085: // "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '{0}'."
73             case 1090: // "'{0}' modifier cannot appear on a parameter."
74             case 1096: // "An index signature must have exactly one parameter."
75             case 1097: // "'{0}' list cannot be empty."
76             case 1098: // "Type parameter list cannot be empty."
77             case 1099: // "Type argument list cannot be empty."
78             case 1117: // "An object literal cannot have multiple properties with the same name in strict mode."
79             case 1121: // "Octal literals are not allowed in strict mode."
80             case 1123: //  "Variable declaration list cannot be empty."
81             case 1141: // "String literal expected."
82             case 1162: // "An object member cannot be declared optional."
83             case 1164: // "Computed property names are not allowed in enums."
84             case 1172: // "'extends' clause already seen."
85             case 1173: // "'extends' clause must precede 'implements' clause."
86             case 1175: // "'implements' clause already seen."
87             case 1176: // "Interface declaration cannot have 'implements' clause."
88             case 1190: // "The variable declaration of a 'for...of' statement cannot have an initializer."
89             case 1196: // "Catch clause variable type annotation must be 'any' or 'unknown' if specified."
90             case 1200: // "Line terminator not permitted before arrow."
91             case 1206: // "Decorators are not valid here."
92             case 1211: // "A class declaration without the 'default' modifier must have a name."
93             case 1242: // "'abstract' modifier can only appear on a class, method, or property declaration."
94             case 1246: // "An interface property cannot have an initializer."
95             case 1255: // "A definite assignment assertion '!' is not permitted in this context."
96             case 1308: // "'await' expression is only allowed within an async function."
97             case 2364: // "The left-hand side of an assignment expression must be a variable or a property access."
98             case 2369: // "A parameter property is only allowed in a constructor implementation."
99             case 2452: // "An enum member cannot have a numeric name."
100             case 2462: // "A rest element must be last in a destructuring pattern."
101             case 8017: // "Octal literal types must use ES2015 syntax. Use the syntax '{0}'."
102             case 17012: // "'{0}' is not a valid meta-property for keyword '{1}'. Did you mean '{2}'?"
103             case 17013: // "Meta-property '{0}' is only allowed in the body of a function declaration, function expression, or constructor."
104                 return true;
105         }
106         return false;
107     });
108 }
109 function convertDiagnosticToSemanticOrSyntacticError(diagnostic) {
110     return Object.assign(Object.assign({}, diagnostic), { message: ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) });
111 }
112 //# sourceMappingURL=semantic-or-syntactic-errors.js.map