From d051f29cacc4f47b71437b8f5afaa9ef7dc428f2 Mon Sep 17 00:00:00 2001 From: Ben Ng Date: Tue, 13 Aug 2013 14:02:52 -0700 Subject: [PATCH] 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