UNPKG

kdesign-ui

Version:

kd is from company of klx, it provide quickly genarator company inner business front structure

29 lines (28 loc) 726 B
const t = require('babel-types') const babel = require('babel-core') const babylon = require('babylon') type types = typeof t type babels = typeof babylon interface optionsInterface { visitor(v: types, babel: babels): Record<string | number | symbol, any> lintCode (code: string): string } const defaultOptions = { visitor(t: types) { return {} }, lintCode(code: string) { return code } } export default function ( code:string = '', options: optionsInterface = defaultOptions ) { const result = babel.transform(code, { plugins: [{ visitor: options.visitor(t, babylon) }], generatorOpts: {} }) //转换语法代码格式 return (options.lintCode(result.code) || '').replace(/\;/g, '') }