babel-plugin-chevrotain-serialize
This plugin finds class declarations which inherit from chevrotain.Parser
, serializes them, and passes this serialization into their constructor super
calls, allowing your code to bypass parser grammar construction at runtime. This is especially useful if you run your code through a minifier, as you’ll no longer have to avoid mangling token names.
Installation
npm install --save-dev babel-plugin-chevrotain-serialize
or
yarn add --dev babel-plugin-chevrotain-serialize
Usage
Add the plugin to your .babelrc.
{
"plugins": ["babel-plugin-chevrotain-serialize"]
}
The plugin will find Parser
references which are imported and referenced in one of four ways.
import { Parser } from "chevrotain";
const { Parser } = require("chevrotain");
class MyParser extends Parser {
}
import * as chevrotain from "chevrotain";
const chevrotain = require("chevrotain");
class MyParser extends chevrotain.Parser {
}
const Parser1 = Parser;
class MyParser extends Parser1 {
}