Skip to content

Commit

Permalink
Add location information to parsing errors (babel#7314)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo authored and aminmarashi committed Mar 17, 2018
1 parent d14e590 commit 7bcd0cf
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/babel-core/src/transformation/normalize-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function parser(pluginPasses, options, code) {
} catch (err) {
const { loc, missingPlugin } = err;
if (loc) {
err.loc = null;
const codeFrame = codeFrameColumns(
code,
{
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-template/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions packages/babel-traverse/src/path/replacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -89,6 +85,7 @@ export function replaceWithSourceString(replacement) {
column: loc.column + 1,
},
});
err.code = "BABEL_REPLACE_SOURCE_ERROR";
}
throw err;
}
Expand Down

0 comments on commit 7bcd0cf

Please sign in to comment.