Sha256: db1bcaf3a652ad5e23699f2de81c7390d2a17f9409b2b141b86d20be26733733

Contents?: true

Size: 1012 Bytes

Versions: 24

Compression:

Stored size: 1012 Bytes

Contents

/**
 * 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);
  }
}

export default () => ({
  name: "transform-safari-for-shadowing",
  visitor: {
    ForXStatement(path) {
      handle(path.get("left"));
    },

    ForStatement(path) {
      handle(path.get("init"));
    },
  },
});

Version data entries

24 entries across 23 versions & 7 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
optimacms-0.1.61 spec/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.16.1 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.15.2 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.18.4 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.18.1 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.14.0 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
tang-0.2.1 spec/tang_app/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@babel/preset-modules/src/plugins/transform-safari-for-shadowing/index.js