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,