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

fix: Remove type-only import x = y.z #17025

Merged

Conversation

liuxingbaoyu
Copy link
Member

Q                       A
Fixed Issues? Fixes #15942
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This seems a bit dangerous and I'm not sure if this will cause a regression.

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: typescript labels Dec 14, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented Dec 14, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58578

Comment on lines 277 to 283
ReferencedIdentifier(path, state) {
if (t.isTSQualifiedName(path.parent) && path.parent.right === path.node) {
return;
}
if (path.parentPath.isTSImportEqualsDeclaration()) return;
state.references.push(path);
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use childPath.skip() to make it easier to re-land #16923 in the future.

@@ -1,2 +1 @@
import * as joint from '@joint/core';
export var JGraph = joint.dia.Graph;
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, what if joint.dia.Graph is a value and not a type?

import * as x from "x";

export import foo = x.foo;

should behave the same as

import { foo } from "x";

export { foo };

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jan 10, 2025

Failure looks relevant :)

@nicolo-ribaudo
Copy link
Member

How does this PR interact with the onlyRemoveTypeImports option? Can we have a test verifying that we only remove import type foo = and not import foo = when it's enabled?

@liuxingbaoyu
Copy link
Member Author

image
TS doesn't seem to support this yet.

@nicolo-ribaudo
Copy link
Member

Oh I see. It seems like TypeScript simply does not remove it when the equivalent TS option (verbatimModuleSyntax) is enabled: https://www.typescriptlang.org/play/?verbatimModuleSyntax=true#code/JYWwDg9gTgLgBAbzgIwIZTgXzgMyhEOAIgA8iBuAKFEllwgjgF4V0A6NALyuvGnhgBPMAFNEcVMgDGWXPkKkKvWvAAmInMwnS2JKkNFwAFgHNgWyVN08gA Instead, people should just replace import with type.

@nicolo-ribaudo nicolo-ribaudo merged commit ad572fd into babel:main Jan 14, 2025
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: typescript PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: TypeScript type only import namespace aliases are not removed
4 participants