question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Keep track of variables assigned to a macro

See original GitHub issue
Sorry 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:closed
  • Created 6 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
tsiq-swyxcommented, Jul 11, 2018

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 https://github.com/tsiq-swyx, if you build it, then we can probably add it to https://github.com/babel-utils

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kentcdodds/babel-plugin-macros/issues/59#issuecomment-404041456, or mute the thread https://github.com/notifications/unsubscribe-auth/AiT1giKvGOz16ypU-q_ChZvDRzNjJn1Uks5uFX7xgaJpZM4STrjl .

1reaction
kentcdoddscommented, Jul 11, 2018

@tsiq-swyx, if you build it, then we can probably add it to https://github.com/babel-utils

Read more comments on GitHub >

github_iconTop Results From Across the Web

Macro Variables Defined by Users - SAS OnlineDoc, V8
You can create your own macro variables, change their values, and define their scope. You can define a macro variable within a macro,...
Read more >
Creating a Generic Data Listing Macro in Three Days or Less
generic data listing macro in three days: 1. Macro Name and Parameters. 2. Prep Work – Initialize Settings and Variables. 3. Change Requested...
Read more >
3. Variables and Macros - Managing Projects with GNU Make ...
This operator will perform the requested variable assignment only if the variable does not yet have a value. # Put all generated files...
Read more >
Building macro action statements - Zendesk help
Using macros, you can set ticket properties, add or modify tags, and add comments. Select an action using the drop-down menu, then select...
Read more >
An Introduction to MACRO Variables and MACRO Programs
No macro variable can have the same name as a SAS-supplied macro or macro function. Now that you know that a macro variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found