Socket
Socket
Sign inDemoInstall

babel-plugin-transform-custom-element-classes

Package Overview
Dependencies
25
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-custom-element-classes

Compile ES6 HTMLElement class extensions to ES5


Version published
Weekly downloads
2.2K
increased by14.98%
Maintainers
1
Install size
4.36 MB
Created
Weekly downloads
 

Readme

Source

babel-plugin-transform-custom-element-classes

Compile Custom Element classes that extend HTMLElement for ES5 environments.

Problem

Custom Elements were designed for native ES6 classes that can extend host objects in ways prototypical inheritance can not. Using the Babel transform-es2015-classes transform will not work as is. You'll likely see a runtime error like "Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function." when attempting to extend HTMLElement in a Babel transpiled class.

Solution

A workaround is to use Reflect.construct to build a new HTMLElement instance expected by the constructor. This transform wraps any ES6 classes extending HTMLElement with an intermediary class that shims this behavior.

Compatibility

  • Chrome Works as is
  • Safari 10.1 Technology Preview Works as is
  • Safari 10 Stable Requires Custom Elements V1 polyfill
  • Firefox Requires Custom Elements V1 polyfill
  • Edge Requires Custom Elements V1 polyfill
  • IE11 Requires Custom Elements V1 polyfill and Reflect.construct polyfill

Installation

$ npm install babel-plugin-transform-custom-element-classes

Usage

Via .babelrc

.babelrc

// include before transform-es2015-classes
{
  "plugins": [
    "transform-custom-element-classes",
    "transform-es2015-classes"
  ]
}

Keywords

FAQs

Last updated on 23 Nov 2016

Did you know?

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

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