endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
829 stars 72 forks source link

bug(static-module-record): invalid transformation #1805

Open kumavis opened 1 year ago

kumavis commented 1 year ago

I found a transformation failure in static-module-record

I encountered an issue when executing a compartment-mapper bundle of the following esm file. The original seems to be compiled output from a typescript Enum.

before transform

// src/ApiError.ts
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
  ErrorCode2[ErrorCode2["EPERM"] = 1] = "EPERM";
  // ...
  return ErrorCode2;
})(ErrorCode || {});
// ...
export {
  // ...
  ErrorCode,
  // ...
}

after transform

// src/ApiError.ts
var $c‍_ErrorCode=/* @__PURE__ */((ErrorCode2)=> {
  ErrorCode2[ErrorCode2["EPERM"]=  1]=  "EPERM";
  // ...
  return ErrorCode2;
 })(ErrorCode|| {});ErrorCode=$c‍_ErrorCode;

causing ReferenceError: ErrorCode is not defined

kumavis commented 1 year ago

Here's a failing test for static-module-record https://github.com/endojs/endo/pull/1806/commits/efabcda3d6ad9fefb7aeb8f320ad0795e555ed21