borisdiakur / memoize-fs

memoize/cache in file system solution for Node.js
https://www.npmjs.org/package/memoize-fs
MIT License
36 stars 13 forks source link

Do not minify (mangle) identifiers in bundle #271

Closed joliss closed 6 months ago

joliss commented 6 months ago

Without this, we get the following in dist/index.js:

const x1 = {
  0: "Unexpected token",
  // ...
};
class I2 extends SyntaxError {
  constructor(i, n, e, t, ...o) {
    const l = "[" + n + ":" + e + "]: " + x1[t].replace(/%(\d+)/g, (f, c) => o[c]);
    super(`${l}`), this.index = i, this.line = n, this.column = e, this.description = l, this.loc = {
      line: n,
      column: e
    };
  }
}

With this change, we get

const errorMessages = {
  0: "Unexpected token",
  // ...
};
class ParseError extends SyntaxError {
  constructor(startindex, line, column, type, ...params) {
    const message = "[" + line + ":" + column + "]: " + errorMessages[type].replace(/%(\d+)/g, (_, i) => params[i]);
    super(`${message}`), this.index = startindex, this.line = line, this.column = column, this.description = message, this.loc = {
      line,
      column
    };
  }
}

This should make for better error messages, as we aren't limited by bandwidth in Node.