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
immosquare-cleaner-0.1.62 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.61 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.60 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.59 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.58 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.57 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.56 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.55 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.54 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.53 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.52 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.51 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
optimacms-0.1.61 spec/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js
disco_app-0.16.1 test/dummy/node_modules/@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js