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

Various Isolated declarations fixes #3976

Closed
wants to merge 9 commits into from

Conversation

escaton
Copy link
Contributor

@escaton escaton commented Jun 29, 2024

I'm playing with "isolated-declarations" in a project with 30k files.
These are fixes I did while attempting to get a successful typecheck.

For now, there is at least one test for each case, and I plan to write more later, but I think I'll need help to make them better.

Copy link

graphite-app bot commented Jun 29, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added A-codegen Area - Code Generation A-isolated-declarations Isolated Declarations labels Jun 29, 2024
is_function_overloads = false;
continue;
}
// if method.value.body.is_none() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO either fix, or uncomment

@@ -16,9 +16,13 @@ mod tests {

let ret = IsolatedDeclarations::new(&allocator).build(&program);
let actual = CodeGenerator::new().build(&ret.program).source_text;
let expected_program = Parser::new(&allocator, expected, source_type).parse().program;
let expected = CodeGenerator::new().build(&expected_program).source_text;
// let expected_program = Parser::new(&allocator, expected, source_type).parse().program;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO revert

@@ -139,3 +139,8 @@ pub fn type_containing_private_name(name: &str, span: Span) -> OxcDiagnostic {
))
.with_label(span)
}

pub fn destructuring_export(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("TS9999: Not supported yet")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to give feedback, that a certain transformation is not supported yet, instead of silently generating wrong .d.ts

Copy link
Member

Choose a reason for hiding this comment

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

I agree, can you provide the examples that need to report this error?

Copy link
Member

Choose a reason for hiding this comment

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

The TSXXXX error code is identical to the error reported by typescript. If you want to report an error that typescript doesn't have, you don't need to add TSXXXX.

Copy link
Contributor Author

@escaton escaton Jun 30, 2024

Choose a reason for hiding this comment

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

can you provide the examples that need to report this error?

  1. I added it here because return None; causes export const {a} = b() to be transformed into export declare const; instead of export declare const a: unknown;.
  2. I also considered adding it here because with current // Skip implementation of function overloads it generates incorrect code, and I don't have ideas how to fix it right away.

Methods in abstract classes could be empty, and it is recognized as overloading:

export abstract class A {
  b(): void;
  c(): void {};
  d(): void {}
}

->

export abstract class A {
  b(): void;
  d(): void {}
}

Copy link
Member

Choose a reason for hiding this comment

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

can you provide the examples that need to report this error?

  1. I added it here because return None; causes export const {a} = b() to be transformed into export declare const; instead of export declare const a: unknown;.

This is a bug. Our goal is to keep the output the same as TypeScript, including diagnostics. if it's not the same, it's considered a bug. So we should report binding_element_export here

  1. I also considered adding it here because with current // Skip implementation of function overloads it generates incorrect code, and I don't have ideas how to fix it right away.

Methods in abstract classes could be empty, and it is recognized as overloading:

export abstract class A {
  b(): void;
  c(): void {};
  d(): void {}
}

->

export abstract class A {
  b(): void;
  d(): void {}
}

This code seems to be incorrect. TypeScript Playground. We assume that the transforms code is correct

Copy link
Member

Choose a reason for hiding this comment

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

The first case is fixed in #3976, The second case has a similar issue, and fixed in #4024

Copy link
Contributor Author

@escaton escaton Jul 2, 2024

Choose a reason for hiding this comment

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

the first case is fixed in #4025, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes!!

@escaton
Copy link
Contributor Author

escaton commented Jun 29, 2024

@Boshen hi!
I'm not sure if you already addressed some of these issues, so let me know if you think this PR can be useful. Of course after some polish.

@Boshen Boshen requested a review from Dunqing June 30, 2024 06:40
@Boshen
Copy link
Member

Boshen commented Jun 30, 2024

Thank you in advance. I have copied over the codegen changes in https://app.graphite.dev/github/pr/oxc-project/oxc/3980 so I can make a quicker release.

@Boshen
Copy link
Member

Boshen commented Jun 30, 2024

@Boshen hi! I'm not sure if you already addressed some of these issues, so let me know if you think this PR can be useful. Of course after some polish.

cc @Dunqing

@Dunqing
Copy link
Member

Dunqing commented Jun 30, 2024

Thank you for working on this! If you need to add test, please add in fixtures. The deno.rs is copy from https://github.com/denoland/deno_graph/blob/main/src/fast_check/transform_dts.rs#L932-#L1532

@Dunqing
Copy link
Member

Dunqing commented Jul 2, 2024

Thank you for your feedback! All known bugs are about to be fixed. Please Feel free to send an RP fix if you find other bugs.

@Dunqing Dunqing closed this Jul 2, 2024
@escaton
Copy link
Contributor Author

escaton commented Jul 2, 2024

@Dunqing I think these commits are still actual

I'll create another PR for them with proper tests

@Dunqing
Copy link
Member

Dunqing commented Jul 2, 2024

@Dunqing I think these commits are still actual

I'll create another PR for them with proper tests

Yes, go ahead!

Boshen pushed a commit that referenced this pull request Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area - Code Generation A-isolated-declarations Isolated Declarations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants