internal-docs/guides/development/debug-assertions.md
Glimmer VM uses debug assertion functions to validate assumptions and catch errors during development. These functions are essential for maintaining code quality but must never appear in published packages.
The following functions from @glimmer/debug are for local development only:
check(value, checker) - Validates a value against a type checker (e.g., CheckReference, CheckString)expect(value, message) - Throws with message if value is falsylocalAssert(condition, message) - Throws with message if condition is falseunwrap(value) - Returns value if truthy, throws if null/undefinedrecordStackSize() - Records stack size for debugging (completely removed in builds)import { check } from '@glimmer/debug';
import { CheckReference, CheckCapturedArguments } from './-debug-strip';
// In your VM opcode implementation:
let definition = check(stack.pop(), CheckReference);
let capturedArgs = check(stack.pop(), CheckCapturedArguments);
// Type checkers validate specific shapes:
// CheckReference - validates the value is a Glimmer Reference
// CheckCapturedArguments - validates captured arguments structure
These debug calls are automatically stripped from all builds using a Babel plugin. The transformation works as follows:
let value = check(stack.pop(), CheckReference);
let value = stack.pop();
The build system automatically removes all debug assertions:
@glimmer/local-debug-babel-plugin) runs during build@glimmer/debugThis ensures that while developers can use these assertions freely during development, end users never pay the cost of these checks in any published builds.