{"id":19182,"library":"babel-plugin-transform-class-constructor-call","title":"babel-plugin-transform-class-constructor-call (deprecated)","description":"This deprecated Babel plugin (v6.24.1, last release 2017) transforms the withdrawn TC39 proposal for call constructor syntax in ES2015 classes. It allows a class to have a 'call constructor' that is invoked when the class is called without 'new', enabling patterns like Date() returning a string while new Date() returns an instance. The proposal was withdrawn and is superseded by decorators. This plugin is part of Babel v6 era and is not compatible with Babel v7+. Developers should not use it in new projects; instead, use modern patterns like static methods or decorators.","status":"deprecated","version":"6.24.1","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-class-constructor-call","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-transform-class-constructor-call","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-class-constructor-call","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-class-constructor-call","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires Babel core v6 to load and run the plugin; not compatible with Babel v7+.","package":"@babel/core","optional":false}],"imports":[{"note":"The plugin is a Babel plugin, not a direct JavaScript import. Use it via Babel configuration.","wrong":"npm install --save-dev babel-plugin-transform-class-constructor-call","symbol":"plugin","correct":"// .babelrc\n{ \"plugins\": [\"transform-class-constructor-call\"] }"},{"note":"Babel v6's core package is 'babel-core' (not @babel/core) and uses CommonJS. Using ESM imports may fail.","wrong":"import { transform } from 'babel-core'; // Babel v6 uses CommonJS, not ESM","symbol":"require('babel-core')","correct":"const babel = require('babel-core');\nbabel.transform(code, { plugins: ['transform-class-constructor-call'] });"},{"note":"The 'call constructor' syntax is non-standard and only works with this plugin. It is not part of any ES spec.","wrong":"// No call constructor; this is the only valid syntax for this plugin","symbol":"class with call constructor","correct":"class Point {\n  constructor(x, y) { this.x = x; this.y = y; }\n  call constructor(x, y) { return new Point(x, y); }\n}"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-transform-class-constructor-call\n// .babelrc\n{\n  \"plugins\": [\"transform-class-constructor-call\"]\n}\n\n// Example usage in code.js\nclass Date {\n  constructor() {\n    this.date = new Date();\n  }\n  call constructor() {\n    let date = new Date();\n    return date.toString();\n  }\n}\n\nlet now = new Date(); // instance\nlet nowStr = Date(); // string\nconsole.log(now instanceof Date); // true\nconsole.log(typeof nowStr); // 'string'\n\n// Transpile with Babel CLI:\n// npx babel code.js --out-file compiled.js","lang":"javascript","description":"Demonstrates usage of the deprecated call constructor plugin to allow a class to be callable without 'new'."},"warnings":[{"fix":"Remove the plugin and refactor code to use static factory methods or decorators.","message":"This plugin is deprecated. The call constructor proposal was withdrawn. Use decorators or static methods instead.","severity":"deprecated","affected_versions":"all"},{"fix":"If using Babel v7, do not use this plugin. There is no direct replacement.","message":"Incompatible with Babel v7. The plugin is designed for Babel v6 and does not work with @babel/core v7+.","severity":"breaking","affected_versions":"all"},{"fix":"Use 'babel-core' version 6.x. Ensure no @babel scoped packages are installed.","message":"The plugin only works with Babel v6's 'babel-core' package. Using '@babel/core' (v7) will fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Refactor to use a static method: static create() { ... } or use decorators.","message":"Syntax is non-standard and will not be natively supported. Code relying on this plugin will not run in modern environments without transpilation.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Remove the plugin from configuration and refactor code.","cause":"The plugin is deprecated and Babel may warn about it.","error":"Error: Plugin transform-class-constructor-call is deprecated"},{"fix":"Ensure 'babel-core' (v6) is installed: npm install --save-dev babel-core","cause":"Using npm packages for Babel v7 (e.g., @babel/core) instead of v6 (babel-core).","error":"Error: Cannot find module 'babel-core'"},{"fix":"Add this plugin to your Babel v6 configuration. For Babel v7, this syntax cannot be used.","cause":"Attempting to use the call constructor syntax without the plugin enabled or with a different Babel version.","error":"SyntaxError: Unexpected token"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}