Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

convert global objects falsely if they are exported  #84

@xiechao06

Description

@xiechao06

take package gloabl for example:

// file: document.js
var topLevel = typeof global !== 'undefined' ? global :
    typeof window !== 'undefined' ? window : {}
var minDoc = require('min-document');

if (typeof document !== 'undefined') {
    module.exports = document;
} else {
    var doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];

    if (!doccy) {
        doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
    }

    module.exports = doccy;
}

when using in browser, the object document actually is window.document, but since it is exported, the last snippet is converted to (notice document is changed to document$1):

var document$1 = createCommonjsModule(function (module) {
    var topLevel = typeof commonjsGlobal !== 'undefined' ? commonjsGlobal :
        typeof window !== 'undefined' ? window : {}
    var minDoc = interopDefault(require$$0$18);

    if (typeof document$1 !== 'undefined') {
        module.exports = document$1;
    } else {
        var doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];

        if (!doccy) {
            doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
        }

        module.exports = doccy;
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions