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 === '?.';
8 exports.isOptionalChainPunctuator = isOptionalChainPunctuator;
9 function isNotOptionalChainPunctuator(token) {
10 return !isOptionalChainPunctuator(token);
12 exports.isNotOptionalChainPunctuator = isNotOptionalChainPunctuator;
13 function isNonNullAssertionPunctuator(token) {
14 return token.type === ts_estree_1.AST_TOKEN_TYPES.Punctuator && token.value === '!';
16 exports.isNonNullAssertionPunctuator = isNonNullAssertionPunctuator;
17 function isNotNonNullAssertionPunctuator(token) {
18 return !isNonNullAssertionPunctuator(token);
20 exports.isNotNonNullAssertionPunctuator = isNotNonNullAssertionPunctuator;
22 * Returns true if and only if the node represents: foo?.() or foo.bar?.()
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()
30 exports.isOptionalOptionalCallExpression = isOptionalOptionalCallExpression;
32 * Returns true if and only if the node represents logical OR
34 function isLogicalOrOperator(node) {
35 return (node.type === ts_estree_1.AST_NODE_TYPES.LogicalExpression && node.operator === '||');
37 exports.isLogicalOrOperator = isLogicalOrOperator;
39 * Checks if a node is a type assertion:
45 function isTypeAssertion(node) {
49 return (node.type === ts_estree_1.AST_NODE_TYPES.TSAsExpression ||
50 node.type === ts_estree_1.AST_NODE_TYPES.TSTypeAssertion);
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;
56 exports.isVariableDeclarator = isVariableDeclarator;
57 function isFunction(node) {
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);
67 exports.isFunction = isFunction;
68 function isFunctionType(node) {
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);
81 exports.isFunctionType = isFunctionType;
82 function isFunctionOrFunctionType(node) {
83 return isFunction(node) || isFunctionType(node);
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;
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;
93 exports.isTSConstructorType = isTSConstructorType;
94 function isClassOrTypeElement(node) {
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,
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);
115 exports.isClassOrTypeElement = isClassOrTypeElement;
117 * Checks if a node is a constructor method.
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');
123 exports.isConstructor = isConstructor;
125 * Checks if a node is a setter method.
127 function isSetter(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');
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;
137 exports.isIdentifier = isIdentifier;
139 * Checks if a node represents an `await …` expression.
141 function isAwaitExpression(node) {
142 return (node === null || node === void 0 ? void 0 : node.type) === ts_estree_1.AST_NODE_TYPES.AwaitExpression;
144 exports.isAwaitExpression = isAwaitExpression;
146 * Checks if a possible token is the `await` keyword.
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';
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);
156 exports.isMemberOrOptionalMemberExpression = isMemberOrOptionalMemberExpression;
157 //# sourceMappingURL=predicates.js.map