Skip to content

babel plugin typescript error? #15825

Answered by JLHwung
zkylearner asked this question in Q&A
Discussion options

You must be logged in to vote

The TryCatchBabelPlugin:

{
  FunctionDeclaration: {
    enter(path) {
      const { params, generator, async, id, body } = path.node;
      if (async) {
        // vvvvvv
        path.skip();
      }
    },
  },
};

will skip the function declaration path after it is replaced. Therefore, the typescript plugin can not transform the type arguments within that function and thus webpack throws on unknown syntax as such.

If you want to prevent the TryCatchBabelPlugin from running on the transformed path, consider invoke replacement on its body, which happens to simplify the plugin a bit:

function babelPlugintryCatch (babel) {
  const { types: t, template } = babel;
  
  return {
    visitor: {

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zkylearner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants