Sha256: bb72fa08d1089b1a6e7bd9ffaa3605d15e5bb51efc76f0cf017cdb3b555984dc

Contents?: true

Size: 1.24 KB

Versions: 35

Compression:

Stored size: 1.24 KB

Contents

/**
 * Fixes block-shadowed let/const bindings in Safari 10/11.
 * https://kangax.github.io/compat-table/es6/#test-let_scope_shadow_resolution
 */
export default function({ 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;
            }
          }
        }
      },
    },
  };
}

Version data entries

35 entries across 34 versions & 7 rubygems

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