我的 .cTags在大多数情况下工作正常。但是,在下面提到的情况下,它没有按预期工作。
目录结构
root
- a
- foo.js
- bar.js
- index.js
- b
- current-file.js
current-file.js
import { foo } from './a'
foo()
index.js
export { default as foo } from './foo'
foo.js
const foo = () => 'foo'
export default foo
当我试图从 current-file.js 跳转到 foo
的定义时,它导航到 a/index.js 而不是a/foo.js
最佳答案
我认为这不是cTags的限制,而是ES6语言本身的限制。
花括号导入将首先查找名为 a
的文件,如果找不到,它将查找名为 'a' 的目录及其 index.js
文件(自动解析,例如:a/index.js
)。它不会在目录中查找文件。
花括号只是从文件中查找非默认导出,而不是通过目录查找。
Example (注意:目录 a
已重命名为 c
,因为 codesandbox 在其引擎中保留了名称 a
)
您可以尝试删除 /c.js
文件以加载 c/index.js
文件。
另外,我建议你this thread这可以给你更多关于 js 中大括号的提示
您可以使用 fs.readDir 读取目录api 并自动 require
/export 您的 index.js
中的文件;但是 index.js
将被加载。
关于javascript - 通过 cTags 导航 ES6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58231697/