3 ms·
It's nice, but the downside is that relying on TCO can make your Bun-tested code unexpectedly break with stack overflow error if it ever gets run on Deno or Nod
by imjonse 3y ago
It's nice, but the downside is that relying on TCO can make your Bun-tested code unexpectedly break with stack overflow error if it ever gets run on Deno or Node. So probably a good idea to comment this part of the code and make sure if it's in a library to similarly warn the callers somehow.
- bryancoxwell 3y agoDoes serverside JS have anything similar to #ifdef?
- antipurist 3y agoSomething like if ('Bun' in globalThis) ... if ('Deno' in globalThis) ... if ('window' in globalThis) ... could be used to determine the runtime.
- timw4mail 3y agoThat certainly works for Bun and Deno, not sure about what is effective in Node, though.
- basil-rash 3y agoChecking for process.versions.{node,bun} works, not sure if Deno has an equivalent.
- deleted 3y ago[deleted]
- vlovich123 3y agoYes. You can define a constant (eg IS_SERVER) which your bundler (eg esbuild) replaces with a specific value depending on what environment you’re targeting. There are also ways to detect it using runtime globals that are only defined within the browser although that can be monkeypatched by your own code or 3p libraries you import (not common but could be a compat layer you add to make server side JS behave more like a browser).
- quickthrower2 3y agoYes the O is more than an Optimisation, it is a change in semantics.