microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.26k stars 128 forks source link

[BUG] __importStar will cause the properties on the prototype chain to be lost #58

Closed acrazing closed 4 years ago

acrazing commented 6 years ago

This function is declared at https://github.com/Microsoft/tslib/blob/master/tslib.js#L212-L217 .

Why not use __importDefault at https://github.com/Microsoft/tslib/blob/master/tslib.js#L220-L222 ?

This bug could be reproduce by eval import("raven-js"), because its exports is an is an object with custom prototype.

gogoyqj commented 5 years ago

same issue -

using babel _interopRequireWildcard instead works

function _interopRequireWildcard(obj) {
  if (obj && obj.__esModule) {
    return obj;
  } else {
    var newObj = {};
    if (obj != null) {
      for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc =
            Object.defineProperty && Object.getOwnPropertyDescriptor
              ? Object.getOwnPropertyDescriptor(obj, key)
              : {};
          if (desc.get || desc.set) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }
    }
    newObj.default = obj;
    return newObj;
  }
}