Skip to content

Commit

Permalink
Revert "Add location information to parsing errors (#7314)"
Browse files Browse the repository at this point in the history
This reverts commit 7234442.
  • Loading branch information
kaicataldo authored Feb 5, 2018
1 parent 28b602d commit 38918da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 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,6 +91,7 @@ function parser(pluginPasses, options, code) {
} catch (err) {
const { loc, missingPlugin } = err;
if (loc) {
err.loc = null;
const codeFrame = codeFrameColumns(
code,
{
Expand All @@ -109,7 +110,6 @@ 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: 4 additions & 1 deletion packages/babel-traverse/src/path/replacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ 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 @@ -85,7 +89,6 @@ export function replaceWithSourceString(replacement) {
column: loc.column + 1,
},
});
err.code = "BABEL_REPLACE_SOURCE_ERROR";
}
throw err;
}
Expand Down

0 comments on commit 38918da

Please sign in to comment.