import { ClassDeclaration , callExpression , isCallExpression , isExportDefaultDeclaration , isIdentifier , } from '@babel/types' ; import { NodePath } from '@babel/core' ; decorator export function replaceClassDecorators ( path ) { const { node } = path ; if ( ! node . decorators ) { return path ; } if ( isIdentifier ( node . id ) ) { const binding = path . scope . getBinding ( node . id . name ) ; if ( binding && binding . referencePaths . length ) { binding . referencePaths . forEach ( refPath => { const { parent : defaultExport } = refPath ; if ( isExportDefaultDeclaration ( defaultExport ) && node . decorators ) { node . decorators . reverse ( ) . forEach ( decorator => { const { declaration } = defaultExport ; if ( isIdentifier ( declaration ) || isCallExpression ( declaration ) ) { defaultExport . declaration = callExpression ( decorator . expression , [ declaration , ] ) ; } } ) ; } } ) ; } node . decorators = null ; } return path ; }