babel-plugin-transform-jscript

raw JSON →
6.22.0 verified Sat Apr 25 auth: no javascript deprecated

Babel plugin that fixes buggy named function expressions in JScript (IE<=8). This is an older Babel 6 plugin (v6.22.0), part of Babel's preset-es2015. It wraps named function expressions in an IIFE to avoid JScript's incorrect hoisting behavior. Not needed for modern browsers or Node.js. The plugin has no active maintenance as Babel 6 is superseded by Babel 7+; alternatives include using @babel/preset-env with the 'ie' target.

error Cannot find module 'babel-plugin-transform-jscript'
cause Package not installed or Babel 7+ is used (plugin name changed).
fix
Run 'npm install babel-plugin-transform-jscript' for Babel 6, or use @babel/plugin-transform-jscript for Babel 7+ (if available) but it's likely not needed.
error Error: Cannot find module 'babel-core' from '...'
cause Using Babel 6 API with Node API but babel-core not installed.
fix
Ensure 'babel-core' is installed: npm install babel-core
deprecated This plugin is for Babel 6 only and is no longer maintained. Use @babel/preset-env with the 'ie' option instead.
fix Upgrade to Babel 7+ and use @babel/preset-env targeting 'ie 8' or similar.
gotcha The plugin only transforms named function expressions with the 'var' assignment pattern. Other patterns like object property assignments are not handled.
fix Ensure your code uses var foo = function bar() {} to be transformed.
npm install babel-plugin-transform-jscript
yarn add babel-plugin-transform-jscript
pnpm add babel-plugin-transform-jscript

Demonstrates how to enable the plugin via .babelrc and shows the transformation of a named function expression to an IIFE to fix JScript hoisting.

// .babelrc
{
  "plugins": ["transform-jscript"]
}
// input.js
var foo = function bar() {};
// output.js
var foo = (function() {
  var bar = function() {};
  return bar;
})();