From c85d4318b935968b7266136008cbcf55c0418772 Mon Sep 17 00:00:00 2001 From: Ben Ng Date: Tue, 13 Aug 2013 14:00:46 -0700 Subject: [PATCH 1/3] Fix sourcemapped column for a quoted key of object literal --- lib/output.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/output.js b/lib/output.js index 90589a2d..2aa3e982 100644 --- a/lib/output.js +++ b/lib/output.js @@ -278,12 +278,29 @@ function OutputStream(options) { var add_mapping = options.source_map ? function(token, name) { try { - if (token) options.source_map.add( - token.file || "?", - current_line, current_col, - token.line, token.col, - (!name && token.type == "name") ? token.value : name - ); + if (token) { + var remainder = 0; + var offset = 0; + var tokenName; + + tokenName = (!name && token.type == "name") ? token.value : name; + + if(tokenName) { + // Cast to a string, it might be a number + tokenName = new String(tokenName); + + // Fixes offsets for quoted keys of object literals + remainder = token.endpos - token.pos - tokenName.length; + offset = remainder === 0 ? 0 : remainder/2; + } + + options.source_map.add( + token.file || "?", + current_line, current_col, + token.line, token.col + offset, + tokenName + ); + } } catch(ex) { AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", { file: token.file, From d051f29cacc4f47b71437b8f5afaa9ef7dc428f2 Mon Sep 17 00:00:00 2001 From: Ben Ng Date: Tue, 13 Aug 2013 14:02:52 -0700 Subject: [PATCH 2/3] Escape sourcemapped names that contain escapable characters --- lib/output.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/output.js b/lib/output.js index 2aa3e982..a7b5e21c 100644 --- a/lib/output.js +++ b/lib/output.js @@ -282,6 +282,14 @@ function OutputStream(options) { var remainder = 0; var offset = 0; var tokenName; + var tokenChars; + var escapable = [ + {find:'\n', replace:'\\n'}, + {find:'\r', replace:'\\r'}, + {find:'\t', replace:'\\t'}, + {find:'\u2028', replace:'\\u2028'}, + {find:'\u2029', replace:'\\u2029'} + ]; tokenName = (!name && token.type == "name") ? token.value : name; @@ -289,6 +297,17 @@ function OutputStream(options) { // Cast to a string, it might be a number tokenName = new String(tokenName); + // Fixes offsets for escaped chars in keys of object literals + tokenChars = tokenName.split(''); + for(var i=0, ii=tokenChars.length; i Date: Thu, 15 Aug 2013 17:26:48 -0700 Subject: [PATCH 3/3] Add missing char to to_ascii --- lib/output.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index a7b5e21c..49c93c9a 100644 --- a/lib/output.js +++ b/lib/output.js @@ -80,11 +80,12 @@ function OutputStream(options) { while (code.length < 4) code = "0" + code; return "\\u" + code; } - }); + }).replace(/\x0B/g, "\\x0B"); }; function make_string(str) { var dq = 0, sq = 0; + str = str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029\0]/g, function(s){ switch (s) { case "\\": return "\\\\";