Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

39 lines (29 sloc) 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.

You can’t perform that action at this time.