MCPcopy Create free account
hub / github.com/Snapchat/Valdi / isExpressionNode

Function isExpressionNode

compiler/companion/src/TSUtils.ts:3–61  ·  view source on GitHub ↗
(node: ts.Node)

Source from the content-addressed store, hash-verified

1import * as ts from 'typescript';
2
3export function isExpressionNode(node: ts.Node): node is ts.Expression {
4 switch (node.kind) {
5 case ts.SyntaxKind.SuperKeyword:
6 case ts.SyntaxKind.NullKeyword:
7 case ts.SyntaxKind.TrueKeyword:
8 case ts.SyntaxKind.FalseKeyword:
9 case ts.SyntaxKind.RegularExpressionLiteral:
10 case ts.SyntaxKind.ArrayLiteralExpression:
11 case ts.SyntaxKind.ObjectLiteralExpression:
12 case ts.SyntaxKind.PropertyAccessExpression:
13 case ts.SyntaxKind.ElementAccessExpression:
14 case ts.SyntaxKind.CallExpression:
15 case ts.SyntaxKind.NewExpression:
16 case ts.SyntaxKind.TaggedTemplateExpression:
17 case ts.SyntaxKind.AsExpression:
18 case ts.SyntaxKind.TypeAssertionExpression:
19 case ts.SyntaxKind.NonNullExpression:
20 case ts.SyntaxKind.ParenthesizedExpression:
21 case ts.SyntaxKind.FunctionExpression:
22 case ts.SyntaxKind.ClassExpression:
23 case ts.SyntaxKind.ArrowFunction:
24 case ts.SyntaxKind.VoidExpression:
25 case ts.SyntaxKind.DeleteExpression:
26 case ts.SyntaxKind.TypeOfExpression:
27 case ts.SyntaxKind.PrefixUnaryExpression:
28 case ts.SyntaxKind.PostfixUnaryExpression:
29 case ts.SyntaxKind.BinaryExpression:
30 case ts.SyntaxKind.ConditionalExpression:
31 case ts.SyntaxKind.SpreadElement:
32 case ts.SyntaxKind.TemplateExpression:
33 case ts.SyntaxKind.OmittedExpression:
34 case ts.SyntaxKind.JsxElement:
35 case ts.SyntaxKind.JsxSelfClosingElement:
36 case ts.SyntaxKind.JsxFragment:
37 case ts.SyntaxKind.YieldExpression:
38 case ts.SyntaxKind.AwaitExpression:
39 case ts.SyntaxKind.MetaProperty:
40 return true;
41 case ts.SyntaxKind.QualifiedName:
42 while (node.parent.kind === ts.SyntaxKind.QualifiedName) {
43 node = node.parent;
44 }
45 return node.parent.kind === ts.SyntaxKind.TypeQuery || isJSXTagName(node);
46 case ts.SyntaxKind.Identifier:
47 if (node.parent.kind === ts.SyntaxKind.TypeQuery || isJSXTagName(node)) {
48 return true;
49 }
50 // falls through
51
52 case ts.SyntaxKind.NumericLiteral:
53 case ts.SyntaxKind.BigIntLiteral:
54 case ts.SyntaxKind.StringLiteral:
55 case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
56 case ts.SyntaxKind.ThisKeyword:
57 return isInExpressionContext(node);
58 default:
59 return false;
60 }

Callers 7

compileFunction · 0.90
toStatementMethod · 0.90
toExpressionMethod · 0.90
outputJSXComponentMethod · 0.90
transformNodeMethod · 0.90
transformNodeGenericMethod · 0.90
isInExpressionContextFunction · 0.85

Calls 2

isJSXTagNameFunction · 0.85
isInExpressionContextFunction · 0.85

Tested by 1

compileFunction · 0.72