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

feat(typescript): Align isolatedDeclaration implementation with tsc #9715

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

CPunisher
Copy link
Contributor

@CPunisher CPunisher commented Nov 5, 2024

Description:

  • Basic implementation. This also includes diagnostics and type inference.
    • Function
    • Class
    • Variable declaration
    • Enum
  • Remove unused imports and declarations. Based on the result ast of fast dts transformation, we collect the usage of ids which also contain syntax context. Then we prune the ast to cut off the unused imports and declarations.
  • Port tests and bug fixes. To ensure correctness, I'd like to port the fixtures as oxc does https://github.com/oxc-project/oxc/tree/main/crates/oxc_isolated_declarations/tests/fixtures.
  • Benmarks
  • Strip internal

Most code is direct translation of https://github.com/oxc-project/oxc/tree/main/crates/oxc_isolated_declarations. The differences come from:

  1. swc and oxc use different ast.
  2. The transformation of swc is mutation-based, which directly mutates the whole cloned ast, while the transformation of oxc is immutation-based, which constructs and copies the ast nodes on demand. Maybe mutation-based transformation is not better, but I think it's also annoyed to construct ast nodes and it could be easy to refactor if there is some demands in the future.
  3. oxc transforms while collecting references information to prune unused idents, which increases the code complexity. However, the ast nodes of swc contain syntax context, we don't need to collect the information again.
  4. I think oxc could have bugs. I manually compare the result with tsc --declaration --isolatedDeclarations --emitDeclarationOnly --isolatedModules --noResolve --noCheck --strictNullChecks test.ts

BREAKING CHANGE:
It will change most of the generated results of d.ts.

Related issue (if exists):
closes #9705
closes #9718

Copy link

changeset-bot bot commented Nov 5, 2024

⚠️ No Changeset found

Latest commit: f8a2e67

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CPunisher CPunisher changed the title feat(typescript): remove unused import in isolatedDeclaration feat(typescript): remove unused imports and declarations in isolatedDeclaration Nov 5, 2024
@SoonIter
Copy link

SoonIter commented Nov 5, 2024

thanks for your help❤️️

😂 got another blocking point of isolatedDeclaration

should generate the same error as tsc

src/App.tsx(8,10): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations.

I'll open another issue

Copy link

codspeed-hq bot commented Nov 5, 2024

CodSpeed Performance Report

Merging #9715 will improve performances by 9.3%

Comparing CPunisher:feat/isolated-decl-minify (5f74590) with main (6ad0735)

Summary

⚡ 1 improvements
✅ 193 untouched benchmarks

Benchmarks breakdown

Benchmark main CPunisher:feat/isolated-decl-minify Change
es/full/base/fixer 127.4 µs 116.6 µs +9.3%

@CPunisher CPunisher changed the title feat(typescript): remove unused imports and declarations in isolatedDeclaration feat(typescript): align tsc isolatedDeclaration Nov 12, 2024
@CPunisher CPunisher changed the title feat(typescript): align tsc isolatedDeclaration feat(typescript): align isolatedDeclaration implementation with tsc Nov 12, 2024
@CPunisher CPunisher changed the title feat(typescript): align isolatedDeclaration implementation with tsc feat(typescript): Align isolatedDeclaration implementation with tsc Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants