Skip to content

Instantly share code, notes, and snippets.

View bathos's full-sized avatar
⚱️
gimme elixir!

Darien Maillet Valentine bathos

⚱️
gimme elixir!
View GitHub Profile
@bathos
bathos / moplogger.js
Created July 6, 2021 15:43
moplogger.js
// This is useful for a few things:
//
// 1. Checking what dictionary options are supported by some platform API.
// 2. Debugging mysterious cases where an object you pass as input to another
// API doesn’t seem to get treated the way you’re expecting.
// 3. When designing another Proxy’s handler implementation, verifying that you
// are accounting for everything correctly and that the intended abstraction
// isn’t leaking in quirky ways.
//
// ex:
@bathos
bathos / consequence-of-constructor-kind-derived.js
Created April 16, 2021 18:18
demonstration of the consequence of whether [[ConstructorKind]] is "base" or "derived"
// CLASS SYNTAX ////////////////////////////////////////////////////////////////
class AFoo {}
class ABar extends AFoo {}
// FUNCTION SYNTAX NEAR-EQUIV //////////////////////////////////////////////////
function BFoo() {
if (!new.target) {
throw new TypeError('Illegal constructor');
@bathos
bathos / acorn-nullish-coalescing-and-optional-chaining.mjs
Created March 18, 2020 13:00
acorn-nullish-coalescing-and-optional-chaining.mjs
export default function acornSkullFishKoalaCaressingAndNonstopSpinalDraining(Parser) {
const tt = Parser.acorn.tokTypes;
const ocToken = new Parser.acorn.TokenType('?.');
const ncToken = new Parser.acorn.TokenType('??', {
beforeExpr: true,
binop: 2.5
});
return class extends Parser {
getTokenFromCode(codePoint) {
@bathos
bathos / observing-last-index-values.js
Created December 30, 2019 21:55
observing-last-index-values.js
function matchAllButUpdateOriginalRegExp(regExp, string) {
return regExp[Symbol.matchAll].call({
constructor: { [Symbol.species]: function() { return regExp; } },
flags: regExp.flags,
lastIndex: regExp.lastIndex
}, string);
}
const pattern = /./g;
@bathos
bathos / home-obj.js
Created December 20, 2019 00:18
home-obj.js
class Foo extends Bar {
method() {
const homeObject = Foo.prototype;
const superReferenceBase = Object.getPrototypeOf(homeObject);
}
static method() {
const homeObject = Foo;
const superReferenceBase = Object.getPrototypeOf(homeObject);
}
@bathos
bathos / escape-eight-and-nine.md
Last active December 12, 2019 07:38
escape-eight-and-nine.md

Trying to understand what accounts for "\8" and "\9" being considered valid string literals with identity escapes in Chrome and FF.

Annex B permits sloppy mode to include legacy octal escapes in strings. It achieves this by replacing the ‘normal’ (strict) EscapeSequence production with a new version accompanied by three new productions.

In the sloppy version, three of the alternatives are the same. The change is replacing this rule:

"0" [lookahead ∉ DecimalDigit]

@bathos
bathos / weekdata.mjs
Last active December 7, 2019 14:08
/util/date/weekdata.mjs
import range from '/util/iterator/range.mjs';
// Week start data pulled from similarly golfed answer on SO:
// https://stackoverflow.com/a/57102881/1631952
//
// I’m not thrilled with this; we probably ought to be generating it since the
// data is pretty obscure. OTOH I’d be far less thrilled with loading hefty
// chunks of ICU data and this is pretty solid and compact!
//
// Note that the RegExp given for lang tags in that answer is a bit off. The one
@bathos
bathos / throwing-into-iterated-async-gen.js
Created December 1, 2019 21:36
throwing-into-iterated-async-gen.js
void async function() {
const asyncGenerator = async function *() { try { yield; } catch {} }();
try {
for await (const value of asyncGenerator) {
await asyncGenerator.throw(new Error);
}
console.log('caught');
} catch {
@bathos
bathos / function-types-kinda.md
Created April 8, 2018 06:15
function-types-kinda.md
FK Cstr TM: Lexical TM: Global / Strict
normal cstr - function() {}; new Function
normal no () => {} x() {}
classConstructor cstr - class {}
classConstructor no - -
generator cstr - -
generator no - function * () {}; * x() {}
async cstr - -
async no async () => {} async function() {}; async x() {}
@bathos
bathos / strings.md
Last active March 22, 2018 02:32
strings.md

When Strings Attack

The Enduring Legacy of a Very Naughty Hack from 1995 / A Bit of Intl

This is my first attempt at a tech talk thing. The focus here is strings in ES. First we’ll talk about what a string is in ES, then some of the consequences that fall out of that (a few aren’t super obvious), and finally some of the cool tools available for working with strings safely & effectively. Because of the nature of the subject we’ll also get into some more general information about Unicode, encodings and broad concepts related to strings and language.