Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 814 Bytes

README.md

File metadata and controls

38 lines (29 loc) · 814 Bytes

babel-macros

UPDATE - work on this will likely happen over at Kent's repo

(this is a readme for a project that I want to exist. previous work - sweetjs, babel-plugin-macros)

a macro is a function that takes source code as input, and modifies it.

input

// hello.macros.js 
export default function hello(x){
  // do whatever with the node  
  x.replaceWithSourceString(`console.log('hello' + ${x.toSource()})`))
}

// app.js
import hello from './hello.macros'

hello('sunil')

output

console.log('hello' + 'sunil')

Works across common function call types

x(...)
<X .../>
x`...`

usage

add 'babel-macros' to your babel config's plugins field.