Sha256: 7c3299e07411b6fd47036ff51968e910586600ff411297e517cfe37029fe343a

Contents?: true

Size: 1.31 KB

Versions: 35

Compression:

Stored size: 1.31 KB

Contents

"use strict";

exports.__esModule = true;
exports.default = _default;

/**
 * Fixes block-shadowed let/const bindings in Safari 10/11.
 * https://kangax.github.io/compat-table/es6/#test-let_scope_shadow_resolution
 */
function _default({
  types: t
}) {
  return {
    name: "transform-safari-block-shadowing",
    visitor: {
      VariableDeclarator(path) {
        // the issue only affects let and const bindings:
        const kind = path.parent.kind;
        if (kind !== "let" && kind !== "const") return; // ignore non-block-scoped bindings:

        const block = path.scope.block;
        if (t.isFunction(block) || t.isProgram(block)) return;
        const bindings = t.getOuterBindingIdentifiers(path.node.id);

        for (const name of Object.keys(bindings)) {
          let scope = path.scope; // ignore parent bindings (note: impossible due to let/const?)

          if (!scope.hasOwnBinding(name)) continue; // check if shadowed within the nearest function/program boundary

          while (scope = scope.parent) {
            if (scope.hasOwnBinding(name)) {
              path.scope.rename(name);
              break;
            }

            if (t.isFunction(scope.block) || t.isProgram(scope.block)) {
              break;
            }
          }
        }
      }

    }
  };
}

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