Skip to content

How to show errors in vscode or other editor when macro is throwing MacroError or buildCodeFrameError? #169

@AmitDigga

Description

@AmitDigga
  • babel-plugin-macros version: ^3.0.1
  • node version: v12.16.3
  • npm version: 6.14.4

Relevant code or config

function macroHandler({ references, state, babel }: MacroParams) {
  const { types: t } = babel;
  const { Hello = []} = references;
  Hello.forEach((refPath) => {
    throw new MacroError("Not Working");
  });
}

What you did:
I tried this macro on another create-react-app.

What happened:

This macro error was only available when app was started or build.

// this is not the exact code. I used my Macro in App render function.
import {Hello} from 'my-macro/lib/hello-macro.macro';
Hello("World") 

Problem description:
Error was not shown on vscode. The macro I am building is a little bit complex so I am asserting errors at the early stages.

  1. Is there any way to show the error with line-numbers or columns in vscode or other IDEs?
  2. What is the use of MacroError? Can this be used in to do that?
  3. I tried buildCodeFrameError which gave some context where error is happening. Not in the IDE, but at time of compilation. So which one should be used?

Suggested solution:
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions