register-babel-syntax
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

register-babel-syntax

Hacks the @babel/parser module to allow the registration of custom syntax plugins

Always update to the latest version to have more features and bug fixes (A looot of bug fixes!)

npm r register-babel-syntax & npm i register-babel-syntax

Warning

This module modifies the source code of @babel/parser, so ensure that this loads before you require @babel/core

Usage

// Import the register function
const register = require("register-babel-syntax");

// Get the generated plugin infos
const info = register("your-syntax-plugin", baseParser => {
    // The "__priv" object contains the parser's exposed private variables
    // ("tt" is the token's enum)
    const { __priv: { tt } } = require("@babel/parser");

    return class extends baseParser {
        // Do your overrides
    };
});

// Normal babel plugin export
module.exports = function () {
    return {
        ...info

        // The other things you may want to export
    };
};

Useful info

For infos on how you can do a syntax plugin:

  • Go to the file node_modules/@babel/parser/lib/index.js
  • View this article, keep in mind the API is changed since
  • Look how I did it here

Package Sidebar

Install

npm i register-babel-syntax

Weekly Downloads

2

Version

1.1.4

License

ISC

Unpacked Size

3.76 kB

Total Files

4

Last publish

Collaborators

  • seanalunni