🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@babel/plugin-transform-new-target

Package Overview
Dependencies
Maintainers
4
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-new-target

Transforms new.target meta property

7.27.1
latest
Source
npm
Version published
Weekly downloads
23M
-5.41%
Maintainers
4
Weekly downloads
 
Created

What is @babel/plugin-transform-new-target?

The @babel/plugin-transform-new-target npm package is designed to transform instances of the `new.target` meta-property within functions. This is particularly useful for compiling ES6 code to be compatible with environments that do not support the `new.target` syntax. The `new.target` property is used within constructors to determine if the constructor was called with the `new` operator, allowing constructors to identify how they were invoked and to behave differently if necessary.

What are @babel/plugin-transform-new-target's main functionalities?

Transforming new.target

This feature allows the transformation of `new.target` usage into a form that can be understood by environments that do not support this syntax. It checks if the constructor was called with `new` and throws an error if it wasn't, ensuring that the constructor behaves as intended even in older JavaScript environments.

function MyConstructor() {\n  if (!new.target) {\n    throw 'MyConstructor must be called with new';\n  }\n  console.log('MyConstructor was called with new');\n}\n// Transformed Code:\nfunction MyConstructor() {\n  var _newtarget = this instanceof MyConstructor ? this.constructor : void 0;\n  if (!_newtarget) {\n    throw 'MyConstructor must be called with new';\n  }\n  console.log('MyConstructor was called with new');\n}

Other packages similar to @babel/plugin-transform-new-target

Keywords

babel-plugin

FAQs

Package last updated on 30 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts