I use private JavaScript class methods in my front-end code and Snowpack for my development workflow.
Currently (as of v2.15.0-pre.5), Snowpack doesn't seem to play well with private class methods, i.e., the following fails to when building with snowpack build
:
export class TestClass {
#test() {
console.log("testing...");
}
test() {
this.#test();
}
}
A repo to reproduce is here. After cloning, run:
npm install
npm run build
I've opened an issue with Snowpack, but apparently the problem lays in the integration with Rollup and the fix isn't a priority.
As far as I understand, to solve it we need:
- a custom Rollup plugin for Snowpack.
- such plugin should use
acornInjectPlugins
to injectacorn-private-methods
.
I wonder if anyone could help with an example of this, before I dive deep into learning Rollup ecosystem?
Or maybe there's another way to make it work?
I'm now back to using _methodName
instead of #methodName
due to time constraints, but I plan to contribute a fix when time allows.
acorn-private-methods
intoacornInjectPlugins
does not appear to work correctly, from my testing. It seems this only applies to the project sources, and not dependencies; this appears consistent with what FredKSchott mentions on the linked GitHub issue: "because mod101 is treated as a dependency, it goes through a different workflow". I think a different approach might be necessary. – Unmovingacorn-private-methods
injection. – Restraintsnowpack.config.js
. It'd be great if you could make it configurable via thepluginOptions
arg, like specifying what exact Acorn plugins to use. – Restraint