forked from preactjs/signals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path@babel__plugin-transform-typescript@7.19.1.patch
54 lines (48 loc) · 1.51 KB
/
@babel__plugin-transform-typescript@7.19.1.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
diff --git a/lib/index.js b/lib/index.js
index 9753d47727d94827bc40a674a721527e50331acd..9c7acc8d88ffd1b588f5c4c9c3a73256892c30dd 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -54,6 +54,20 @@ function registerGlobalType(programScope, name) {
GLOBAL_TYPES.get(programScope).add(name);
}
+// A hack to avoid removing the impl Binding when we remove the declare NodePath
+function safeRemove(path) {
+ const ids = path.getBindingIdentifiers();
+ for (const name of Object.keys(ids)) {
+ const binding = path.scope.getBinding(name);
+ if (binding && binding.identifier === ids[name]) {
+ binding.scope.removeBinding(name);
+ }
+ }
+ path.opts.noScope = true;
+ path.remove();
+ path.opts.noScope = false;
+}
+
var _default = (0, _helperPluginUtils.declare)((api, opts) => {
api.assertVersion(7);
const JSX_PRAGMA_REGEX = /\*?\s*@jsx((?:Frag)?)\s+([^\s]+)/;
@@ -347,16 +361,16 @@ var _default = (0, _helperPluginUtils.declare)((api, opts) => {
},
TSDeclareFunction(path) {
- path.remove();
+ safeRemove(path)
},
TSDeclareMethod(path) {
- path.remove();
+ safeRemove(path)
},
VariableDeclaration(path) {
if (path.node.declare) {
- path.remove();
+ safeRemove(path)
}
},
@@ -376,7 +390,7 @@ var _default = (0, _helperPluginUtils.declare)((api, opts) => {
} = path;
if (node.declare) {
- path.remove();
+ safeRemove(path)
return;
}
},