Skip to content

ensureDisposeSymbols

Makes Symbol.dispose and Symbol.asyncDispose exist, falling back to the registry symbols esbuild’s using helpers look up.

Serialized into the emitted banner. A disposable declares its method under the LITERAL key [Symbol.dispose], while esbuild lowers every using to a lookup through __knownSymbol('dispose'), which falls back to Symbol.for('Symbol.dispose') when the engine has no well-known symbol. On such an engine the literal key evaluates to undefined, the method lands under the string "undefined", and every using of it throws Object not disposable. Filling the well-known slot with that same registry symbol makes both sides name one key on every engine. A host that already has the symbol is left untouched: ??= never reaches the assignment, which the host’s non-writable property would refuse.

The default names Symbol bare on purpose: it exists on every engine this runs on, and a bare reference resolves against whatever scope the banner is evaluated in, exactly as the bundle’s own [Symbol.dispose] keys do.

Import:

import { ensureDisposeSymbols } from 'obsidian-dev-utils/script-utils/bundlers/esbuild-impl/preprocess-plugin';

Signature:

function ensureDisposeSymbols(symbolConstructor: DisposeSymbolHost): void

Parameters:

Parameter Type Description
symbolConstructor DisposeSymbolHost The Symbol constructor to patch. Defaults to the ambient one; the parameter exists so a test can hand in an engine that lacks the well-known symbols.

Returns: void