From 3ad332d5d4be3712f197d22fa2435f4b01cbb918 Mon Sep 17 00:00:00 2001 From: Jason Walton Date: Tue, 6 Aug 2013 16:25:23 -0400 Subject: [PATCH] Issue #3092: Fix column numbers in sourcemaps to not be essentially random. --- lib/coffee-script/coffee-script.js | 6 +++++- src/coffee-script.coffee | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index cb66b956..4180d5a0 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -69,7 +69,11 @@ } newLines = helpers.count(fragment.code, "\n"); currentLine += newLines; - currentColumn = fragment.code.length - (newLines ? fragment.code.lastIndexOf("\n") : 0); + if (newLines) { + currentColumn = fragment.code.length - (fragment.code.lastIndexOf("\n") + 1); + } else { + currentColumn += fragment.code.length; + } } js += fragment.code; } diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index fe245443..1d28556f 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -62,7 +62,10 @@ exports.compile = compile = withPrettyErrors (code, options) -> {noReplace: true}) newLines = helpers.count fragment.code, "\n" currentLine += newLines - currentColumn = fragment.code.length - (if newLines then fragment.code.lastIndexOf "\n" else 0) + if newLines + currentColumn = fragment.code.length - (fragment.code.lastIndexOf("\n") + 1) + else + currentColumn += fragment.code.length # Copy the code from each fragment into the final JavaScript. js += fragment.code