Skip to content

Commit

Permalink
Update esrefactor to revision c5081d5385 (Apr 23 2013).
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Apr 23, 2013
1 parent 170f531 commit 5b74142
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/3rdparty/esrefactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
// code will be `var y; y = 42'.

Context.prototype.rename = function (identification, name) {
var result, list, i, id, entry;
var result, list, set, i, id, entry;

if (!this._code) {
throw new Error('Unable to rename without the original source');
Expand All @@ -254,14 +254,20 @@
// shifting all the ranges.
list.sort(function (a, b) { return b[0] - a[0]; });

id = identification.identifier.name;
for (i = 0; i < list.length; ++i) {
entry = list[i];
if (result.substr(entry[0], id.length) === id) {
result = result.slice(0, entry[0]) + name + result.slice(entry[1]);
// Prevent double renaming, get the unique set.
set = [];
set.push(list[0]);
for (i = 1; i < list.length; ++i) {
if (list[i][0] !== list[i - 1][0]) {
set.push(list[i]);
}
}

id = identification.identifier.name;
for (i = 0; i < set.length; ++i) {
result = result.slice(0, set[i][0]) + name + result.slice(set[i][1]);
}

return result;
};

Expand Down

0 comments on commit 5b74142

Please sign in to comment.