A Babel plugin that transforms function parameter decorators to behave like TypeScript parameter decorators. Current stable version is 1.0.16, with infrequent releases. It enables parameter decorators on constructor parameters and method parameters when using Babel with legacy decorator support. Unlike TypeScript's built-in support, this plugin requires the separate `@babel/plugin-proposal-decorators` with `legacy: true` and optionally `@babel/plugin-proposal-class-properties`. It is the only dedicated Babel plugin for parameter decorator transformation as of 2024, filling a gap left by other decorator plugins. Works with both JavaScript and TypeScript via Babel presets.
npm install babel-plugin-parameter-decoratorVerified import paths — ran on the pinned version, not inferred.
Shows how to install, configure Babel with plugin-proposal-decorators (legacy mode) and this plugin, and then transpile a class with parameter decorators.
Ensure order: [['@babel/plugin-proposal-decorators', {legacy: true}], 'babel-plugin-parameter-decorator']Set 'onlyRemoveTypeImports' to true in preset options: ['@babel/preset-typescript', { onlyRemoveTypeImports: true }]Use legacy: true (the Stage 1 decorators proposal).
Add ["@babel/plugin-proposal-decorators", { "legacy": true }] before babel-plugin-parameter-decorator.Ensure a method decorator writes the metadata that the parameter decorator expects; example uses @validate.
Define parameter decorator correctly: function decorator(key) { return function(target, propKey, paramIndex) { ... }; }