This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

babel-plugin-transform-custom-element-classes

0.1.0 • Public • Published

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

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"
  ]
}

/babel-plugin-transform-custom-element-classes/

    Package Sidebar

    Install

    npm i babel-plugin-transform-custom-element-classes

    Weekly Downloads

    3,483

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • andrialexandrou
    • jfuchs
    • githubbot
    • manuelpuyol
    • jonrohan
    • broccolini
    • primer-css
    • keithamus
    • colebemis
    • smockle
    • simurai
    • khiga8
    • dustin.greif
    • srt32