Skip to content

victor-homyakov/acorn-static-class-property-initializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

acorn-static-class-property-initializer

Partial support for static class properties from ES Class Fields & Static Properties Proposal in Acorn - a tiny, fast JavaScript parser, written completely in JavaScript.

Purpose

Made to support static property initializers in React components written as ES6+ classes:

class EntityState extends Component {
    static propTypes = {
        entityState: PropTypes.string.isRequired
    };

    render() {
        return <div>{this.props.entityState}</div>;
    }
}

Usage

You can use module directly in order to get Acorn instance with plugin installed:

var acorn = require('acorn-static-class-property-initializer');

Or you can use inject.js to inject multiple plugins into Acorn:

var acorn = require('acorn');
var injectAcornJsx = require('acorn-jsx/inject');
var injectAcornStaticClassPropertyInitializer = require('acorn-static-class-property-initializer/inject');
injectAcornJsx(acorn);
injectAcornStaticClassPropertyInitializer(acorn);

Then, use the plugins option whenever you need to support static class properties while parsing:

var ast = acorn.parse(code, {
  plugins: {
      jsx: true, // true to enable JSX plugin
      staticClassPropertyInitializer: true // true to enable staticClassPropertyInitializer plugin
  }
});

About

Partial support for static class properties in Acorn

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published