Babel plugins that read AST `loc` produce wrong positions when running after OXC
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- babel, react, typescript
- 领域
- build-system, frontend
调研方向
从链接的 vite-babel-order-repro 开始,跟踪 @vitejs/plugin-react 的 OXC 转换以及 @rolldown/plugin-babel 的后处理路径。比较 pre 和 post 排序下的 Babel AST loc 值与 OXC jsxDEV 源信息。完成标准是自定义 Babel 插件能够接收到原始源位置,同时不改变 OXC 的位置。
由索引模型根据 Issue 内容生成。
描述
Related plugins
Describe the bug
When a Babel plugin runs after @vitejs/plugin-react's OXC transform (using @rolldown/plugin-babel with enforce: 'post' or a custom plugin), the Babel AST loc values refer to the OXC-transformed code, not the original source. Any Babel plugin that reads loc.start.line / loc.start.column to embed source positions in the output will produce incorrect values.
This was not an issue with @vitejs/plugin-react v5 where Babel handled both JSX transform and custom plugins in a single pass — loc always pointed to the original source.
Example
We have a Babel plugin that inserts ComponentName.__debugSourceDefine = { fileName, lineNumber, columnNumber } after each React function component, using the function body's loc:
FunctionDeclaration(path, state) {
const name = path.node.id.name;
const loc = path.node.body.loc; // ← wrong after OXC transform
// inserts: Foo.__debugSourceDefine = { fileName: "...", lineNumber: loc.start.line, ... }
path.insertAfter(createDebugInfo(name, state.file.opts.filename, loc));
}
With v5 (react({ babel: { plugins: [myPlugin] } })), loc.start.line referred to the original .tsx file. With v6, OXC transforms JSX first, changing line numbers. Babel sees the transformed code and its loc values are offset.
The dilemma — no configuration produces correct results
With enforce: 'pre' (default) — Babel runs before OXC:
- ✅
__debugSourceDefineline numbers are correct (Babel sees original source) - ❌ OXC's
jsxDEV()source info is wrong — every JSX element in the app gets shifted line numbers because Babel inserted__debugSourceDefineblocks (4+ lines each) before OXC processed the file
With enforce: 'post' — Babel runs after OXC:
- ❌
__debugSourceDefineline numbers are wrong (Babel ASTlocrefers to OXC-transformed code, not the original source) - ✅ OXC's
jsxDEV()source info is correct (OXC saw the original source)
Reproduction
https://github.com/Artur-/vite-babel-order-repro
Steps to reproduce
npm install
npx vite
Open in browser — the page automatically verifies source positions.
System Info
System:
OS: macOS 26.3.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 24.14.0
npm: 11.9.0
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
- 主要语言
- TypeScript
- 星标
- 1.2k
- 派生
- 287
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
vitejs/vite-plugin-react 的其他 Issue
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)可能已有人在做 @wozhenbang2004 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
vitejs/vite-plugin-react#1570 ·
维护者通常 1 天内回复
-
pending triage
难度 4/5 3-5 天 新手友好度 35/100
vitejs/vite-plugin-react#1581 ·
维护者通常 1 天内回复
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC build可能已有人在做 @NeilPant 于 4 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
vitejs/vite-plugin-react#1578 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
vitejs/vite-plugin-react#1577 ·
维护者通常 1 天内回复
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceError可能已有人在做 @draarivpatel-ui 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
vitejs/vite-plugin-react#1566 · 1 条评论 ·
维护者通常 1 天内回复
查看 vitejs/vite-plugin-react 的全部 Issue
相似的 Issue
-
good first issue help wanted
难度 2/5 1 小时以内 新手友好度 86/100
Intelligenza-Umana/intelligenza-umana-web#16 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
open-webui/open-webui#35184 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
danielmiessler/LifeOS#3001 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复