Hacker News new | ask | show | jobs
by vundercind 780 days ago
> JavaScript has lots of wacky problems but its main advantage to me was the loosy goosy approach to types.

It runs in the browser. That’s always been its only advantage. Even now that it’s much better than it used to be: still true.

> Not sure why nobody built something like reentrent exceptions or cool stuff like that, instead they built a stupid jail that down compiles to unreadable sludge.

TIL machine-readable and -verifiable versions of the documentation you should be writing anyway (but probably aren’t) is a jail.

Also one of the reasons I didn’t worry about it going the way of other compile-to-JS languages is that it’s output is nearly identical to what I would have written anyway, so it’s got a clean and easy “escape hatch”. But maybe I write unreadable sludge.

1 comments

I've had it generate some verbose stuff when using .?, along these lines:

    (_c = this.log) === null || _c === void 0 ? void 0 : _c.withIndent('    ', () => {
        var _a;
        // (pointless ?. silence eslint)
        (_a = this.log) === null || _a === void 0 ? void 0 : _a.pn(`Buffer address: 0x${utils.hex8(bufferAddress)} `);
    });
This was originally this:

    this.log?.withIndent('    ', () => {
        // (pointless ?. silence eslint)
        this.log?.pn(`Buffer address: 0x${utils.hex8(bufferAddress)} `);
    });
If you have a long chain of ?., perhaps it gets really ugly.
It's just downleveling the syntax so it runs in browsers that are too old to support `?.` (similar to what Babel would do). If you set your compile target to es2020 or later it will emit `?.` verbatim.
Oh no, they’ve added more features JS doesn’t actually support. Enums were one thing, this was… an extremely bad idea. I hope it’s not a sign they’re gonna move farther into being a separate language.

[edit] oh no wait that’s in newer JS versions, you’re just “compiling” to a version that doesn’t support it. Update your target to a version that supports the feature you used and it should be fine.

Right - if you use a language feature that is newer than your compile target, it will compile down 'modern' syntax like that. I'm not sure what else you would expect.
The discussion topic was cases where the js output includes a bunch of extra junk, so this is just intended as an example of that! Mostly the output looks pretty much like the input.

(The compile target in my case is ES2017, as configured in August 2018. I can probably update that.)