Enhance withDefaults support and improve API handling#64
Merged
Conversation
- 从 ADAPTER_RULES 动态生成免 import 的 API 名称集合 - 排除 dir.* 系指令适配规则
- 移除白名单常量(VUE_API_MAP.defineAsyncComponent),改用 AUTO_IMPORTED_APIS - 重构逻辑:优先检查 binding(精确匹配),无 binding 时 fallback 到白名单 - 修复 issue #62:unplugin-auto-import 场景下正确的 API 识别
- 删除 resolve-analysis-only-adapter.ts 中本地的 isVueApiReference/isVueImportBinding 实现 - 改为从 resolve-rename-adapter 导入共享的 isVueApiReference 函数
- input.vue: 精简 import,仅保留仍在使用的 Vue API 更新 ref/reactive/computed 初始值为新数据 - output.jsx: 同步更新预期输出值和 computed 表达式
- input.vue: 覆盖 8 种 v-if 场景 1. 基本 v-if 2. v-if / v-else 3. v-if / v-else-if / v-else(多分支) 4. template 上使用 v-if 分组 5. 复杂条件(结合 computed) 6. 嵌套条件(内部嵌套 v-if + v-for) 7. 可选链操作符 ?. 安全访问 8. 更深层嵌套的可选链 - expected/output.jsx: 编译预期输出(三元表达式 + 可选链 + Fragment) - expected/output.css: scoped 样式预期输出
- ICompilationContext.scriptData 新增 propsWithDefaults 字段 - 新增 PropsWithDefaults 类型,包含 varName、values、typeParameters、位置/注释信息
- resolve-reactive-bindings 中新增 MACRO_API_NAMES.defaults 判断 - defineProps 和 withDefaults 声明的变量名均被收集为组件 props 名
- resolveWithDefaultsOptions:在预处理阶段解析 withDefaults 调用 - 校验参数合法性(defineProps + 对象字面量) - 提取默认值并展平函数包装值(如 labels: () => ['one', 'two'] → ['one', 'two']) - 记录转换信息到 ctx.scriptData.propsWithDefaults - 用占位空语句标记替换位置,供后处理使用 - 移除 withDefaults 外层包装,保留 defineProps - 导出 resolveWithDefaultsOptions 供 syntax-processor 注册
- resolveWithDefaults:在后处理阶段将占位符替换为完整的 useMemo 声明
- 在 Program.exit 中查找占位空语句
- 生成 const props = useMemo<Readonly<Props>>(() => ({...vrProps, msg: vrProps.msg ?? 'hello'}), [vrProps])
- 继承原始 withDefaults 调用的位置/注释信息
- 导出 resolveWithDefaults 供 syntax-processor 注册
- preprocess 中注册 resolveWithDefaultsOptions - postprocess 中注册 resolveWithDefaults - 关联 issue #63
- input.vue: 使用 withDefaults(defineProps<Props>(), { msg, count, labels }) 的 TS 场景
- expected/output.tsx: 编译预期输出,包含 useMemo 默认值合并
- 移除了多余换行,与编译器实际输出保持一致 - 对象数组写法改为紧凑格式 - return 部分改为单行 JSX
- 将项目定位从'Vue 迁移 React 与混合开发的完整解决方案'改为'专为 Vue 迁移 React 设计的智能编译器' - 同步更新中、英、日三语 README 描述
- 版本号从 1.9.0 升级至 1.10.0 - 更新包描述为 'A smart compiler for migrating Vue to React' - 同步更新中英文 README 描述信息 - 移除 Stars 徽章
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- 重排徽章顺序,调整 Stars/Downloads/Monthly 位置 - Stars 徽章添加 color=white 白色标识 - Npm 徽章链接统一指向 vureact.top 首页 - 移除 Vue 3.x 和 React 18+ 版本徽章 - 同步更新中、英、日三语 README
- 移除 Monthly 下载量徽章 - 部分徽章去掉 style=flat-square 使显示更简洁 - 日文版修复多余空行
- 将'Compiling Vue to React...'拆分为 Compiling components/scripts/styles 三个阶段 - 编译完成提示改为'Vue compiled to React'
- 新增 Added:withDefaults 宏 API 转换支持 - 新增 Fixed:unplugin-auto-import 等免导入插件下绑定缺失问题 - 新增 Changed:编译提示优化及测试覆盖
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compiler-core:
unplugin-auto-import时,编译器无法识别 Vue API 来源,导致跳过转换Compiling Vue to React...改为Compiling components/scripts/styles...更新仓库首页描述文案