Sha256: c0a173e629b2db1672c0f495dd4ad41e7dd180efbf3ef2caa89bcbde432d5793

Contents?: true

Size: 1.1 KB

Versions: 35

Compression:

Stored size: 1.1 KB

Contents

"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;

Version data entries

35 entries across 34 versions & 7 rubygems

Version Path
immosquare-cleaner-0.1.62 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.61 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.60 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.59 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.58 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.57 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.56 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.55 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.54 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.53 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.52 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.51 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
optimacms-0.1.61 spec/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
disco_app-0.16.1 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js