UNPKG

@nx/angular

Version:

The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypre

18 lines (17 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getComponentDataFromAST = getComponentDataFromAST; function getComponentDataFromAST(tree, normalizedComponentPath) { const COMPONENT_CONTENT_SELECTOR = 'ClassDeclaration:has(Decorator > CallExpression:has(Identifier[name=Component]))'; const COMPONENT_NAME_SELECTOR = 'ClassDeclaration:has(Decorator > CallExpression:has(Identifier[name=Component])) > Identifier'; const componentFileContents = tree.read(normalizedComponentPath, 'utf-8'); const { tsquery } = require('@phenomnomnominal/tsquery'); const componentAST = tsquery.ast(componentFileContents); const componentNode = tsquery(componentAST, COMPONENT_CONTENT_SELECTOR, { visitAllChildren: true, })[0]; const componentContents = componentFileContents.slice(componentNode.getStart(), componentNode.getEnd()); const componentNameNode = tsquery(tsquery.ast(componentContents), COMPONENT_NAME_SELECTOR, { visitAllChildren: true })[0]; const componentName = componentNameNode.getText(); return { componentFileContents, componentAST, componentName }; }