diff --git a/packages/babel-core/src/transformation/file/file.js b/packages/babel-core/src/transformation/file/file.js index a0a9f65bcdf4..db788ac51e69 100644 --- a/packages/babel-core/src/transformation/file/file.js +++ b/packages/babel-core/src/transformation/file/file.js @@ -19,6 +19,17 @@ const errorVisitor = { }, }; +export type NodeLocation = { + loc?: { + end?: { line: number, column: number }, + start: { line: number, column: number }, + }, + _loc?: { + end?: { line: number, column: number }, + start: { line: number, column: number }, + }, +}; + export default class File { _map: Map = new Map(); opts: Object; @@ -250,10 +261,7 @@ export default class File { } buildCodeFrameError( - node: ?{ - loc?: { start: { line: number, column: number } }, - _loc?: { start: { line: number, column: number } }, - }, + node: ?NodeLocation, msg: string, Error: typeof Error = SyntaxError, ): Error { @@ -287,6 +295,13 @@ export default class File { line: loc.start.line, column: loc.start.column + 1, }, + end: + loc.end && loc.start.line === loc.end.line + ? { + line: loc.end.line, + column: loc.end.column + 1, + } + : undefined, }, { highlightCode }, ); diff --git a/packages/babel-core/src/transformation/plugin-pass.js b/packages/babel-core/src/transformation/plugin-pass.js index 6e62c42bc786..e11f97804745 100644 --- a/packages/babel-core/src/transformation/plugin-pass.js +++ b/packages/babel-core/src/transformation/plugin-pass.js @@ -1,6 +1,7 @@ // @flow import type File from "./file/file"; +import type NodeLocation from "./file/file"; export default class PluginPass { _map: Map = new Map(); @@ -47,14 +48,7 @@ export default class PluginPass { return this.file.getModuleName(); } - buildCodeFrameError( - node: ?{ - loc?: { start: { line: number, column: number } }, - _loc?: { start: { line: number, column: number } }, - }, - msg: string, - Error?: typeof Error, - ) { + buildCodeFrameError(node: ?NodeLocation, msg: string, Error?: typeof Error) { return this.file.buildCodeFrameError(node, msg, Error); } }