diff --git a/lib/output.js b/lib/output.js index 37e30c0e..19b972cb 100644 --- a/lib/output.js +++ b/lib/output.js @@ -80,7 +80,7 @@ function OutputStream(options) { while (code.length < 4) code = "0" + code; return "\\u" + code; } - }); + }).replace(/\x0B/g, "\\x0B"); }; function make_string(str) { @@ -278,12 +278,46 @@ 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 tokenName; + var tokenChars; + var escapable = [ + {find:'\n', replace:'\\n'}, + {find:'\r', replace:'\\r'}, + {find:'\t', replace:'\\t'}, + {find:'\b', replace:'\\b'}, + {find:'\f', replace:'\\f'}, + {find:'\v', replace:'\\v'}, + {find:'\\', replace:'\\\\'}, + {find:'\u2028', replace:'\\u2028'}, + {find:'\u2029', replace:'\\u2029'} + ]; + + 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 escaped chars in keys of object literals + tokenChars = tokenName.split(''); + for(var i=0, ii=tokenChars.length; i