Navigate ES6 throught cTags

Viewed 175

My .cTags is working fine in mostly cases. However in a scenario mentioned below it's not working as expected.

Directory Structure

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

When i am trying to jump in definition of foo from current-file.js its navigating to a/index.js instead of a/foo.js

1 Answers

I think this is not a limitation about the cTags, but about the ES6 language itself.

The curly braces import will first lookup for the file named a, if not found, it will look for the directory named 'a' with its index.js file (auto-resolved, e.g: a/index.js). It won't look for a file into a directory.

The curly braces are only looking for the non-default exports from a file, and it's not looking through directories.

Example (NOTE: the directory a has been renamed to c as codesandbox reserved the name a in his engine)

You can try to remove the /c.js file to load the c/index.js file instead.

Also, I suggest you this thread which can give you more tips on curly brackets in js

You might be able to do a read through a directory with the fs.readDir api and automatically require/export the files in your index.js; But the index.js will be loaded.

Related