Add location information to parsing errors (#7314)
This commit is contained in:
parent
5ea1bfe780
commit
7234442fde
@ -91,7 +91,6 @@ function parser(pluginPasses, options, code) {
|
||||
} catch (err) {
|
||||
const { loc, missingPlugin } = err;
|
||||
if (loc) {
|
||||
err.loc = null;
|
||||
const codeFrame = codeFrameColumns(
|
||||
code,
|
||||
{
|
||||
@ -110,6 +109,7 @@ function parser(pluginPasses, options, code) {
|
||||
err.message =
|
||||
`${options.filename || "unknown"}: ${err.message}\n\n` + codeFrame;
|
||||
}
|
||||
err.code = "BABEL_PARSE_ERROR";
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -148,8 +148,8 @@ function parseWithCodeFrame(code: string, parserOpts: {}): BabelNodeFile {
|
||||
} catch (err) {
|
||||
const loc = err.loc;
|
||||
if (loc) {
|
||||
err.loc = null;
|
||||
err.message += "\n" + codeFrameColumns(code, { start: loc });
|
||||
err.code = "BABEL_TEMPLATE_PARSE_ERROR";
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -77,10 +77,6 @@ export function replaceWithSourceString(replacement) {
|
||||
} catch (err) {
|
||||
const loc = err.loc;
|
||||
if (loc) {
|
||||
// Set the location to null or else the re-thrown exception could
|
||||
// incorrectly interpret the location as referencing the file being
|
||||
// transformed.
|
||||
err.loc = null;
|
||||
err.message +=
|
||||
" - make sure this is an expression.\n" +
|
||||
codeFrameColumns(replacement, {
|
||||
@ -89,6 +85,7 @@ export function replaceWithSourceString(replacement) {
|
||||
column: loc.column + 1,
|
||||
},
|
||||
});
|
||||
err.code = "BABEL_REPLACE_SOURCE_ERROR";
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user