Skip to content

Enhance withDefaults support and improve API handling#64

Merged
smirk9581 merged 21 commits into
masterfrom
dev_@Ryan-Zhong
Jul 1, 2026
Merged

Enhance withDefaults support and improve API handling#64
smirk9581 merged 21 commits into
masterfrom
dev_@Ryan-Zhong

Conversation

@smirk9581

@smirk9581 smirk9581 commented Jun 29, 2026

Copy link
Copy Markdown
Member
  • compiler-core:

    • 新增 withDefaults 测试用例
    • syntax-processor 注册 withDefaults 处理阶段
    • 修复使用 unplugin-auto-import 时,编译器无法识别 Vue API 来源,导致跳过转换
    • 新增无需 Vue API 来源的转换测试用例
    • 更新 v-if 预期输出格式
    • 优化编译流程提示,细分为 3 个阶段:将 Compiling Vue to React... 改为 Compiling components/scripts/styles...
    • 升级至 v1.10.0 并更新文档
  • 更新仓库首页描述文案

smirk9581 added 15 commits June 26, 2026 14:56
- 从 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 徽章
@smirk9581 smirk9581 self-assigned this Jun 29, 2026
@smirk9581 smirk9581 added bug Something isn't working enhancement New feature or request labels Jun 29, 2026
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.19728% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ntax-processor/preprocess/resolve-with-defaults.ts 86.48% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

- 重排徽章顺序,调整 Stars/Downloads/Monthly 位置
- Stars 徽章添加 color=white 白色标识
- Npm 徽章链接统一指向 vureact.top 首页
- 移除 Vue 3.x 和 React 18+ 版本徽章
- 同步更新中、英、日三语 README
@smirk9581 smirk9581 added the documentation Improvements or additions to documentation label Jun 29, 2026
- 移除 Monthly 下载量徽章
- 部分徽章去掉 style=flat-square 使显示更简洁
- 日文版修复多余空行
- 将'Compiling Vue to React...'拆分为 Compiling components/scripts/styles 三个阶段
- 编译完成提示改为'Vue compiled to React'
- 新增 Added:withDefaults 宏 API 转换支持
- 新增 Fixed:unplugin-auto-import 等免导入插件下绑定缺失问题
- 新增 Changed:编译提示优化及测试覆盖
@smirk9581 smirk9581 merged commit 7d93fa2 into master Jul 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant