Skip to content

Commit

Permalink
fixup! feat(scripts): Add esbench
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed May 16, 2024
1 parent e95bb2e commit 20b4d24
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/esbench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,16 @@ const spawnKit = async ([cmd, ...args], { input, ...options } = {}) => {
};

const toSource = (value, space) =>
// Rely on JSON.stringify, but replace `"__proto__"` property names
// with computed equivalent `["__proto__"]` and make all objects
// null-prototype (ensuring that absent fields are undefined).
JSON.stringify(value, undefined, space)
// Escape "{" in strings, replace "__proto__" with a computed property,
// and make all objects null-prototype (ensuring that absent fields are
// undefined).
// Escape "{" in strings to avoid confusing later replacements.
.replaceAll(/"(\\.|[^\\"])*"/gs, s => s.replaceAll('{', '\\x7B'))
.replaceAll('"__proto__":', '["__proto__"]:')
.replaceAll('{', '{__proto__: null,');
.replaceAll('{', '{__proto__: null,')
// Restore "{".
.replaceAll(/\\x7B|\\./gs, s => (s === '\\x7B' ? '{' : s));

const { makeSimpleError, raiseError } = (() => {
const simpleErrors = new WeakSet();
Expand Down

0 comments on commit 20b4d24

Please sign in to comment.