({
json,
options,
withAttributePassing,
rootRef,
}: {
json: MitosisComponent;
options: ToAngularOptions;
withAttributePassing?: boolean;
rootRef: string;
})
| 7 | import { isAssignmentExpression } from '@babel/types'; |
| 8 | |
| 9 | export const getDomRefs = ({ |
| 10 | json, |
| 11 | options, |
| 12 | withAttributePassing, |
| 13 | rootRef, |
| 14 | }: { |
| 15 | json: MitosisComponent; |
| 16 | options: ToAngularOptions; |
| 17 | withAttributePassing?: boolean; |
| 18 | rootRef: string; |
| 19 | }): Set<string> => { |
| 20 | const domRefs = getRefs(json); |
| 21 | |
| 22 | const nativeElement = options.api === 'signals' ? `()?.nativeElement` : '?.nativeElement'; |
| 23 | |
| 24 | if (withAttributePassing) { |
| 25 | if (!domRefs.has(rootRef)) { |
| 26 | domRefs.add(rootRef); |
| 27 | } |
| 28 | |
| 29 | addCodeNgAfterViewInit( |
| 30 | json, |
| 31 | ` |
| 32 | const element: HTMLElement | null = this.${rootRef}${nativeElement}; |
| 33 | this.enableAttributePassing(element, "${dashCase(json.name)}"); |
| 34 | `, |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | mapRefs(json, (refName, extra) => { |
| 39 | const isDomRef = domRefs.has(refName); |
| 40 | let additional = nativeElement; |
| 41 | if (extra?.type === 'bindings' && options.api === 'signals') { |
| 42 | // we don't need nativeElement and this. for bindings in signals |
| 43 | return refName; |
| 44 | } else if (extra?.type === 'hooks-deps-array' && options.api === 'signals') { |
| 45 | // we don't need nativeElement for deps-array in hooks |
| 46 | additional = '()'; |
| 47 | } else if (extra?.path.parentPath && isAssignmentExpression(extra?.path.parentPath.container)) { |
| 48 | // we cannot use conditionals for assignments, it has to be checked before |
| 49 | additional = options.api === 'signals' ? `()!.nativeElement` : '!.nativeElement'; |
| 50 | } |
| 51 | return `this.${isDomRef ? '' : '_'}${refName}${isDomRef ? additional : ''}`; |
| 52 | }); |
| 53 | |
| 54 | return domRefs; |
| 55 | }; |
no test coverage detected