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
disco_app-0.15.2 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
disco_app-0.18.4 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
disco_app-0.18.1 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
disco_app-0.14.0 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
tang-0.2.1 spec/tang_app/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
tang-0.2.0 spec/tang_app/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
tang-0.1.0 spec/tang_app/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
tang-0.0.9 spec/tang_app/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js
condenser-0.3 lib/condenser/processors/node_modules/@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js