In my front-end development, I utilize private JavaScript class methods and Snowpack for my workflow.
Unfortunately, I've encountered an issue with Snowpack (as of v2.15.0-pre.5) not supporting private class methods. When trying to build using snowpack build
, the following code fails:
export class TestClass {
#test() {
console.log("testing...");
}
test() {
this.#test();
}
}
To reproduce the issue, you can visit the repository here. After cloning, run:
npm install
npm run build
I have reported this issue to Snowpack, but it seems that the problem lies in its integration with Rollup and is not currently a priority for fixing.
To address this, it appears that we need:
- a custom Rollup plugin for Snowpack.
- this plugin should utilize
acornInjectPlugins
to injectacorn-private-methods
.
I am seeking assistance or example of how to implement this before delving deep into learning the Rollup ecosystem. Are there any alternative solutions available?
For now, due to time constraints, I have resorted back to using _methodName
instead of #methodName
. However, I do plan on contributing a fix once time permits.