Skip to content

Commit

Permalink
Merge pull request #174 from preactjs/babel-typescript-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Sep 18, 2022
2 parents d351c3f + 2f02a08 commit 22f564d
Show file tree
Hide file tree
Showing 3 changed files with 610 additions and 423 deletions.
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -28,10 +28,11 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/core": "^7.19.1",
"@babel/preset-env": "^7.19.1",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/plugin-transform-typescript": "^7.19.1",
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.2",
"@types/chai": "^4.3.3",
Expand Down Expand Up @@ -83,7 +84,8 @@
},
"pnpm": {
"patchedDependencies": {
"microbundle@0.15.1": "patches/microbundle@0.15.1.patch"
"microbundle@0.15.1": "patches/microbundle@0.15.1.patch",
"@babel/plugin-transform-typescript@7.19.1": "patches/@babel__plugin-transform-typescript@7.19.1.patch"
}
}
}
54 changes: 54 additions & 0 deletions patches/@babel__plugin-transform-typescript@7.19.1.patch
@@ -0,0 +1,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;
}
},

0 comments on commit 22f564d

Please sign in to comment.