mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Add generated code to errors thrown by BabelPlugin
If we've generated an erroneous AST (eg duplicate declarations), this lets us observe what the code looked like to aid debugging
This commit is contained in:
1 parent
0d2653dbd4
commit
e159844b0d
1 file changed
+13
-2
@@ -8,8 +8,10 @@
|
||||
/// <reference path="./plugin-syntax-jsx.d.ts" />
|
||||
|
||||
import type * as BabelCore from "@babel/core";
|
||||
import generate from "@babel/generator";
|
||||
import jsx from "@babel/plugin-syntax-jsx";
|
||||
import { parseCompilerFlags } from "../CompilerFlags";
|
||||
import prettier from "prettier";
|
||||
import { compile } from "../CompilerPipeline";
|
||||
|
||||
/**
|
||||
@@ -46,8 +48,17 @@ export default function ReactForgetBabelPlugin(
|
||||
|
||||
// We are generating a new FunctionDeclaration node, so we must skip over it or this
|
||||
// traversal will loop infinitely.
|
||||
fn.replaceWith(ast);
|
||||
fn.skip();
|
||||
try {
|
||||
fn.replaceWith(ast);
|
||||
fn.skip();
|
||||
} catch (err) {
|
||||
const result = generate(ast);
|
||||
err.message = `${err.message}\n\n${prettier.format(result.code, {
|
||||
semi: true,
|
||||
parser: "babel-ts",
|
||||
})}`;
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user