import type * as d from '../../../declarations' ; import { addImports } from '../add-imports' ; import { addLegacyApis } from '../core-runtime-apis' ; import { getComponentMeta , getModuleFromSourceFile } from '../transform-utils' ; import { updateHydrateComponentClass } from './hydrate-component' ; import { updateStyleImports } from '../style-imports' ; import ts from 'typescript' ; export const hydrateComponentTransform = ( compilerCtx , transformOpts ) : ts . TransformerFactory < ts . SourceFile > => { return ( transformCtx ) => { return ( tsSourceFile ) => { const moduleFile = getModuleFromSourceFile ( compilerCtx , tsSourceFile ) ; const visitNode = ( node ) : any => { if ( ts . isClassDeclaration ( node ) ) { const cmp = getComponentMeta ( compilerCtx , tsSourceFile , node ) ; if ( cmp != null ) { return updateHydrateComponentClass ( node , moduleFile , cmp ) ; } } return ts . visitEachChild ( node , visitNode , transformCtx ) ; } ; tsSourceFile = ts . visitEachChild ( tsSourceFile , visitNode , transformCtx ) ; if ( moduleFile . cmps . length > 0 ) { tsSourceFile = updateStyleImports ( transformOpts , tsSourceFile , moduleFile ) ; } if ( moduleFile . isLegacy ) { addLegacyApis ( moduleFile ) ; } tsSourceFile = addImports ( transformOpts , tsSourceFile , moduleFile . coreRuntimeApis , transformOpts . coreImportPath ) ; return tsSourceFile ; } ; } ; } ;