UNPKG

babel-plugin-r-sugar

Version:

A Babel plugin that adds Vue-style v-if directive support to React

27 lines (23 loc) 832 B
// src/index.ts import { PluginObj } from '@babel/core'; import type { NodePath } from '@babel/traverse'; import type { JSXElement } from '@babel/types'; import { vIfPlugin } from './visitors/vIf'; import { tablePlugin } from './visitors/tableSticky'; import { formColonPlugin } from './visitors/formColon'; const reactVIfPlugin = function(babel: typeof import('@babel/core')) { return { name: "babel-plugin-react-v-if", visitor: { JSXElement(path: NodePath<JSXElement>, state: any) { // 处理v-if指令 vIfPlugin(path, babel.types); // 处理Table组件的sticky属性 tablePlugin(path, babel.types); // 处理Form组件的colon属性,强制设置为false formColonPlugin(path, babel.types); } } }; }; export default reactVIfPlugin;