Compiler assumptions
babel.dev
babel.dev
Of course, I would still feel pretty nervous turning these on in a large multi-dev codebase unless some corresponding linter rules were also in place.
Except when you’re doing them by mistake, or because a dependency happened to be clever and you missed it.
See also: UB in every C and C++ code base.
Most of these are pretty hard to do by accident... I didn't even know about maybe a third of these things, and I've been writing JavaScript for 10 years
A significant exception to all of the generalizations I've been making is iterableIsArray:
> When using an iterable object (in array destructuring, for-of or spreads), assume that it is an array.
Violating this one is neither an anti-pattern nor hard to do by accident. It would mean a significant shift in practices for a project, and it would have to allow for some really exceptional optimizations if I were going to even consider enabling it
- Jurassic Park. Also, what I think about every time I learn about a "feature" of javascript (like all of the examples in this post) that allows you to do things that would cause any other compiler developer to laugh you out of the room.
I'm assuming if you're writing Babel plugins maybe you want to turn some of these features off so you can make it do alternative behaviour?
Also, a lot of compilers have ways to enable normally unsafe transformations: in sbcl, for example, if you (declare (safety 0)), the compiler will just automatically trust your type declarations and generate machine code that is unsafe if this assumption isn’t true: it’s useful because sometimes “correct” behavior has an unacceptable performance cost.