import _ts from 'typescript' ; import { createSourceFile } from '../../helpers' ; import { findTargetSyntaxKind } from '../../ast' ; export function parseExternalComponentsFromScrtipContent ( scriptContent , ts ) { const node = findExternalComponents ( scriptContent , ts ) ; if ( ! node ) return { } ; const externalComponents = node . properties ; const dict = externalComponents . reduce ( ( acc , ac ) => { if ( ts . isShorthandPropertyAssignment ( ac ) ) { const componentName = ac . name . escapedText . toString ( ) ; acc [ componentName ] = componentName ; } else if ( ts . isPropertyAssignment ( ac ) ) { } return acc ; } , { } as Record < string , string > ) ; return dict ; } function findExternalComponents ( scriptContent , ts ) { const node = createSourceFile ( ts , scriptContent ) ; const exportAssignment = findTargetSyntaxKind ( ts , node , ts . SyntaxKind . ExportAssignment ) ; if ( ! exportAssignment ) { return undefined ; } const callExpression = findTargetSyntaxKind ( ts , exportAssignment , ts . SyntaxKind . CallExpression ) ; if ( ! callExpression ) { return undefined ; } const objectLiteralExpression = findTargetSyntaxKind ( ts , callExpression , ts . SyntaxKind . ObjectLiteralExpression ) ; if ( ! objectLiteralExpression ) { return undefined ; } function findComponentsProperty ( node ) { if ( ts . isPropertyAssignment ( node ) ) { const name = node . name ; if ( 'escapedText' in name && name . escapedText === 'components' ) { return node ; } } return ts . forEachChild ( node , findComponentsProperty ) ; } const componentsProperty = findComponentsProperty ( objectLiteralExpression ) ; if ( ! componentsProperty ) return undefined ; return findTargetSyntaxKind ( ts , componentsProperty , ts . SyntaxKind . ObjectLiteralExpression ) ; }