babel-plugin-transform-es2015-classes
Compile ES2015 classes to ES5
Last updated 9 years ago by hzoo .
MIT · Repository · Original npm · Tarball · package.json
$ npm install babel-plugin-transform-es2015-classes 
SYNC missed versions from official npm registry.

babel-plugin-transform-es2015-classes

Compile ES2015 classes to ES5

Caveats

Built-in classes such as Date, Array, DOM etc cannot be properly subclassed due to limitations in ES5 (for the es2015-classes plugin). You can try to use babel-plugin-transform-builtin-extend based on Object.setPrototypeOf and Reflect.construct, but it also has some limitations.

Installation

npm install --save-dev babel-plugin-transform-es2015-classes

Usage

Via .babelrc (Recommended)

.babelrc

// without options
{
  "plugins": ["transform-es2015-classes"]
}

// with options
{
  "plugins": [
    ["transform-es2015-classes", {
      "loose": true
    }]
  ]
}

Via CLI

babel --plugins transform-es2015-classes script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-es2015-classes"]
});

Options

loose

boolean, defaults to false.

Method enumerability

Please note that in loose mode class methods are enumerable. This is not in line with the spec and you may run into issues.

Method assignment

Under loose mode, methods are defined on the class prototype with simple assignments instead of being defined. This can result in the following not working:

class Foo {
  set bar() {
    throw new Error("foo!");
  }
}

class Bar extends Foo {
  bar() {
    // will throw an error when this method is defined
  }
}

When Bar.prototype.foo is defined it triggers the setter on Foo. This is a case that is very unlikely to appear in production code however it's something to keep in mind.

Current Tags

  • 6.24.1                                ...           latest (8 years ago)
  • 7.0.0-beta.3                                ...           next (7 years ago)

53 Versions

  • 7.0.0-beta.3                                ...           7 years ago
  • 7.0.0-beta.2                                ...           7 years ago
  • 7.0.0-beta.1                                ...           7 years ago
  • 7.0.0-beta.0                                ...           7 years ago
  • 7.0.0-alpha.20                                ...           7 years ago
  • 7.0.0-alpha.19                                ...           7 years ago
  • 7.0.0-alpha.18                                ...           7 years ago
  • 7.0.0-alpha.17                                ...           7 years ago
  • 7.0.0-alpha.16                                ...           7 years ago
  • 7.0.0-alpha.15                                ...           7 years ago
  • 7.0.0-alpha.14                                ...           7 years ago
  • 7.0.0-alpha.12                                ...           8 years ago
  • 7.0.0-alpha.11                                ...           8 years ago
  • 7.0.0-alpha.10                                ...           8 years ago
  • 7.0.0-alpha.9                                ...           8 years ago
  • 7.0.0-alpha.8                                ...           8 years ago
  • 6.24.1                                ...           8 years ago
  • 7.0.0-alpha.7                                ...           8 years ago
  • 7.0.0-alpha.3                                ...           8 years ago
  • 7.0.0-alpha.1                                ...           8 years ago
  • 6.23.0                                ...           8 years ago
  • 6.22.0                                ...           8 years ago
  • 6.18.0                                ...           8 years ago
  • 6.14.0                                ...           8 years ago
  • 6.9.0                                ...           9 years ago
  • 6.8.0                                ...           9 years ago
  • 6.7.7                                ...           9 years ago
  • 6.6.5                                ...           9 years ago
  • 6.6.4                                ...           9 years ago
  • 6.6.0                                ...           9 years ago
  • 6.5.2                                ...           9 years ago
  • 6.5.0-1                                ...           9 years ago
  • 6.5.0                                ...           9 years ago
  • 6.4.5                                ...           9 years ago
  • 6.4.0                                ...           9 years ago
  • 6.3.15                                ...           9 years ago
  • 6.3.13                                ...           9 years ago
  • 6.3.2                                ...           9 years ago
  • 6.2.4                                ...           9 years ago
  • 6.2.2                                ...           9 years ago
  • 6.2.0                                ...           9 years ago
  • 6.1.21                                ...           9 years ago
  • 6.1.20                                ...           9 years ago
  • 6.1.18                                ...           9 years ago
  • 6.1.17                                ...           9 years ago
  • 6.1.10                                ...           9 years ago
  • 6.1.5                                ...           9 years ago
  • 6.1.4                                ...           9 years ago
  • 6.1.2                                ...           9 years ago
  • 6.0.15                                ...           9 years ago
  • 6.0.14                                ...           9 years ago
  • 6.0.8                                ...           9 years ago
  • 6.0.2                                ...           9 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE