source: trip-planner-front/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js@ 6a80231

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

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5
6/**
7 * Safari ~11 has an issue where variable declarations in a For statement throw if they shadow parameters.
8 * This is fixed by renaming any declarations in the left/init part of a For* statement so they don't shadow.
9 * @see https://bugs.webkit.org/show_bug.cgi?id=171041
10 *
11 * @example
12 * e => { for (let e of []) e } // throws
13 * e => { for (let _e of []) _e } // works
14 */
15function handle(declaration) {
16 if (!declaration.isVariableDeclaration()) return;
17 const fn = declaration.getFunctionParent();
18 const {
19 name
20 } = declaration.node.declarations[0].id; // check if there is a shadowed binding coming from a parameter
21
22 if (fn && fn.scope.hasOwnBinding(name) && fn.scope.getOwnBinding(name).kind === "param") {
23 declaration.scope.rename(name);
24 }
25}
26
27var _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 }
39});
40
41exports.default = _default;
42module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.