(node: any)
| 20 | const metas: ParsedMetadata[] = []; |
| 21 | |
| 22 | const visitNode = (node: any): void => { |
| 23 | if (node.kind === ts.SyntaxKind.ClassDeclaration) { |
| 24 | const decorators = ts.getDecorators(node); |
| 25 | const meta = { |
| 26 | componentName: node.name.text, |
| 27 | } as ParsedMetadata; |
| 28 | |
| 29 | if (node.jsDoc && node.jsDoc.length) { |
| 30 | for (const doc of node.jsDoc) { |
| 31 | if (doc.tags && doc.tags.length) { |
| 32 | for (const tag of doc.tags) { |
| 33 | const tagValue = tag.comment; |
| 34 | const tagName = tag.tagName.text; |
| 35 | if (tagName === 'title') { |
| 36 | meta.title = tagValue; |
| 37 | meta.isPrimary = true; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if (decorators && decorators.length) { |
| 45 | for (const decorator of decorators) { |
| 46 | const call = decorator.expression; |
| 47 | |
| 48 | if ( |
| 49 | !ts.isCallExpression(call) || |
| 50 | !ts.isIdentifier(call.expression) || |
| 51 | call.expression.text !== 'Component' || |
| 52 | call.arguments.length === 0 || |
| 53 | !ts.isObjectLiteralExpression(call.arguments[0]) |
| 54 | ) { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | for (const prop of call.arguments[0].properties) { |
| 59 | if (!ts.isPropertyAssignment(prop) || !prop.name || !ts.isIdentifier(prop.name)) { |
| 60 | continue; |
| 61 | } |
| 62 | |
| 63 | const propName = prop.name.text; |
| 64 | |
| 65 | // Since additional files can be also stylesheets, we need to properly parse |
| 66 | // the styleUrls metadata property. |
| 67 | if (propName === 'styleUrls' && ts.isArrayLiteralExpression(prop.initializer)) { |
| 68 | meta[propName] = prop.initializer.elements.map( |
| 69 | literal => (literal as ts.StringLiteralLike).text, |
| 70 | ); |
| 71 | } else if (propName === 'styleUrl' && ts.isStringLiteralLike(prop.initializer)) { |
| 72 | meta.styleUrls = [prop.initializer.text]; |
| 73 | } else if ( |
| 74 | ts.isStringLiteralLike(prop.initializer) || |
| 75 | ts.isIdentifier(prop.initializer) |
| 76 | ) { |
| 77 | (meta as any)[propName] = prop.initializer.text; |
| 78 | } |
| 79 | } |
no test coverage detected
searching dependent graphs…