trytelework / rollup-plugin-class-fields-to-getters

A plugin which transforms public class fields to static getters for Closure Compiler interop.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compile class fields to get methods

Uses Babel to transpile public class fields to get methods for compilation by Closure Compiler, which currently does not support them.

rollup.config.js

import classFieldsToGetters from 'rollup-plugin-class-fields-to-getters';
export default {
  ...
  plugins: [
    ...
    classFieldsToGetters(),
    ...
  ],
  ...
}

Input

class MyTestClass {
  static myStaticProp1 = 'staticProp';
  static myStaticProp2 = 'staticProp';
  static myStaticProp3 = 'staticProp';
  myProp1 = 'instanceProp';
  myProp2 = 'instanceProp';
  myProp3 = 'instanceProp';
}

Output

class MyTestClass {
  static get myStaticProp1() {
    return 'staticProp';
  }

  static get myStaticProp2() {
    return 'staticProp';
  }

  static get myStaticProp3() {
    return 'staticProp';
  }

  get myProp1() {
    return 'instanceProp';
  }

  get myProp2() {
    return 'instanceProp';
  }

  get myProp3() {
    return 'instanceProp';
  }

}

About

A plugin which transforms public class fields to static getters for Closure Compiler interop.

License:MIT License


Languages

Language:JavaScript 100.0%