Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It does seem that the unminified code is very close to the original. In some cases ChatGPT even did its own refactoring in addition to the unminification:

    // ORIGINAL:
    j.useEffect(() => {
        function r() {
            n({ height: window.innerHeight, width: window.innerWidth });
        }
        if (typeof window < "u") return n({ height: window.innerHeight, width: window.innerWidth }), window.addEventListener("resize", r), () => window.removeEventListener("resize", r);
    }, []),

    // UNMINIFIED:
    useEffect(() => {
      const handleResize = () => {
        setSize({ height: window.innerHeight, width: window.innerWidth });
      };

      // Initial size setting
      handleResize();

      window.addEventListener('resize', handleResize);
      return () => {
        window.removeEventListener('resize', handleResize);
      };
    }, []);
Note that the original code doesn't call `handleResize` immediately, but have its contents inlined instead. (Probably the minifier did the actual inlining.) The only real difference here is a missing `if (typeof window < "u")` condition.


the condition is a constant so it can be safely removed


Only in the web environment. In fact the condition itself is true only when it runs in a web browser and not in a web worker.


which is the case for that code and it was added by the obfuscator


No obfuscator would add only that. It is almost surely from some library that is aware of the possibility that `window` may not exist.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: