@babel/types APIs
- ObjectExpression
- Expression
- Identifier
- CallExpression
- Node
- ImportDeclaration
- ArrayExpression
- VariableDeclarator
- JSXElement
- File
- JSXAttribute
- ImportSpecifier
- Statement
- ObjectProperty
- JSXExpressionContainer
- JSXMemberExpression
- BlockStatement
- JSXIdentifier
- ObjectPattern
- isIdentifier
- identifier
- stringLiteral
- booleanLiteral
- isObjectProperty
- isMemberExpression
- StringLiteral
- ArrowFunctionExpression
- VariableDeclaration
- ImportDefaultSpecifier
- FunctionExpression
- jsxAttribute
- jsxIdentifier
- JSXFragment
- JSXSpreadChild
- JSXText
- expressionStatement
- Program
- BooleanLiteral
- JSXOpeningElement
- MemberExpression
- FunctionDeclaration
- PatternLike
- RestElement
- LVal
- SourceLocation
- SpreadElement
- file
- Comment
- isCallExpression
- isVariableDeclarator
- isLogicalExpression
- isReturnStatement
- conditionalExpression
- isAssignmentExpression
- isNumericLiteral
- arrayPattern
- jsxElement
- isStringLiteral
- isBooleanLiteral
- jsxExpressionContainer
- isExpression
- jsxOpeningElement
- jsxMemberExpression
- isObjectExpression
- jsxClosingElement
- jsxText
- isArrayPattern
- isExpressionStatement
- isFunctionExpression
- ExpressionStatement
- ImportNamespaceSpecifier
- ReturnStatement
- JSXNamespacedName
- JSX
- LogicalExpression
- AssignmentPattern
- objectProperty
- objectExpression
- arrayExpression
- objectPattern
- nullLiteral
- numericLiteral
- isAssignmentPattern
- isRestElement
- importDeclaration
- importSpecifier
- isTemplateLiteral
- callExpression
- isImportSpecifier
- isArrowFunctionExpression
- isTSTypeReference
- isTypeAnnotation
- isObjectPattern
- BinaryExpression
- UnaryExpression
- ArrayPattern
- CatchClause
- DoWhileStatement
- ForInStatement
- ForOfStatement
- ForStatement
- NewExpression
- SwitchCase
- TemplateLiteral
- WhileStatement
- program
- isJSXIdentifier
- isJSXMemberExpression
- ClassDeclaration
- DebuggerStatement
- Declaration
- ExportDefaultDeclaration
- ExportNamedDeclaration
- ExportSpecifier
- NumericLiteral
- ObjectMethod
- Pattern
- TSDeclareFunction
- ExportDeclaration
- AssignmentExpression
- JSXEmptyExpression
- JSXSpreadAttribute
- isTSModuleDeclaration
- CommentBlock
- CommentLine
- InterpreterDirective
- addComments
- removeComments
Other Related APIs
@babel/types#isTSTypeReference TypeScript Examples
The following examples show how to use
@babel/types#isTSTypeReference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: validateRef.ts From engine with MIT License | 6 votes |
validateRef = (ref: Babel.NodePath): Result => {
const result: Result = {
error: true,
};
if (!ref) {
return result;
}
const node = ref.parentPath?.node;
const refNode = ref.node as Identifier;
const parent = ref.findParent((p) => p.isVariableDeclarator());
if (!parent) {
throw new Error(
"The producer or view types can only be used with variable declarations e.g. let foo: producer."
);
}
const declaration = parent.node as VariableDeclarator;
if (!(isTSTypeReference(node) || isTypeAnnotation(node))) {
result.errorMessage = `\`${refNode.name}\` should be used as a type. Please see the engine documentation`;
} else if (!isArrowFunctionExpression(declaration.init)) {
result.errorMessage = `\`${refNode.name}\` should receive an arrow function expression. Please see the engine documentation`;
} else if (
declaration.init.params.length > 0 &&
!isObjectPattern(declaration.init.params[0])
) {
result.errorMessage = `\`${refNode.name}\` should receive a single argument which needs to be an object`;
} else {
result.error = false;
result.success = true;
}
return result;
}