Skip to content

Instantly share code, notes, and snippets.

@jacob-ebey
Last active November 7, 2024 08:09
Show Gist options
  • Save jacob-ebey/1dffca6200440acfd0bed83e16e2b969 to your computer and use it in GitHub Desktop.
Save jacob-ebey/1dffca6200440acfd0bed83e16e2b969 to your computer and use it in GitHub Desktop.
function* iterable() {
yield 1;
yield 2;
}
async function* asyncIterable() {
yield 1;
yield 2;
}
const subinput = [
{ a: "a value 1", b: "b value" },
{ c: "c value", a: "a value 2" },
];
const nullObj = Object.create(null);
nullObj.a = "a value";
const input = [
subinput,
"d",
"e",
null,
nullObj,
new Test("f"),
new Date(),
Promise.resolve({ p: "1" }),
Promise.resolve(iterable()),
Promise.resolve(asyncIterable()),
Promise.resolve(BigInt("42")),
Promise.resolve(Symbol.for("42")),
];
// find: ^<(\$[PE]?\d+)>
// replace: const $1 = <$1>
const $1 = <$1>[
<$2>[
<$3>{ a: "a value 1", b: "b value" },
<$4>{ c: "c value", a: "a value 2" },
],
"d",
"e",
null,
<$5$null>(<$5>{ a: "a value" }),
<$6>{ a: "f" },
<$7$Date$>(<$7>{ iso: "2024-11-07T08:07:46.903Z" }),
$P8,
$P9,
$P10,
$P11,
$P12,
];
const $P8 = <$P8>(<$13>{ p: "1" });
const $P9 = <$P9>(<$14>[1, 2]);
const $P10 = <$P10>(<$15$AsyncIterable$>(<$15>{ next: $P16 }));
const $P11 = <$P11>(<$17$BigInt$>(<$17>{ value: "42" }));
const $P12 = <$P12>(<$18$Symbol$>(<$18>{ key: "42" }));
const $P16 = <$P16>(<$19>{ value: 1, next: $P20 });
const $P20 = <$P20>(<$21>{ value: 2, next: $P22 });
const $P22 = <$P22>(<$23>{});
<$1>[<$2>[<$3>{"a":"a value 1","b":"b value"},<$4>{"c":"c value","a":"a value 2"}],"d","e",null,<$5$null><$5>{"a":"a value"},<$6>{"a":"f"},<$7$Date$><$7>{"iso":"2024-11-07T08:07:46.903Z"},$P8,$P9,$P10,$P11,$P12]
<$P8><$13>{"p":"1"}
<$P9><$14>[1,2]
<$P10><$15$AsyncIterable$><$15>{"next":$P16}
<$P11><$17$BigInt$><$17>{"value":"42"}
<$P12><$18$Symbol$><$18>{"key":"42"}
<$P16><$19>{"value":1,"next":$P20}
<$P20><$21>{"value":2,"next":$P22}
<$P22><$23>{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment