-
Notifications
You must be signed in to change notification settings - Fork 28
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
Expose _repr_
in non-debug builds
#227
Comments
Once Temporal ships natively in browsers (I expect this to happen later this year or early 2024) then presumably browsers' debug consoles will natively expose more useful debug console output, much like they do for For polyfills, the goal is to mirror the spec exactly, so exposing
I'm admittedly unfamiliar with whether there's a better way to do this. If you have ideas, especially those that won't change the observable properties and methods of objects, we're open to it. |
Hmm, makes sense. For now I'm using this wrapper in Deno — similar would work for Node but with import { Temporal } from 'https://esm.sh/@js-temporal/[email protected]'
for (const k of [
'Instant',
'Calendar',
'PlainDate',
'PlainDateTime',
'Duration',
'PlainMonthDay',
'PlainTime',
'TimeZone',
'PlainYearMonth',
'ZonedDateTime',
] as const) {
const prototype = (Temporal[k]).prototype as any
prototype[Symbol.for('Deno.customInspect')] = function() {
return `\x1b[36m${this[Symbol.toStringTag]} <${this.toString()}>\x1b[0m`
}
}
export { Temporal } I can't think of anything similar that'd work in browser consoles, though, as they'll only show non-computed properties, and it's not possible to overwrite a class's constructor... unless unique symbols don't count as "observable" for this purpose? In which case it'd be trivial for the library to expose a unique const reprSymbol = Symbol('_repr_')
class X { [reprSymbol] = 'xyz' }
console.log(new X())
// logs something similar to "X { [Symbol(_repr_)]: 'xyz' }" in all of Chrome, FireFox, Deno, Node, etc |
Your PR #226 seemed fine for the purpose of getting custom logging working in Deno? Or is the problem that it needs to work in non-debug builds? In the proposal's browser playground we define
|
To clarify our current build setup: nothing we publish to NPM (sans a maintainer error when publishing) would include debug code as that is optimized out before publishing. If you are debugging your code using local builds, you could instead locally link to our sources and create a local debug build of your project by cloning the repo and using
More steps to follow, but this procedure works for any NPM package with nothing specific to this project. |
Yeah, I figured it won't work for my use case as I'm using Node when contributing to the library, whereas when I'm consuming it in Deno I import from an esm.sh URL that builds from the NPM version. It's true that I can compile my own version with a different |
Now I think about it, wouldn't a private field fulfil this requirement? There's no way to access them from outside the class itself, including in derived classes. Problem is Babel compiles them to a Private fields also won't show up for Node/Deno logging in the terminal (but will show up when inspecting Node/Deno processes in dev tools). |
The private field idea sounds nice - it'd provide at least some sort of insight into the object in non-debug builds, at least if you were using devtools. |
Currently, logging
Temporal
objects imported via the npm module in Node or via esm.sh in the browser, Deno, etc. yields pretty unhelpful results:Exposing
_repr_
on non-debug builds would massively improve this experience:Cost to bundle size is ~2k uncompressed. Would this be acceptable? Or is there some other way the logging/debugging output could be improved?
The text was updated successfully, but these errors were encountered: