-
-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Private name "#errorHandler" must be declared in an enclosing class #3673
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3673 +/- ##
==========================================
- Coverage 91.70% 91.69% -0.01%
==========================================
Files 159 159
Lines 10145 10149 +4
Branches 2851 2879 +28
==========================================
+ Hits 9303 9306 +3
- Misses 840 841 +1
Partials 2 2 ☔ View full report in Codecov by Sentry. |
@TiBianMod Thanks!
Does it throw an error? If so, can you share the minimal code to reproduce it? |
@yusukebe Thanks, please checkout https://github.com/TiBianMod/3673-reproduction but like i set, |
Thanks. But can you share the code without an external library? |
As you said, |
From the document, there is no problem with the current code, as the JavaScript specification allows access to private properties of other instances of the same class within the class. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties |
@yusukebe yes is weird, (i tried some tests but no luck) for me you can merge this PR (is totally safe and valid) |
@yusukebe try this with
function errorHandler() {}
class Hono {
#errorHandler = errorHandler;
}
const app = new Hono();
function route(app) {
if (app.#errorHandler === errorHandler) {
//
}
}
route(app); |
Hi @TiBianMod. Thank you for the explanation. The However, before #3596, the transpiler was exporting Given this situation, although #3596 contains a change that is effectively incompatible, |
@usualoma Thanks for the information! @TiBianMod Can we close the issue and this PR? |
sure |
All our tests pass. Please share your test codes that fail. |
If '#' is bad, we can implement using 'private'. |
We suppose you could use private in the code and prefix it at build time for readability and all that (#3673 (comment)), but that might be overkill. |
The code above throws an error since it access Private means that only the class itself uses it... |
@yusukebe reproduction repo It is related to the fact that the inner Hono app is exported with |
@yusukebe can I reopen the PR? |
@TiBianMod I have ideas. Please wait a bit! |
This PR fixes #3671
on
hono-base.ts
theroute
method acceptsapp: Hono<SubEnv, SubSchema, SubBasePath>
, so when using theapp
instance we don't have access on private methods.before the
errorHandler
propery wasprivate errorHandler
(only valid on typescript) but now is#errorHandler
, so is not accessible anymore.related: #3596
The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code