glato / emerge

Emerge is a browser-based interactive codebase and dependency visualization tool for many different programming languages. It supports some basic code quality and graph metrics and provides a simple and intuitive way to explore and analyze a codebase by using graph structures.
MIT License
818 stars 49 forks source link

(JS/TS) Import format not parsed correctly yet #5

Closed nicoespeon closed 3 years ago

nicoespeon commented 3 years ago

Hey @glato 👋

I did more tests to identify edge cases that would not be covered yet with emerge. I'll report them here as I find these. If you don't have time to fix them, I'll have a look some time myself.

1. Import local index

This is a valid import:

import { GenericId, Age, Country, Amount } from ".";

"." refers to the current folder. In JS, it will pick the index.{js,ts} file.

Today, this doesn't seem to be resolved. This structure should highlight the issue:

src/
|__ index.js 
|__ math.js    # import { someFunction } from "." 

This would generate 2 orphan nodes. math.js should depend on index.js though.

glato commented 3 years ago

Hey @nicoespeon, thanks for the tests and the feedback. I'll have a look at resolving the case with the current path, should be a good addition and probably not too hard to fix (as I encountered/resolved such cases in the Python Parser also) 👍

glato commented 3 years ago

@nicoespeon I've just pushed a naive implementation for the JS parser (0.16.1) which should include your described and valid case

import { GenericId, Age, Country, Amount } from ".";

If you find the time, check if this solves the problem in the JS parser. I was thinking of splitting every dependency resolving case/code into separate methods inside the parser, this should facilitate readability and testability, e.g.

def resolve_dependency_current_dir_index_js(self, ...)
...
def resolve_dependency_global_at(self, ...)
...
def resolve_dependency_relative_current_dir(self, ...)
...

What do you think? If you find more cases or could even implement them, I'd appreciate any help 😉

glato commented 3 years ago

@nicoespeon I've rewritten some parts of the dependency resolving code for all parsers, including TS and JS. Hopefully this should be less error-prone and not creating false duplicates anymore. If you haven't found any more bugs, I would close this issue?

nicoespeon commented 3 years ago

@glato hey! Sorry I didn't get back to this.

I think it's fine to close this. I'll give it a try this week and get back to you if I find anything 👍 Worst-case scenario: I create a new issue 😁

nicoespeon commented 3 years ago

I gave it a try and it works fine!