Feature request: Keep track of variables assigned to a macro
See original GitHub issueSorry for deleting the issue template but this is feature request.
First of all, thanks for building babel-plugin-macros. It finally makes working with babel-plugin controll- and maintainable.
Maybe my use case is a little bit special but I would propose to add a way to keep track of results and assigned variables that contain a value “returned” by the macro. To give an example:
import myMacro from './my.macro'
const res = myMacro();
console.log(res())
Currently this will result in an default
array that only contains the CallExpression in line 2. But not the subsequent call in line 3.
My specify use case for this feature would be to write a macro that would be capable of implementing retarget a library that is using tagged template or proxy objects to generate reusable selector functions.
Example:
import retarget from 'retarget' // retarget.macro
const STATE = {
a: { b: 'Hello World' }
}
const selectA = retarget.a;
const selectB = retarget.b;
const selectAB = retarget[selectA][selectB];
console.log(selectAB(STATE)) // Hello World
try it
If babel-plugin-macro
would allow for keeping track of the result of a macro the code above could be transpiled to something like this:
const STATE = {
a: { b: 'Hello World' }
}
const selectAB = (obj) => obj.a.b;
console.log(selectAB(STATE)) // Hello World
If you would be interested in supporting this feature I would try to implement this.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (10 by maintainers)
yeah i think we’ve both built some version of it - the trick is extracting it so it is reusable out of context. i have a vaaague idea of how it might work - will ship my thing first and look at that sometime later in the year
On Wed, Jul 11, 2018 at 12:28 AM Kent C. Dodds notifications@github.com wrote:
@tsiq-swyx, if you build it, then we can probably add it to https://github.com/babel-utils