Effect CommunityEC
Effect Community3y ago
8 replies
WIP

webpack is not mangling @effect/data/mjs/* properly

I investigated the bug I mentioned yesterday (starting a new thread for clarity)

When bundling my minimal divide app for production with webpack, the mangled output failed at runtime with a reference error _a is not defined.

The stack trace points to @effect/data/mjs/internal/Option.mjs:12:5

You can reproduce by cloning https://github.com/geoffreytools/effect-tree-shaking and running npm run build/webpack and npm run debug

Here is an extract from the file
/**
 * @since 1.0.0
 */
var _a, _b;
/* [...] */
export class Some {
  [(_a = EffectTypeId, Equal.symbol)](that) { // <----------------------------here
    return isOption(that) && isSome(that) && Equal.equals(that.i0, this.i0);
  }
 /* [...] */
  constructor(i0) {
    this.i0 = i0;
    this._tag = "Some";
    this._id = TypeId;
    this.i1 = undefined;
    this.i2 = undefined;
    this[_a] = effectVariance; // <------------------------------------------here
  }
  pipe() {
    return pipeArguments(this, arguments);
  }
}

Using [effectTypeId] directly in the constructor in the mjs output solved it
  constructor(i0) {
    this.i0 = i0;
    this._tag = "Some";
    this._id = TypeId;
    this.i1 = undefined;
    this.i2 = undefined;
    this[EffectTypeId] = effectVariance;
  }


This assignment with a coma expression in a computed property is ugly, but it's valid JS so I would say it's a bug in webpack's terser. However, maybe whatever you are using to compile should not do this either
Was this page helpful?