리팩토링의 이름을 잘 바꾸는 브라우저 내/다운로드 가능한 node.js 라이브러리 도구가 있습니다. Esprima은 다음과 같은 ES6 코드 (예제에서 약간 수정 됨)를 처리하여 전역 범위 hi
중 하나의 이름을 변경할 때 hi
이름 만 주석 블록으로 묶습니다. (더 나은 방법을 생각할 수 없었습니다. 마크 다운이 코드 블록에 표시되지 않으므로 코드를 호출하십시오. 죄송합니다.)
// Array shuffling code from Underscore.js, code modified from base example on http://esprima.org/demo/rename.html
var shuffled;
var /*hi*/ = 'hi'; // initial declaration
function /*hi*/() { // modifies var above
this.shuffle = 'x';
}
_.shuffle = function(obj) {
function hi() {
return 'hello';
}
var shuffled = [], rand;
each(obj, function(value, index, list) {
rand = Math.floor(Math.random() * (index + 1));
shuffled[index] = shuffled[rand];
shuffled[rand] = value;
});
hi(); // calls function defined above, name not changed by change to global scope 'hi'
console.log(hello); // considered to be the same as the let statement below even though this is a syntax error since let doesn't get hoisted like var
return shuffled;
};
let hello = 'hello';
function hiNotInScope() {
var hi = 'something else'; // not in global scope, so change to global hi doesn't change this
console.log(hi); // changed if the hi in this scope is changed
}
// hi (not changed since it's in a comment)
/*hi*/(); // calls global hi function.
더 코드 오류가없는만큼 규칙을 범위 지정 존중하는 것
(예를 들어, let
위에 게양됩니다 같은 이름의 var
선언 위의 let
선언에-범위로 간주되지만 이는 구문 오류이므로 문제가되지 않습니다.)