rslib icon indicating copy to clipboard operation
rslib copied to clipboard

[Bug]: No export when export function with eval usage

Open Timeless0911 opened this issue 1 year ago • 1 comments

Before

Source

export function add(a: number, b: number) {
  return a + b;
}

Output

function add(a, b) {
    return a + b;
}
export { add };

Current

If we use eval in a function

Source

export function add(a: number, b: number) {
  return a + b;
}

export function evalFunc() {
  return eval('1');
}

Output

// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(exports, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
// webpack/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
// webpack/runtime/make_namespace_object
(()=>{
    // define __esModule on exports
    __webpack_require__.r = function(exports) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports, '__esModule', {
            value: true
        });
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    add: function() {
        return add;
    },
    evalFunc: function() {
        return evalFunc;
    }
});
function add(a, b) {
    return a + b;
}
function evalFunc() {
    return eval('1');
}

Timeless0911 avatar Nov 25 '24 06:11 Timeless0911

Currently, entry module is required to be concatenated, eval will break the premise.

fi3ework avatar Nov 27 '24 09:11 fi3ework

Workaround: https://github.com/web-infra-dev/rslib/issues/1206#issuecomment-3257639818

Timeless0911 avatar Sep 05 '25 09:09 Timeless0911

Advanced ESM output

import { __webpack_require__ } from "./runtime.js";
__webpack_require__.add({
    "./src/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
        __webpack_require__.d(__webpack_exports__, {
            L: ()=>evalFunc,
            W: ()=>add
        });
        function add(a, b) {
            return a + b;
        }
        function evalFunc() {
            return eval('1');
        }
    }
});
const src = __webpack_require__("./src/index.ts");
var W = src.W;
var L = src.L;
export { L as evalFunc, W as add };

The issue has been solved.

Timeless0911 avatar Oct 30 '25 08:10 Timeless0911