macro-system

2.0.2 • Public • Published

JavaScript Macros

A simple and lightweight macro system for JavaScript, inspired by Lisp macros. This package allows you to define and use macros to perform code transformations at compile time.

Installation

npm install macro-system

Usage

const { macroexpand, macroexpand1, gensym } = require('macro-system');

// Define macros using defmacro
const inputCode = `
  defmacro('log', msg => \`console.log(\${msg})\`);
  log('Hello, World!');
`;

// Expand macros in the input code
const expandedCode = macroexpand(inputCode);

// Output: console.log('Hello, World!');
console.log(expandedCode);

Dependencies

This package relies on the following dependencies:

  • esprima: JavaScript parser used for generating and working with abstract syntax trees (AST).
  • escodegen: JavaScript code generator used for transforming ASTs back into source code.

Author

  • Varun A

License

MIT

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i macro-system

    Weekly Downloads

    0

    Version

    2.0.2

    License

    MIT

    Unpacked Size

    32.8 kB

    Total Files

    4

    Last publish

    Collaborators

    • runsys