Skip to content

Commit

Permalink
fix usage of codeframe
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Jun 1, 2017
1 parent 523fae4 commit f1cfbe0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/babel-core/src/transformation/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,13 @@ export default class File extends Store {

const loc = err.loc;
if (loc) {
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
const location = {
start: {
line: loc.line,
column: loc.column + 1
},
};
err.codeFrame = codeFrame(code, location, this.opts);
message += "\n" + err.codeFrame;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/babel-traverse/src/path/replacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ export function replaceWithSourceString(replacement) {
} catch (err) {
const loc = err.loc;
if (loc) {
const location = {
start: {
line: loc.line,
column: loc.column + 1
},
};
err.message += " - make sure this is an expression.";
err.message += "\n" + codeFrame(replacement, loc.line, loc.column + 1);
err.message += "\n" + codeFrame(replacement, location);
}
throw err;
}
Expand Down

0 comments on commit f1cfbe0

Please sign in to comment.