UNPKG

vue-to-react-tool

Version:
42 lines (40 loc) 886 B
import babelTraverse from '@babel/traverse'; /** * 用于去除ts类型检测 * @export * @param {*} ast * @returns */ export default function(ast) { babelTraverse(ast, { ExportNamedDeclaration(exportPath) { let declaration = exportPath.get('declaration'); if ( declaration && (declaration.isTSInterfaceDeclaration() || declaration.isTSTypeAliasDeclaration()) ) { exportPath.remove(); } }, TSTypeAliasDeclaration(path) { path.remove(); }, TSTypeParameterDeclaration(path) { path.remove(); }, TSInterfaceDeclaration(path) { path.remove(); }, TSTypeParameterInstantiation(path) { path.remove(); }, TSTypeAnnotation(path) { path.remove(); }, TSAsExpression(path) { path.replaceWith(path.get('expression')); } }); return ast; }