Fix sourcemapped column for a quoted key of object literal

This commit is contained in:
Ben Ng 2013-08-13 14:00:46 -07:00
parent 6ea3f7fe34
commit c85d4318b9

View File

@ -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,