macro-system
v2.0.2
Published
A simple and lightweight macro system for JavaScript, inspired by Lisp macros.
Downloads
10
Maintainers
Readme
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