Urara-Blog/node_modules/.pnpm-store/v3/files/3a/3e5f995855108d0856026dfb9c2b7b6a59320f4d5a965c556c40fe577ec4b464c785ab41a1223b92ce2261163e2fc8010843ac097d3b9eb6ff15e13c6937b9
2022-08-14 01:14:53 +08:00

42 lines
No EOL
1.1 KiB
Text

"use strict";
exports.__esModule = true;
exports.default = void 0;
/**
* Safari ~11 has an issue where variable declarations in a For statement throw if they shadow parameters.
* This is fixed by renaming any declarations in the left/init part of a For* statement so they don't shadow.
* @see https://bugs.webkit.org/show_bug.cgi?id=171041
*
* @example
* e => { for (let e of []) e } // throws
* e => { for (let _e of []) _e } // works
*/
function handle(declaration) {
if (!declaration.isVariableDeclaration()) return;
const fn = declaration.getFunctionParent();
const {
name
} = declaration.node.declarations[0].id; // check if there is a shadowed binding coming from a parameter
if (fn && fn.scope.hasOwnBinding(name) && fn.scope.getOwnBinding(name).kind === "param") {
declaration.scope.rename(name);
}
}
var _default = () => ({
name: "transform-safari-for-shadowing",
visitor: {
ForXStatement(path) {
handle(path.get("left"));
},
ForStatement(path) {
handle(path.get("init"));
}
}
});
exports.default = _default;
module.exports = exports.default;