You need to enable JavaScript to run this app. 如何阻止Vite/Esbuild编译器将ASCII字符码替换为数字?
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Vite/Esbuild编译器将ASCII字符码替换为数字?

问题

编译后代码中的0x30和0x31分别被替换为48和49。在TypeScript Playground环境下并未出现此问题,但使用Vite作为构建工具时会触发该现象,怀疑与Esbuild配置有关。求问是否有其他人遇到过类似问题并找到了解决方案?

示例代码

const scan = (path: PathParser) => {
  const { index, pathValue } = path;
  const code = pathValue.charCodeAt(index);

  if (code === 0x30/* 0 */) {
    path.param = 0;
    path.index += 1;
    return;
  }

  if (code === 0x31/* 1 */) {
    path.param = 1;
    path.index += 1;
    return;
  }
}

已解决:问题并非ASCII字符码转数字导致,而是示例函数上方的TypeScript笔误。


内容的提问来源于stack exchange,提问作者thednp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 21:50:17