main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.default = void 0;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Safari ~11 has an issue where variable declarations in a For statement throw if they shadow parameters.
|
---|
8 | * This is fixed by renaming any declarations in the left/init part of a For* statement so they don't shadow.
|
---|
9 | * @see https://bugs.webkit.org/show_bug.cgi?id=171041
|
---|
10 | *
|
---|
11 | * @example
|
---|
12 | * e => { for (let e of []) e } // throws
|
---|
13 | * e => { for (let _e of []) _e } // works
|
---|
14 | */
|
---|
15 | function handle(declaration) {
|
---|
16 | if (!declaration.isVariableDeclaration()) return;
|
---|
17 | const fn = declaration.getFunctionParent();
|
---|
18 | const {
|
---|
19 | name
|
---|
20 | } = declaration.node.declarations[0].id; // check if there is a shadowed binding coming from a parameter
|
---|
21 |
|
---|
22 | if (fn && fn.scope.hasOwnBinding(name) && fn.scope.getOwnBinding(name).kind === "param") {
|
---|
23 | declaration.scope.rename(name);
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | var _default = () => ({
|
---|
28 | name: "transform-safari-for-shadowing",
|
---|
29 | visitor: {
|
---|
30 | ForXStatement(path) {
|
---|
31 | handle(path.get("left"));
|
---|
32 | },
|
---|
33 |
|
---|
34 | ForStatement(path) {
|
---|
35 | handle(path.get("init"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | }
|
---|
39 | });
|
---|
40 |
|
---|
41 | exports.default = _default;
|
---|
42 | module.exports = exports.default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.