scottrogowski / code2flow

Pretty good call graphs for dynamic languages
MIT License
3.98k stars 295 forks source link

'class fields' in js not supported #53

Closed dhlolo closed 2 years ago

dhlolo commented 2 years ago

'class fields' is common in es6. But it should use acorn plugin, there seems no acorn plugin command line option~ image

scottrogowski commented 2 years ago

I believe what you are looking for is:

--source-type=module

Let me know if that works or if I misunderstood something.

dhlolo commented 2 years ago

I believe what you are looking for is:

--source-type=module

Let me know if that works or if I misunderstood something.

Actually, 'class fields' is a feature that is not included in '--source-type=module'. I noticed the feature needs acorn(javascript AST analyzer) plugin to enable the feature, rather than only acorn basic commands. However, I don't know make it through.

Maybe you can try:

class A {
    methodWork() {}; // this will work.
    methodNotWork = () => {}; // It doesn't work as 'class fields' feature is not supported.
}
scottrogowski commented 2 years ago

Reopening to investigate

scottrogowski commented 2 years ago

I'm understanding the problem better now. Class fields, owing to their newness, are not supported by vanilla acorn and need a plugin. I've confirmed that adding the plugin allows the parser to work whereas there was a syntax error previously.

I'm reluctant to fix this. Using class fields for function definitions doesn't seem common enough to introduce another dependency that would complicate backward compatibility and keep the CLI clean. So I'll have to close this again. Feel free to protest if you think it is, actually, really common