6.24.1 • Published 7 years ago

babel-plugin-transform-class-properties v6.24.1

Weekly downloads
1,163,908
License
MIT
Repository
github
Last release
7 years ago

babel-plugin-transform-class-properties

This plugin transforms es2015 static class properties as well as properties declared with the es2016 property initializer syntax.

Example

Below is a class with four class properties which will be transformed.

  class Bork {
    //Property initializer syntax
    instanceProperty = "bork";
    boundFunction = () => {
      return this.instanceProperty;
    }

    //Static class properties
    static staticProperty = "babelIsCool";
    static staticFunction = function() {
      return Bork.staticProperty;
    }
  }

  let myBork = new Bork;

  //Property initializers are not on the prototype.
  console.log(myBork.prototype.boundFunction); // > undefined

  //Bound functions are bound to the class instance.
  console.log(myBork.boundFunction.call(undefined)); // > "bork"

  //Static function exists on the class.
  console.log(Bork.staticFunction()); // > "babelIsCool"

Installation

npm install --save-dev babel-plugin-transform-class-properties

Usage

Via .babelrc (Recommended)

.babelrc

// without options
{
  "plugins": ["transform-class-properties"]
}

// with options
{
  "plugins": [
    ["transform-class-properties", { "spec": true }]
  ]
}

Via CLI

babel --plugins transform-class-properties script.js

Via Node API

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

Options

spec

boolean, defaults to false.

Class properties are compiled to use Object.defineProperty. Static fields are now defined even if they are not initialized.

References

egghead-ui-test@procore/core-webpack@procore/core-scripts@niftyco/babel-node@straw-hat/neutrinofooji-serverless-utilsweb-bootisotone-preset-reactcommon-ui-controls@arisageha/react-lazyload@arisageha/react-lazyload-fix@cashremit/cr-streamline-iconswttestrube-toolsairsiders-mapping-toolpon4-packhyj-test-npm3cezerin2-themekelex-clikelex-plugin-applesca-class-pkgwebpack-react-base-pkgreadytest-testcafezolazola-clivulcan-cra-starterawlet@phil8795/pecuniarius-apireact-best-table2webpack-boxreactcloud-dev-serverreactcloud-webpackbabel-preset-fswqreact-artsy-modaltim-react-scriptsares-nextbabel-preset-react-latestglyph-coresmartbarcode-web-coreeasy-draft-js@fizzmod/devservercazetto-pawjs@cloudkite/next@ubaid-desynova/babel-presetsxyj-taro-transformer-wxbabel-preset-mcalbabel-preset-hirokitchen-dodger-gamepugworkbabel-preset-medopadrespamatrix2-iterative-fluid-heightmapchoerodon-hap-front-boot@jjavery/babel-preset-react-apptrustwise-react-native@zrf9018/marvel-clireact-application-base@bybit/marvel-clireact-create-appreact-create-storemindv-clihimapack-clinowtv-sales-sharedpdxdeploy-v3.1.3skri.beboilerplate-react-js-with-sassbabel-preset-noctisboolean-html-js-exerciseslpp-databaseuinz-notification@nehrdani/babel-preset-kickstart@pojntfx-incubator/featherjs-basics@pojntfx-incubator/neoservice-mockup@pojntfx-incubator/node-gtk-learning@chrismlee/reactcardsbabel-preset-create-packagescirex-clitd-react-boilerplatejoymo-lib@everything-registry/sub-chunk-1204@explodingcamera/nextbabel-preset-topxelsg-react-apiembedsg-react-apiembedsuni-react-apiembedgulp-assets-pipelinesimply-benefits-apitcr-styled-componentsexpress-request-queuefacelogbookinfacelogyfable-compiler-netcorefaw-op-yqcloud-front-bootfaw-op-yqcloud-front-boot-anotherfaw-yqcloud-front-bootffkfe-dockerfec-builder-wkcfeigned
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

7 years ago

7.0.0-alpha.11

7 years ago

7.0.0-alpha.10

7 years ago

7.0.0-alpha.9

7 years ago

7.0.0-alpha.8

7 years ago

6.24.1

7 years ago

7.0.0-alpha.7

7 years ago

7.0.0-alpha.3

7 years ago

7.0.0-alpha.1

7 years ago

6.23.0

7 years ago

6.22.0

7 years ago

6.19.0

7 years ago

6.18.0

8 years ago

6.16.0

8 years ago

6.11.5

8 years ago

6.10.2

8 years ago

6.9.1

8 years ago

6.9.0

8 years ago

6.8.0

8 years ago

6.6.0

8 years ago

6.5.2

8 years ago

6.5.0-1

8 years ago

6.5.0

8 years ago

6.4.0

8 years ago

6.3.13

8 years ago

6.3.2

8 years ago

6.3.0

8 years ago

6.2.4

8 years ago

6.2.2

8 years ago

6.1.20

8 years ago

6.1.18

8 years ago

6.1.17

8 years ago

6.1.10

8 years ago

6.1.5

8 years ago

6.1.4

8 years ago

6.0.14

8 years ago

6.0.2

8 years ago