1 | import * as ts from 'typescript';
|
2 | import * as implicitRoles from './implicitRoles';
|
3 | import { isJsxElement, isJsxSelfClosingElement, isJsxOpeningElement } from './TypeGuard';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export function getImplicitRole(node: ts.Node): string {
|
14 | let tagName: string;
|
15 |
|
16 | if (isJsxElement(node)) {
|
17 | tagName = node.openingElement.tagName.getText();
|
18 | } else if (isJsxSelfClosingElement(node)) {
|
19 | tagName = node.tagName.getText();
|
20 | } else if (isJsxOpeningElement(node)) {
|
21 | tagName = node.tagName.getText();
|
22 | } else {
|
23 | tagName = undefined;
|
24 | }
|
25 |
|
26 | return tagName && implicitRoles[tagName] && implicitRoles[tagName](node);
|
27 | }
|