source: trip-planner-front/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1012 bytes
Line 
1/**
2 * Safari ~11 has an issue where variable declarations in a For statement throw if they shadow parameters.
3 * This is fixed by renaming any declarations in the left/init part of a For* statement so they don't shadow.
4 * @see https://bugs.webkit.org/show_bug.cgi?id=171041
5 *
6 * @example
7 * e => { for (let e of []) e } // throws
8 * e => { for (let _e of []) _e } // works
9 */
10
11function handle(declaration) {
12 if (!declaration.isVariableDeclaration()) return;
13
14 const fn = declaration.getFunctionParent();
15 const { name } = declaration.node.declarations[0].id;
16
17 // check if there is a shadowed binding coming from a parameter
18 if (
19 fn &&
20 fn.scope.hasOwnBinding(name) &&
21 fn.scope.getOwnBinding(name).kind === "param"
22 ) {
23 declaration.scope.rename(name);
24 }
25}
26
27export default () => ({
28 name: "transform-safari-for-shadowing",
29 visitor: {
30 ForXStatement(path) {
31 handle(path.get("left"));
32 },
33
34 ForStatement(path) {
35 handle(path.get("init"));
36 },
37 },
38});
Note: See TracBrowser for help on using the repository browser.