禁止在循环语句内包含不安全引用的函数声明。
该规则仅支持对.js/.ts文件进行检查。
const a = function(): void {
console.info('hello');
};
for (let i = 10; i; i--) {
a();
}
for (let i = 10; i; i--) {
const b = function(): void {
a();
}; // OK, no references to variables in the outer scopes.
b();
} const num = 10;
for (let i = num; i; i--) {
// 变量i是不安全的引用
(function(): number {
return i;
})();
}
let i1 = 0;
while (i1 < num) {
// 变量i是不安全的引用
const a = function(): number {
return i1;
};
a();
i1++;
}
let i2 = 0;
do {
// 变量i是不安全的引用
function a(): number {
return i2;
}
a();
i2++;
} while (i2 < num);