| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
export default function({ types: t }) { |
| 6 |
return { |
| 7 |
name: "transform-safari-block-shadowing", |
| 8 |
visitor: { |
| 9 |
VariableDeclarator(path) { |
| 10 |
|
| 11 |
const kind = path.parent.kind; |
| 12 |
if (kind !== "let" && kind !== "const") return; |
| 13 |
|
| 14 |
|
| 15 |
const block = path.scope.block; |
| 16 |
if (t.isFunction(block) || t.isProgram(block)) return; |
| 17 |
|
| 18 |
const bindings = t.getOuterBindingIdentifiers(path.node.id); |
| 19 |
for (const name of Object.keys(bindings)) { |
| 20 |
let scope = path.scope; |
| 21 |
|
| 22 |
|
| 23 |
if (!scope.hasOwnBinding(name)) continue; |
| 24 |
|
| 25 |
|
| 26 |
while ((scope = scope.parent)) { |
| 27 |
if (scope.hasOwnBinding(name)) { |
| 28 |
path.scope.rename(name); |
| 29 |
break; |
| 30 |
} |
| 31 |
if (t.isFunction(scope.block) || t.isProgram(scope.block)) { |
| 32 |
break; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
}, |
| 37 |
}, |
| 38 |
}; |
| 39 |
} |