Registry / devops / babel-plugin-transform-class-constructor-call

babel-plugin-transform-class-constructor-call

JSON →
library6.24.1jsnpmunverified

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.

npm install babel-plugin-transform-class-constructor-call
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-class-constructor-call
devopsjavascriptv6.24.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
// .babelrc { "plugins": ["transform-class-constructor-call"] }
npm install --save-dev babel-plugin-transform-class-constructor-call
The plugin is a Babel plugin, not a direct JavaScript import. Use it via Babel configuration.
require('babel-core')
const babel = require('babel-core'); babel.transform(code, { plugins: ['transform-class-constructor-call'] });
import { transform } from 'babel-core'; // Babel v6 uses CommonJS, not ESM
Babel v6's core package is 'babel-core' (not @babel/core) and uses CommonJS. Using ESM imports may fail.
class with call constructor
class Point { constructor(x, y) { this.x = x; this.y = y; } call constructor(x, y) { return new Point(x, y); } }
// No call constructor; this is the only valid syntax for this plugin
The 'call constructor' syntax is non-standard and only works with this plugin. It is not part of any ES spec.

Demonstrates usage of the deprecated call constructor plugin to allow a class to be callable without 'new'.

// Install: npm install --save-dev babel-plugin-transform-class-constructor-call // .babelrc { "plugins": ["transform-class-constructor-call"] } // Example usage in code.js class Date { constructor() { this.date = new Date(); } call constructor() { let date = new Date(); return date.toString(); } } let now = new Date(); // instance let nowStr = Date(); // string console.log(now instanceof Date); // true console.log(typeof nowStr); // 'string' // Transpile with Babel CLI: // npx babel code.js --out-file compiled.js
Debug
Known issues
deprecatedThis plugin is deprecated. The call constructor proposal was withdrawn. Use decorators or static methods instead.
fix
Remove the plugin and refactor code to use static factory methods or decorators.
affects: all
breakingIncompatible with Babel v7. The plugin is designed for Babel v6 and does not work with @babel/core v7+.
fix
If using Babel v7, do not use this plugin. There is no direct replacement.
affects: all
gotchaThe plugin only works with Babel v6's 'babel-core' package. Using '@babel/core' (v7) will fail.
fix
Use 'babel-core' version 6.x. Ensure no @babel scoped packages are installed.
affects: all
gotchaSyntax is non-standard and will not be natively supported. Code relying on this plugin will not run in modern environments without transpilation.
fix
Refactor to use a static method: static create() { ... } or use decorators.
affects: all
Errors
Common errors & fixes
Error: Plugin transform-class-constructor-call is deprecated
The plugin is deprecated and Babel may warn about it.
fix
Remove the plugin from configuration and refactor code.
Error: Cannot find module 'babel-core'
Using npm packages for Babel v7 (e.g., @babel/core) instead of v6 (babel-core).
fix
Ensure 'babel-core' (v6) is installed: npm install --save-dev babel-core
SyntaxError: Unexpected token
Attempting to use the call constructor syntax without the plugin enabled or with a different Babel version.
fix
Add this plugin to your Babel v6 configuration. For Babel v7, this syntax cannot be used.
Upgrade
Version history
6.24.1latest on npm
Audit
Dependencies
@babel/corerequiredRequires Babel core v6 to load and run the plugin; not compatible with Babel v7+.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
babel-plugin-transform-class-constructor-call — npm install babel-plugin-transform-class-constructor-call · libregistry