Allows you to build simple compile-time libraries
Instead, let's use the macro it's shipped with like this:
1. Add `babel-plugin-macros` to `.babelrc` (only once for all macros)
2. Use it in a code:
```js
import scope from 'babel-plugin-console/scope.macro'
function add100(a) {
const oneHundred = 100
scope('Add 100 to another number')
return add(a, oneHundred)
}
function add(a, b) {
return a + b
}
```
The result is exactly the same, but this approach has a few advantages:
**Advantages:**
- requires only one entry in `.babelrc` for all macros used in project. Add that
once and you can use all the macros you want
- toolkits (like [create-react-app][cra]) may already support
`babel-plugin-macros`, so no configuration is needed at all
- it's explicit. With `console.scope` people may be fooled that it's just a
normal `console` API when there's really a babel transpilation going on. When
you import `scope`, it's obvious that it's macro and does something with the
code at compile time. Some ESLint rules may also have issues with plugins that
look for "global" variables
- macros are safer and easier to write, because they receive exactly the AST
node to process
- If you misconfigure `babel-plugin-console` you wont find out until you run the
code. If you misconfigure `babel-plugin-macros` you'll get a compile-time
error.
**Drawbacks:**
- Cannot (should not) be used for implicit transpilations (like syntax plugins)
- Explicitness is more verbose. Which some people might consider a drawback...
### In what order are macros executed?
This is another advantage of `babel-plugin-macros` over regular plugins. The
user of the macro is in control of the ordering! The order of execution is the
same order as imported. The order of execution is clear, explicit and in full
control of the user:
```js
import preval from 'preval.macro'
import idx from 'idx.macro'
// preval macro is evaluated first, then idx
```
This differs from the current situation with babel plugins where it's
prohibitively difficult to control the order plugins run in a particular file.
### Does it work with function calls only?
No! Any AST node type is supported.
It can be tagged template literal:
```js
import eval from 'eval.macro'
const val = eval`7 * 6`
```
A function:
```js
import eval from 'eval.macro'
const val = eval('7 * 6')
```
JSX Element:
```js
import Eval from 'eval.macro'
const val =