unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.77k stars 349 forks source link

When the global variable and function definition parameter have the same name, the function parameter will be overwritten by the global variable. After troubleshooting, it is caused by the unplugin vue components plugin. Removing this plugin is normal #687

Open WormGirl opened 1 year ago

WormGirl commented 1 year ago

Describe the bug

When the global variable and function definition parameter have the same name, the function parameter will be overwritten by the global variable. After troubleshooting, it is caused by the unplugin vue components plugin. Removing this plugin is normal

<script setup lang="ts">
const a = 3
function test(a: Number, b: Number) {
  // a的值应该是1才对  实际变成了3 有点离谱, 删掉unplugin-vue-components插件就正常了
  console.log(a, b)
}
</script>

<template>
  <button @click="test(1, 2)">
    点我可复现
  </button>
</template>

Reproduction

https://github.com/WormGirl/bug-report-unplugin-vue-components

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz   
    Memory: 16.88 GB / 31.79 GB
  Binaries:
    Node: 16.20.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.10 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (116.0.1938.62)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

pnpm

Validations

lishaobos commented 1 year ago

兄弟,你这个依赖安装不成功啊,确定 package.json 里面没有包含私有仓库的包

WormGirl commented 1 year ago

兄弟,你这个依赖安装不成功啊,确定 package.json 里面没有包含私有仓库的包

抱歉,是有几个私有的忘了删了,更新了,你重新拉下

lishaobos commented 1 year ago

兄弟,我这边没问题,你要么删除掉 lock 文件再安装试试?

image

WormGirl commented 1 year ago

兄弟,我这边没问题,你要么删除掉 lock 文件再安装试试?

image

兄弟,我这边没问题,你要么删除掉 lock 文件再安装试试?

image

兄弟,我上次就是删掉lock文件重装的

WormGirl commented 1 year ago

我打印的也是1 2 ,你加个debugger看看 ,很离谱的,运行时是3,2 GIF 2023-9-5 15-21-13

WormGirl commented 1 year ago
const a = 3
function test(a: Number, b: Number) {
  // a的值应该是1才对  实际变成了3 有点离谱
  // eslint-disable-next-line no-debugger, no-restricted-syntax
  debugger
  console.log(a, b)
}
lishaobos commented 1 year ago

这个应该是 sourcemap 生成或者是 chrome 的问题:

你 debugger 源代码,函数 a 变量实则成为了 a2,所以会指向上面的 a,你自己打印 a2,还是 1,我觉得这个不用过多纠结

image image

WormGirl commented 1 year ago

但是我删掉这个插件debugger就正常了 这是咋回事

WormGirl commented 1 year ago

感觉还是和这个插件有点关系

WormGirl commented 1 year ago

你把vite.config.ts里unplugin-vue-components/vite相关的删掉看下

WormGirl commented 1 year ago

重新验证了 就是debugger的时候不对 实际运行结果符合预期。。。可以的话还是麻烦看下啥原因 debugger不对也影响开发

lishaobos commented 1 year ago

提交 pr 了,是 sourceMap 精细度不够,等通过就好了