Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-new-target

Package Overview
Dependencies
54
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

@babel/plugin-transform-new-target

Transforms new.target meta property

    7.23.3latest
    GitHub
    npm

Version published
Maintainers
4
Weekly downloads
22,155,050
increased by4.54%

Weekly downloads

Package description

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

Changelog

Source

v7.23.3 (2023-11-09)

:bug: Bug Fix
  • babel-plugin-transform-typescript
    • #16071 Strip type-only TS namespaces (@colinaaa)
  • babel-generator
  • babel-compat-data, babel-plugin-bugfix-v8-static-class-fields-redefine-readonly, babel-preset-env
  • babel-plugin-transform-object-super
  • babel-helper-module-transforms, babel-plugin-transform-modules-amd, babel-plugin-transform-modules-commonjs, babel-plugin-transform-modules-umd
:memo: Documentation
  • #16044 docs: Update links in @babel/eslint-parser README (@aryehb)
:house: Internal
  • babel-core, babel-preset-env
:running_woman: Performance
:microscope: Output optimization
  • babel-plugin-transform-computed-properties

Readme

Source

@babel/plugin-transform-new-target

Transforms new.target meta property

See our website @babel/plugin-transform-new-target for more information.

Install

Using npm:

npm install --save-dev @babel/plugin-transform-new-target

or using yarn:

yarn add @babel/plugin-transform-new-target --dev

Keywords

FAQs

Last updated on 09 Nov 2023

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc