{"id":19186,"library":"babel-plugin-transform-decorators-legacy","title":"Babel Legacy Decorator Plugin","description":"A Babel 6 plugin that replicates the legacy decorator behavior from Babel 5, allowing migration to Babel 6 without dropping decorators. Version 1.3.5 is the latest stable release; no longer maintained. For Babel 7+, use @babel/plugin-proposal-decorators with legacy: true. Key difference: decorators evaluate top-to-bottom and execute bottom-to-top (spec-compliant), unlike Babel 5's reverse order. Also handles static property initializers differently.","status":"maintenance","version":"1.3.5","language":"javascript","source_language":"en","source_url":"https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy","tags":["javascript","babel","babel-plugin","es7","decorators"],"install":[{"cmd":"npm install babel-plugin-transform-decorators-legacy","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-decorators-legacy","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-decorators-legacy","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires Babel 6.x as a peer dependency","package":"babel-core","optional":false}],"imports":[{"note":"In .babelrc or babel config, use the short plugin name without the 'babel-plugin-' prefix.","wrong":"plugins: [\"babel-plugin-transform-decorators-legacy\"]","symbol":"plugin","correct":"plugins: [\"transform-decorators-legacy\"]"},{"note":"For Babel 7+, use this official plugin with legacy: true to get the same behavior as transform-decorators-legacy.","wrong":"plugins: [\"@babel/plugin-proposal-decorators\"]","symbol":"@babel/plugin-proposal-decorators (legacy)","correct":"plugins: [[\"@babel/plugin-proposal-decorators\", { legacy: true }]]"},{"note":"This plugin is intended for Babel 6 which uses CommonJS. ESM imports are not supported in Babel 6 context.","wrong":"import plugin from 'babel-plugin-transform-decorators-legacy'","symbol":"require('babel-plugin-transform-decorators-legacy')","correct":"const plugin = require('babel-plugin-transform-decorators-legacy')"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"transform-decorators-legacy\"]\n}\n\n// Ensure order: decorators before class properties\n// Correct:\n{\n  \"plugins\": [\n    \"transform-decorators-legacy\",\n    \"transform-class-properties\"\n  ]\n}\n\n// Example usage\nfunction log(target, name, descriptor) {\n  const original = descriptor.value;\n  descriptor.value = function(...args) {\n    console.log(`Calling ${name} with`, args);\n    return original.apply(this, args);\n  };\n  return descriptor;\n}\n\nclass Example {\n  @log\n  greet(name) {\n    return `Hello, ${name}`;\n  }\n}\n\nconst ex = new Example();\nex.greet('World'); // logs: Calling greet with ['World']","lang":"javascript","description":"Shows correct Babel config, plugin ordering, and a simple decorator usage for logging."},"warnings":[{"fix":"Replace with @babel/plugin-proposal-decorators and set legacy: true in Babel config.","message":"Babel 7+ users must use @babel/plugin-proposal-decorators with legacy: true; this plugin does not work with Babel 7.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Place transform-decorators-legacy before transform-class-properties in the plugins array.","message":"Plugin ordering matters: transform-decorators-legacy must come before transform-class-properties.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Migrate to Babel 7 and use @babel/plugin-proposal-decorators with legacy: true or adopt the new decorator spec.","message":"This plugin is not maintained for Babel 6 and will not receive updates; the decorator proposal has evolved.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Adjust code that depends on evaluation order; this behavior matches the spec.","message":"Decorator evaluation order differs from Babel 5: later decorators evaluate first (top-to-bottom), but execute in reverse (bottom-to-top).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not rely on initializer being called multiple times for side effects.","message":"Static class property initializers are evaluated once and cached; initializer returns precomputed value, not re-executed on each access.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install babel-plugin-transform-decorators-legacy and add it to .babelrc plugins.","cause":"Using Babel 6 without proper plugin enabled or using Babel 7's syntax without the plugin.","error":"Error: [BABEL] unknown: Decorators are not supported yet in 6.x."},{"fix":"Reorder plugins so transform-decorators-legacy comes first.","cause":"Incorrect plugin ordering: transform-class-properties runs before transform-decorators-legacy.","error":"TypeError: Cannot read property 'value' of undefined"},{"fix":"Ensure babel-core version 6.x is installed and use the short plugin name 'transform-decorators-legacy'.","cause":"Using an outdated Babel 6 version or incorrect import path.","error":"ReferenceError: [BABEL] unknown: Plugin/Preset files are not allowed to export objects, only functions."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}