.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / experimental-utils / dist / ast-utils / predicates.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.isVariableDeclarator = exports.isTypeAssertion = exports.isTSFunctionType = exports.isTSConstructorType = exports.isSetter = exports.isOptionalOptionalCallExpression = exports.isOptionalChainPunctuator = exports.isNotOptionalChainPunctuator = exports.isNotNonNullAssertionPunctuator = exports.isNonNullAssertionPunctuator = exports.isMemberOrOptionalMemberExpression = exports.isLogicalOrOperator = exports.isIdentifier = exports.isFunctionType = exports.isFunctionOrFunctionType = exports.isFunction = exports.isClassOrTypeElement = exports.isConstructor = exports.isAwaitKeyword = exports.isAwaitExpression = void 0;
4 const ts_estree_1 = require("../ts-estree");
5 function isOptionalChainPunctuator(token) {
6     return token.type === ts_estree_1.AST_TOKEN_TYPES.Punctuator && token.value === '?.';
7 }
8 exports.isOptionalChainPunctuator = isOptionalChainPunctuator;
9 function isNotOptionalChainPunctuator(token) {
10     return !isOptionalChainPunctuator(token);
11 }
12 exports.isNotOptionalChainPunctuator = isNotOptionalChainPunctuator;
13 function isNonNullAssertionPunctuator(token) {
14     return token.type === ts_estree_1.AST_TOKEN_TYPES.Punctuator && token.value === '!';
15 }
16 exports.isNonNullAssertionPunctuator = isNonNullAssertionPunctuator;
17 function isNotNonNullAssertionPunctuator(token) {
18     return !isNonNullAssertionPunctuator(token);
19 }
20 exports.isNotNonNullAssertionPunctuator = isNotNonNullAssertionPunctuator;
21 /**
22  * Returns true if and only if the node represents: foo?.() or foo.bar?.()
23  */
24 function isOptionalOptionalCallExpression(node) {
25     return (node.type === ts_estree_1.AST_NODE_TYPES.OptionalCallExpression &&
26         // this flag means the call expression itself is option
27         // i.e. it is foo.bar?.() and not foo?.bar()
28         node.optional);
29 }
30 exports.isOptionalOptionalCallExpression = isOptionalOptionalCallExpression;
31 /**
32  * Returns true if and only if the node represents logical OR
33  */
34 function isLogicalOrOperator(node) {
35     return (node.type === ts_estree_1.AST_NODE_TYPES.LogicalExpression && node.operator === '||');
36 }
37 exports.isLogicalOrOperator = isLogicalOrOperator;
38 /**
39  * Checks if a node is a type assertion:
40  * ```
41  * x as foo
42  * <foo>x
43  * ```
44  */
45 function isTypeAssertion(node) {
46     if (!node) {
47         return false;
48     }
49     return (node.type === ts_estree_1.AST_NODE_TYPES.TSAsExpression ||
50         node.type === ts_estree_1.AST_NODE_TYPES.TSTypeAssertion);
51 }
52 exports.isTypeAssertion = isTypeAssertion;
53 function isVariableDeclarator(node) {
54     return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.VariableDeclarator;
55 }
56 exports.isVariableDeclarator = isVariableDeclarator;
57 function isFunction(node) {
58     if (!node) {
59         return false;
60     }
61     return [
62         ts_estree_1.AST_NODE_TYPES.ArrowFunctionExpression,
63         ts_estree_1.AST_NODE_TYPES.FunctionDeclaration,
64         ts_estree_1.AST_NODE_TYPES.FunctionExpression,
65     ].includes(node.type);
66 }
67 exports.isFunction = isFunction;
68 function isFunctionType(node) {
69     if (!node) {
70         return false;
71     }
72     return [
73         ts_estree_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
74         ts_estree_1.AST_NODE_TYPES.TSConstructorType,
75         ts_estree_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
76         ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
77         ts_estree_1.AST_NODE_TYPES.TSFunctionType,
78         ts_estree_1.AST_NODE_TYPES.TSMethodSignature,
79     ].includes(node.type);
80 }
81 exports.isFunctionType = isFunctionType;
82 function isFunctionOrFunctionType(node) {
83     return isFunction(node) || isFunctionType(node);
84 }
85 exports.isFunctionOrFunctionType = isFunctionOrFunctionType;
86 function isTSFunctionType(node) {
87     return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.TSFunctionType;
88 }
89 exports.isTSFunctionType = isTSFunctionType;
90 function isTSConstructorType(node) {
91     return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.TSConstructorType;
92 }
93 exports.isTSConstructorType = isTSConstructorType;
94 function isClassOrTypeElement(node) {
95     if (!node) {
96         return false;
97     }
98     return [
99         // ClassElement
100         ts_estree_1.AST_NODE_TYPES.ClassProperty,
101         ts_estree_1.AST_NODE_TYPES.FunctionExpression,
102         ts_estree_1.AST_NODE_TYPES.MethodDefinition,
103         ts_estree_1.AST_NODE_TYPES.TSAbstractClassProperty,
104         ts_estree_1.AST_NODE_TYPES.TSAbstractMethodDefinition,
105         ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
106         ts_estree_1.AST_NODE_TYPES.TSIndexSignature,
107         // TypeElement
108         ts_estree_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
109         ts_estree_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
110         // AST_NODE_TYPES.TSIndexSignature,
111         ts_estree_1.AST_NODE_TYPES.TSMethodSignature,
112         ts_estree_1.AST_NODE_TYPES.TSPropertySignature,
113     ].includes(node.type);
114 }
115 exports.isClassOrTypeElement = isClassOrTypeElement;
116 /**
117  * Checks if a node is a constructor method.
118  */
119 function isConstructor(node) {
120     return ((node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.MethodDefinition &&
121         node.kind === 'constructor');
122 }
123 exports.isConstructor = isConstructor;
124 /**
125  * Checks if a node is a setter method.
126  */
127 function isSetter(node) {
128     return (!!node &&
129         (node.type === ts_estree_1.AST_NODE_TYPES.MethodDefinition ||
130             node.type === ts_estree_1.AST_NODE_TYPES.Property) &&
131         node.kind === 'set');
132 }
133 exports.isSetter = isSetter;
134 function isIdentifier(node) {
135     return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.Identifier;
136 }
137 exports.isIdentifier = isIdentifier;
138 /**
139  * Checks if a node represents an `await …` expression.
140  */
141 function isAwaitExpression(node) {
142     return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.AwaitExpression;
143 }
144 exports.isAwaitExpression = isAwaitExpression;
145 /**
146  * Checks if a possible token is the `await` keyword.
147  */
148 function isAwaitKeyword(node) {
149     return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_TOKEN_TYPES.Identifier && node.value === 'await';
150 }
151 exports.isAwaitKeyword = isAwaitKeyword;
152 function isMemberOrOptionalMemberExpression(node) {
153     return (node.type === ts_estree_1.AST_NODE_TYPES.MemberExpression ||
154         node.type === ts_estree_1.AST_NODE_TYPES.OptionalMemberExpression);
155 }
156 exports.isMemberOrOptionalMemberExpression = isMemberOrOptionalMemberExpression;
157 //# sourceMappingURL=predicates.js.map