|
1 |
| -import { ts } from 'ts-morph'; |
| 1 | +import { SyntaxKind, ts } from 'ts-morph'; |
2 | 2 | import { detectIndent } from '../../../../../utils';
|
3 | 3 | import { ClassHelper } from './class-helper';
|
4 | 4 | import { IParseDeepIdentifierResult, SymbolHelper } from './symbol-helper';
|
@@ -44,6 +44,77 @@ export class ComponentHelper {
|
44 | 44 | return this.symbolHelper.getSymbolDeps(props, 'exportAs', srcFile).pop();
|
45 | 45 | }
|
46 | 46 |
|
| 47 | + public getComponentHostDirectives( |
| 48 | + props: ReadonlyArray<ts.ObjectLiteralElementLike> |
| 49 | + ): Array<any> { |
| 50 | + const hostDirectiveSymbolParsed = this.symbolHelper.getSymbolDepsRaw( |
| 51 | + props, |
| 52 | + 'hostDirectives' |
| 53 | + ); |
| 54 | + let hostDirectiveSymbol = null; |
| 55 | + |
| 56 | + if (hostDirectiveSymbolParsed.length > 0) { |
| 57 | + hostDirectiveSymbol = hostDirectiveSymbolParsed.pop(); |
| 58 | + } |
| 59 | + |
| 60 | + const result = []; |
| 61 | + |
| 62 | + if ( |
| 63 | + hostDirectiveSymbol && |
| 64 | + hostDirectiveSymbol.initializer && |
| 65 | + hostDirectiveSymbol.initializer.elements && |
| 66 | + hostDirectiveSymbol.initializer.elements.length > 0 |
| 67 | + ) { |
| 68 | + hostDirectiveSymbol.initializer.elements.forEach(element => { |
| 69 | + if (element.kind === SyntaxKind.Identifier) { |
| 70 | + result.push({ |
| 71 | + name: element.escapedText |
| 72 | + }); |
| 73 | + } else if ( |
| 74 | + element.kind === SyntaxKind.ObjectLiteralExpression && |
| 75 | + element.properties && |
| 76 | + element.properties.length > 0 |
| 77 | + ) { |
| 78 | + const parsedDirective: any = { |
| 79 | + name: '', |
| 80 | + inputs: [], |
| 81 | + outputs: [] |
| 82 | + }; |
| 83 | + |
| 84 | + element.properties.forEach(property => { |
| 85 | + if (property.name.escapedText === 'directive') { |
| 86 | + parsedDirective.name = property.initializer.escapedText; |
| 87 | + } else if (property.name.escapedText === 'inputs') { |
| 88 | + if ( |
| 89 | + property.initializer && |
| 90 | + property.initializer.elements && |
| 91 | + property.initializer.elements.length > 0 |
| 92 | + ) { |
| 93 | + property.initializer.elements.forEach(propertyElement => { |
| 94 | + parsedDirective.inputs.push(propertyElement.text); |
| 95 | + }); |
| 96 | + } |
| 97 | + } else if (property.name.escapedText === 'outputs') { |
| 98 | + if ( |
| 99 | + property.initializer && |
| 100 | + property.initializer.elements && |
| 101 | + property.initializer.elements.length > 0 |
| 102 | + ) { |
| 103 | + property.initializer.elements.forEach(propertyElement => { |
| 104 | + parsedDirective.outputs.push(propertyElement.text); |
| 105 | + }); |
| 106 | + } |
| 107 | + } |
| 108 | + }); |
| 109 | + |
| 110 | + result.push(parsedDirective); |
| 111 | + } |
| 112 | + }); |
| 113 | + } |
| 114 | + |
| 115 | + return result; |
| 116 | + } |
| 117 | + |
47 | 118 | public getComponentHost(
|
48 | 119 | props: ReadonlyArray<ts.ObjectLiteralElementLike>
|
49 | 120 | ): Map<string, string> {
|
|
0 commit comments