|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | exports.__esModule = true;
|
|---|
| 4 | exports.default = _default;
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * Fixes block-shadowed let/const bindings in Safari 10/11.
|
|---|
| 8 | * https://kangax.github.io/compat-table/es6/#test-let_scope_shadow_resolution
|
|---|
| 9 | */
|
|---|
| 10 | function _default({
|
|---|
| 11 | types: t
|
|---|
| 12 | }) {
|
|---|
| 13 | return {
|
|---|
| 14 | name: "transform-safari-block-shadowing",
|
|---|
| 15 | visitor: {
|
|---|
| 16 | VariableDeclarator(path) {
|
|---|
| 17 | // the issue only affects let and const bindings:
|
|---|
| 18 | const kind = path.parent.kind;
|
|---|
| 19 | if (kind !== "let" && kind !== "const") return; // ignore non-block-scoped bindings:
|
|---|
| 20 |
|
|---|
| 21 | const block = path.scope.block;
|
|---|
| 22 | if (t.isFunction(block) || t.isProgram(block)) return;
|
|---|
| 23 | const bindings = t.getOuterBindingIdentifiers(path.node.id);
|
|---|
| 24 |
|
|---|
| 25 | for (const name of Object.keys(bindings)) {
|
|---|
| 26 | let scope = path.scope; // ignore parent bindings (note: impossible due to let/const?)
|
|---|
| 27 |
|
|---|
| 28 | if (!scope.hasOwnBinding(name)) continue; // check if shadowed within the nearest function/program boundary
|
|---|
| 29 |
|
|---|
| 30 | while (scope = scope.parent) {
|
|---|
| 31 | if (scope.hasOwnBinding(name)) {
|
|---|
| 32 | path.scope.rename(name);
|
|---|
| 33 | break;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | if (t.isFunction(scope.block) || t.isProgram(scope.block)) {
|
|---|
| 37 | break;
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | }
|
|---|
| 44 | };
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | module.exports = exports.default; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.