DEV Community

Discussion on: Journey into the Minification Abyss: The Peculiar '0' Placeholder

Collapse
 
j4k0xb profile image
j4k0xb

This minute difference allows the transpiler to maintain syntactic coherence in it's rules for transformation which facilitate optimization and compatibility
It's just a placeholder to maintaining syntactic harmony

what? 🤔

The actual reason is to ensure that the receiver/this is undefined when calling. Maybe you meant that but I didnt really see it explained in the article...

// source:
import { sanitize } from 'lib';
sanitize(n.desc) // `this` inside sanitize is undefined

// correct output:
const $ = __webpack_require__(1);
(0, $.sanitize)(n.desc); // `this` inside sanitize is undefined

// wrong output:
const $ = __webpack_require__(1);
$.sanitize(n.desc); // `this` inside sanitize is $ (error?)
Enter fullscreen mode Exit fullscreen mode

Not all functions access this but to avoid analyzing (slow) it gets applied anyways

Real example where transpiling to obj.fn(args) instead of (0, obj.fn)(args) resulted in an error: github.com/es-shims/Promise.allSet...

Collapse
 
js_bits_bill profile image
JS Bits Bill

@j4k0xb, thank you so much for this explanation. My interpretation was way too vague so I really appreciate your insight! I've edited this article with hopefully a better explanation.