fuhrmanator / FamixTypeScriptImporter

MIT License
2 stars 1 forks source link

How to handle CommonJS modules, e.g. `import foo = require('foo');` ? #46

Open fuhrmanator opened 1 year ago

fuhrmanator commented 1 year ago

See #35 (CommonJS lazy-loading case)

import foo = require('foo'); results in an identifier foo: any. How should we represent this in Famix? A NamedEntity doesn't have a type. A Module is not quite the same as a CommonJS module (which is like a black box to some degree).

A solution could be to create CommonJSModule someplace (under StructuralEntity or under NamedEntity?) which allows for a Type definition, and when the parser encounters import x = require('blah') we just make an instance of this CommonJSModule with a type any.

CommonJSModule would not have a lot of info in Famix, but perhaps we can see the dependencies through ImportClauses.

I am thinking with AMD modules we could also do a similar thing. However, AMD doesn't always use import syntax, so I'm not sure it's easy to support.