Closed dhlolo closed 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.
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.
}
Reopening to investigate
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
'class fields' is common in es6. But it should use acorn plugin, there seems no acorn plugin command line option~