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.

Prevent macro from running without babel-marcos

See original GitHub issue

I was wondering, as I am using babel-macros in a project now, if there could be a way added so macros could “catch” it when they are being imported in a normal file.

As it seems now, there isn’t such thing. The this is unset, if packing with webpack I could check if I am running in node (browser won’t), but I also use this on node. Possible would be to check the arguments, but as the mantra of this repo is, I think explicit is better than implicit 😉

I wonder what the best way is though:

  • Setting this seemed good, but won’t work with arrow functions
  • Setting a property to check on the macro function itself:
      const macros = require(requirePath)
    + macros.with_babel_macros
      macros({
        references: referencePathsByImportName,
        state,
        babel,
      })
    
    Feels kinda hacky, but again we are putting macros into javascript, So who cares about hacky 😅 (This one is actually also possible (cleaner?) with Symbols)
  • Passing a symbol as first argument that can be compared
    import babelMacros from 'babel-macros';
    export default ({ is_babel_macros, references, state }) => {
      if (is_babel_macros !== babelMacros.is_babel_macros) {
        ...
    

Most likely I am missing an option or some perspective, so I’d like to discuss this 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
reznordcommented, Aug 16, 2017

I’d be happy to take this on!

0reactions
kentcdoddscommented, Sep 8, 2017

Now it’s recommended to wrap your macro in createMacro. See the updated docs 👍

Not “recommended” … “required” 🕶

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop a Macro from Running in Excel - TeachExcel.com
How to stop a macro from running after it has started. This method uses the keyboard and has nothing to do with the...
Read more >
Excel: Preventing auto_open and Workbook_Open events ...
At the same time I sometimes want to prevent Workbook_Open event code or an Auto_Open macro from running. This little article shows you...
Read more >
Prevent Users from Running Macros | MrExcel Message Board
As long as the user doesn't know the name of the macro, that will work as far as a basic way to hide...
Read more >
Macros from the internet will be blocked by default in Office
Provides guidance for admins about how Office blocks macros in files from the internet.
Read more >
Stop Running Macro other than ESC / Command +
it is possible that your code is super busy and does not respond to key presses. · Thanks for the help jsotola, but...
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