From 13cb24e35f670343d9ea6959f544e1d30cf8ea12 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Mon, 9 Apr 2018 23:54:34 +0200 Subject: Maintain column width when transforming consts --- lib/moduleEnv.js | 10 ++++++---- testLib/sharedTestCases.js | 5 +---- testLib/throwError.js | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/moduleEnv.js b/lib/moduleEnv.js index cbb76d9..688401e 100644 --- a/lib/moduleEnv.js +++ b/lib/moduleEnv.js @@ -111,17 +111,19 @@ function jsExtension(module, filename) { var _compile = module._compile; module._compile = function (content, filename) { - const noConstAssignMessage = linter.verify(content, eslintOptions).find(isNoConstAssignMessage); + var noConstAssignMessage = linter.verify(content, eslintOptions).find(isNoConstAssignMessage); + var line; + var column; if (noConstAssignMessage !== undefined) { - const { line, column } = noConstAssignMessage; - + line = noConstAssignMessage.line; + column = noConstAssignMessage.column; throw new TypeError(`Assignment to constant variable at ${ filename }:${ line }:${ column }`); } _compile.call( module, - content.replace(matchConst, "$1let$2"), // replace const with let + content.replace(matchConst, "$1let $2"), // replace const with let, while maintaining the column width filename ); }; diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js index 611a1d6..aa18516 100644 --- a/testLib/sharedTestCases.js +++ b/testLib/sharedTestCases.js @@ -260,14 +260,11 @@ module.exports = function () { it("should not modify line numbers in stack traces", function () { var throwError = rewire("./throwError.js"); - if (process.env.running_under_istanbul === "1") { - return; - } try { throwError(); } catch (err) { if (err.stack) { - expect(err.stack.split("\n")[1]).to.match(/:7:11/); + expect(err.stack.split("\n")[1]).to.match(/:6:26/); } } }); diff --git a/testLib/throwError.js b/testLib/throwError.js index e85ea36..0993618 100644 --- a/testLib/throwError.js +++ b/testLib/throwError.js @@ -1,8 +1,7 @@ // Using deliberately const here because we know that we're transform const to let -const test = 1; +const a = "a"; module.exports = function () { - let test = 1; - - throw new Error(); + // Ensure that column numbers are correct + const b = "b"; throw new Error(); }; -- cgit v1.2.3