A Babel plugin that converts JSDoc type annotations (@param and @type) into runtime assertion statements (console.assert) for testing. Version 4.0.0 is the current stable release, requiring Babel 7+. The plugin transforms static type documentation into executable checks, enabling runtime verification without a separate type system. Unlike TypeScript or Flow, it operates at the AST level during Babel transpilation and supports generic arrays (e.g., number[]) and rest parameters. Its primary differentiator is seamless integration into Babel workflows for development-only assertions, with options to enable/disable @param and @type checking. The package is maintained by azu and has a preset version (babel-preset-jsdoc-to-assert). Releases are infrequent, focusing on compatibility and bug fixes.
npm install babel-plugin-jsdoc-to-assertVerified import paths — ran on the pinned version, not inferred.
Shows .babelrc configuration, environment-specific usage, and the runtime assertion transformation for @param types.
Upgrade to Babel 7 and ensure @babel/core is installed.
Set checkAtType: true only if plugin runs before ES2015 transforms (e.g., via plugin ordering). Consider using babel-preset-jsdoc-to-assert.
Use babel-preset-jsdoc-to-assert with useSpecReporter option for throwing assertions.
Upgrade to v4.0.0 for Babel 7 compatibility.
Ensure source files are syntactically valid JavaScript. If error persists, file an issue with code sample.
Fix the syntax error in the source file. If the error is not reproducible without the plugin, file an issue on GitHub.
Disable checkAtType or use babel-preset-jsdoc-to-assert which handles ordering. Alternatively, ensure plugin runs after ES2015 transforms.
Polyfill console or consider using babel-preset-jsdoc-to-assert with useSpecReporter which uses assert instead.