nevware21 / ts-utils

Common JavaScript functions for TypeScript
MIT License
4 stars 1 forks source link

[Bug] getInst() function is getting mis-optimized for a worker with rollup #302

Closed nev21 closed 1 month ago

nev21 commented 3 months ago

The getInst() function is getting mis-optimized via rollup / karma for worker tests in another (as yet) unpublished project (ts-debug)

function getInst(name, useCached) {
    if (name === WINDOW) {
        return getWindow();
    }
    return NULL_VALUE;
}

from

export function getInst<T>(name: string | number | symbol, useCached?: boolean): T | null {
    const gbl = (!_cachedGlobal || useCached === false) ? getGlobal(useCached) : _cachedGlobal.v;
    if (gbl && gbl[name]) {
        return gbl[name] as T;
    }

    // Test workaround, for environments where <global>.window (when global == window) doesn't return the base window
    if (name === WINDOW) {
        // tslint:disable-next-line: no-angle-bracket-type-assertion
        return <any>getWindow() as T;
    }

    return NULL_VALUE;
}