Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch @babel/plugin-transform-typescript to not drop export #174

Merged
merged 1 commit into from Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
},