Escape sourcemapped names that contain escapable characters
This commit is contained in:
parent
c85d4318b9
commit
d051f29cac
|
|
@ -282,6 +282,14 @@ function OutputStream(options) {
|
||||||
var remainder = 0;
|
var remainder = 0;
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
var tokenName;
|
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;
|
tokenName = (!name && token.type == "name") ? token.value : name;
|
||||||
|
|
||||||
|
|
@ -289,6 +297,17 @@ function OutputStream(options) {
|
||||||
// Cast to a string, it might be a number
|
// Cast to a string, it might be a number
|
||||||
tokenName = new String(tokenName);
|
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<ii; i++) {
|
||||||
|
for(var y=0, yy=escapable.length; y<yy; y++) {
|
||||||
|
if(tokenChars[i] === escapable[y].find && (i===0 || tokenChars[i-1] != '\\')) {
|
||||||
|
tokenChars[i] = escapable[y].replace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tokenName = tokenChars.join('')
|
||||||
|
|
||||||
// Fixes offsets for quoted keys of object literals
|
// Fixes offsets for quoted keys of object literals
|
||||||
remainder = token.endpos - token.pos - tokenName.length;
|
remainder = token.endpos - token.pos - tokenName.length;
|
||||||
offset = remainder === 0 ? 0 : remainder/2;
|
offset = remainder === 0 ? 0 : remainder/2;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user