Commit graph

59 commits

Author SHA1 Message Date
michaelm
97a2c41192
fix(isolated-declarations): False positive for class private getter with non-inferrable return type (#5987)
Fixes a case missing from https://github.com/oxc-project/oxc/pull/5964

Co-authored-by: MichaelMitchell-at <=>
2024-09-23 15:28:29 +08:00
DonIsaac
d6cbbe723c test(isolated-declarations): arrow function unions in return signature (#5973) 2024-09-23 02:44:01 +00:00
Dunqing
fd1c46ca9e fix(isolated-declarations): infer failed if there are two setter/getter methods that need to be inferred (#5967) 2024-09-22 13:41:47 +00:00
Dunqing
6df82eee28 fix(isolated-declarations): false positive for class private method that has arguments without type annotations (#5964)
close: #5874
2024-09-22 10:10:52 +00:00
Dunqing
6a9e71da46 fix(isolated-declarations): wrap TSFunctionType in parentheses if it is inside the TSUnionType (#5963) 2024-09-22 10:10:52 +00:00
Dunqing
4a62703d88 feat(isolated-declarations): handle export in the namespace correctly (#5950)
Previous I didn't follow the behavior of `TypeScript` to handle `export` in `namespace` as I thought no one used this
2024-09-21 16:39:58 +00:00
Dunqing
ea32d5b156 fix(isolated-declarations): should print constructor assignments first (#5934) 2024-09-21 07:52:51 +00:00
Boshen
e148c80fcb
fix(isolated_declarations): try fix fixtures 2024-09-21 01:27:56 +08:00
Boshen
ee748b0c05
fix(isolated_declarations): fix fixture spacing 2024-09-21 00:42:59 +08:00
Dunqing
0f96b59990 fix(isolated-declarations): missing print comments in class's private method (#5931) 2024-09-20 15:12:01 +00:00
Dunqing
8780c5440f fix(isolated-declarations): do not union a undefined when the param type is any or unknown (#5930) 2024-09-20 15:12:01 +00:00
Dunqing
f07ff14876 fix(isolated-declarations): should not transform signature that has type annotation (#5927) 2024-09-20 14:19:04 +00:00
Dunqing
b6a9178075 fix(isolated-declarations): don't collect references when ExportNamedDeclaration has source (#5926) 2024-09-20 14:19:03 +00:00
Dunqing
756a571432 fix(isolated-declarations): missing empty export when has an export declare (#5925) 2024-09-20 14:19:02 +00:00
Boshen
84a5816d03
feat(isolated_declarations): add stripInternal (#5878)
closes #3906
closes #5687
closes #3958

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-09-19 23:14:47 +08:00
Dunqing
b9bf54494f fix(isolated-declarations): false positive for setter method in interface (#5681)
close: #5668
2024-09-10 16:22:08 +00:00
Dunqing
6e8409a020 fix(isolated-declarations): bindings referenced in TSModuleDeclaration are removed incorrectly (#5680)
close: #5667
2024-09-10 16:22:07 +00:00
overlookmotel
dc924892cc test: add trailing line breaks to conformance fixtures (#5541)
Continuation of #5537. Ensure all conformance fixture files have a trailing line break.
2024-09-06 12:55:17 +00:00
michaelm
185eb206a8
fix(isolated_declarations): namespaces that are default exported should be considered for expando functions (#4935)
This should be ok but currently has an error reported
```ts
function foo(): void {}

namespace foo {
  export let bar = 42;
}

foo.bar = 42;

export default foo;
```

Co-authored-by: MichaelMitchell-at <=>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-19 11:24:05 +08:00
michaelm
8e80f593fd
fix(isolated_declarations): Class properties should still be lifted from private constructors (#4934)
Before, this
```ts
export class Bux {
  private constructor(
    public readonly prop: number = 0,
    private readonly prop2: number = 1,
    readonly prop3: number = 1,
  ) {}
}
```
would be emitted as 
```ts
export declare class Bux {
	private constructor();
}
```

Now it will be emitted as
```ts
export declare class Bux {
	readonly prop: number;
	private readonly prop2;
	readonly prop3: number;
	private constructor();
}
```

Co-authored-by: MichaelMitchell-at <=>
2024-08-16 21:43:44 +08:00
michaelm
b3ec9e50bd
fix(isolated_declarations): Always emit module declarations that perform augmentation (#4919)
Fixes https://github.com/oxc-project/oxc/issues/4607

Co-authored-by: MichaelMitchell-at <=>
2024-08-16 00:39:28 +08:00
Dunqing
46fb3cbb3e Revert "fix(isolated_declarations): Always emit module declarations (#4911)" (#4916)
This reverts commit 0fb0b71f0d.

test failed  https://github.com/oxc-project/oxc/actions/runs/10405198969/job/28815418191

We should only emit for
```ts
declare module "xx" {}
declare global {}
```

Do not emit for
```ts
module x {}
declare module x {}
```

@MichaelMitchell-at cc
2024-08-15 14:48:28 +00:00
michaelm
0fb0b71f0d
fix(isolated_declarations): Always emit module declarations (#4911)
Fixes https://github.com/oxc-project/oxc/issues/4607

Co-authored-by: MichaelMitchell-at <=>
2024-08-15 22:13:32 +08:00
michaelm
4a16916887
fix(isolated_declarations): Support expando functions (#4910)
I mentioned this issue in a
https://github.com/oxc-project/oxc/issues/4607#issuecomment-2264863618
but I later realized this is actually a separate issue from the one that
I originally reported.

It seems that https://github.com/oxc-project/oxc/pull/3872 added support
for reporting expando function errors, but didn't add support for cases
where expando functions are allowed. This PR adds support for not
reporting errors when there is a namespace declaration that declares the
variable being assigned to.

[TypeScript
playground](https://www.typescriptlang.org/play/?noCheck=true&isolatedDeclarations=true&ts=5.5.4#code/KYDwDg9gTgLgBAMwK4DsDGMCWEWIhACgEoAuOANwkwBM4BvAXwCgF8A6AQzDABsBPOAF44xIQD56zJqEiw4aHAGd4AIw5QhI0hSq1BExkzVQ2aDjx6bR+yUzszo8FBwC2wRWA5pgcAHIBleiY4OAc5BRRlOABzfCttShpxWxDYiDYeYBRomAALTQBGAAYmKTCnV3dPbzwIIJDM1XVNABYAJgBuYNDwRzhGuDUAL0Kioq6pVnTjVs6WdmHR8bsAehW4VHLgaiYIqKG44WIyRL0DZgP0mAh-GChMbPjkxiA)
for reference

---------

Co-authored-by: MichaelMitchell-at <=>
2024-08-15 22:12:16 +08:00
Dunqing
cb1af043b8 fix(isolated-declarations): remove the async and generator keywords from MethodDefinition (#4130)
close: #4120
2024-07-09 03:58:47 +00:00
michaelm
3fcad5e16f
fix(isolated_declarations): Remove nested AssignmentPatterns from inside parameters (#4077)
The default values in destructured parameters are retained in
declarations, which can cause captured variables to be part of the emit
when they shouldn't be. This can also lead to unnecessary isolated
declaration errors when those variables are themselves missing type
annotations and can't be inferred.

For example:
```ts
const x = 42;
const y = '';
export function fooGood3({a = x, b: [{c = y}]}: object): void {}
```

before this change will be emitted as:
```ts
declare const x = 42;
declare const y = '';
export declare function fooGood3({ a = x, b: [{ c = y }] }: object): void;
```

and after this change will be emitted as:
```ts
export declare function fooGood3({ a, b: [{ c }] }: object): void;
```

Co-authored-by: MichaelMitchell-at <=>
2024-07-08 11:06:26 +08:00
michaelm
f8d77e4d7a
fix(isolated_declarations): Infer type of template literal expressions as string (#4068)
In a "non-`const`" context, a template literal string can just be
inferred a `string`. This is consistent with TypeScript's behavior.

Co-authored-by: MichaelMitchell-at <=>
2024-07-08 00:41:33 +08:00
michaelm
1b8f208572
fix(isolated_declarations): correct emit for private static methods (#4064) 2024-07-06 12:30:13 +08:00
Dunqing
3d29e9cb75 fix(isolated-declarations): eliminate imports incorrectly when they are used in TSInferType (#4043)
close: #4018
2024-07-03 15:32:27 +00:00
Egor Blinov
7768d233c6
feat(isolated-declarations): support optional class methods (#4035)
Example class
```
export class A {
  m1?(): void;
  m2(): void {}
}
```

Before the fix:
```
export declare class A {
  m1(): void;
}
```

with the fix:
```
export declare class A {
  m1?(): void;
  m2(): void;
}
```
2024-07-03 09:46:59 +08:00
Egor Blinov
c043bec674
fix(isolated_declarations): add mapped-type constraint to the scope (#4037)
Fixes https://github.com/oxc-project/oxc/issues/4020

Example:
```ts
import {K} from 'foo'
import {T} from 'bar'

export interface I {
    prop: {[key in K]: T}
}
```

Before:
```ts
import {T} from 'bar'
export interface I {
    prop: {[key in K]: T}
}
```

After:
```ts
import {K} from 'foo'
import {T} from 'bar'
export interface I {
    prop: {[key in K]: T}
}
```

TSC:
```ts
import { K } from 'foo';
import { T } from 'bar';
export interface I {
    prop: {
        [key in K]: T;
    };
}

```
2024-07-03 09:45:03 +08:00
Egor Blinov
b007553ebe
fix(isolated_declarations): Fix readonly specifier on class constructor params (#4030) 2024-07-02 23:26:19 +08:00
Egor Blinov
da628399fa
fix(isolated_declarations): inferring literal types for readonly class fileds (#4027) 2024-07-02 23:00:37 +08:00
Dunqing
02ea19a3b7 fix(isolated-declarations): should emit export {} when only having ImportDeclaration (#4026)
close: #4023
2024-07-02 13:47:30 +00:00
Dunqing
7c915f4665 fix(isolated-declarations): binding elements with export should report an error (#4025)
close: #3976
2024-07-02 13:47:28 +00:00
Dunqing
05a047c17d fix(isolated-declarations): method following an abstract method gets dropped (#4024)
close: #4019
2024-07-02 13:47:26 +00:00
Dunqing
bd1141da67 fix(isolated-declarations): if declarations is referenced in declare global then keep it (#3982)
close: #3981
2024-06-30 11:34:04 +00:00
Dunqing
31e4c3b33e fix(isolated-declarations): declare global {} should be kept even if it is not exported (#3956)
close: #3952
2024-06-29 05:07:21 +00:00
Dunqing
27665945f1 fix(codegen): print type parameters for MethodDefinition (#3922)
close: #3918
2024-06-26 07:21:42 +00:00
Dunqing
27f0531aac fix(isolated-declarations): private constructor reaching unreachable (#3921)
fix: #3917
2024-06-26 07:21:38 +00:00
Dunqing
59ce38bb85 fix(isolated-declarations): inferring of UnrayExpression incorrectly (#3920)
close: #3914
2024-06-26 07:21:35 +00:00
Dunqing
5e2baf3edd feat(isolated-declarations): report error for expando functions (#3872)
close: #3703
2024-06-24 10:56:23 +00:00
Dunqing
58e54f4aea fix(isolated-declarations): report an error for parameters if they are ObjectPattern or ArrayPattern without an explicit type (#3810) 2024-06-21 10:20:28 +00:00
Dunqing
a37138f1ec feat(isolated-declarations): improve the inference template literal (#3797) 2024-06-20 15:02:45 +00:00
Dunqing
b0d7355c98 feat(isolated-declarations): transform const expression correctly (#3793) 2024-06-20 15:02:41 +00:00
Dunqing
2821e0e307 feat(codegen): print readonly keyword for TSIndexSignature (#3791) 2024-06-20 10:13:51 +00:00
Dunqing
7d47fc3fcc fix(isolated-declarations): should stripe async and generator keyword after transformed (#3790) 2024-06-20 10:13:44 +00:00
Dunqing
97575d8cab feat(codegen): print TSClassImplements and TSThisParameter (#3786)
close: https://github.com/oxc-project/oxc/issues/3692#issuecomment-2178994839
2024-06-20 06:15:23 +00:00
Dunqing
497769cb60 feat(ast): add some visitor functions (#3785) 2024-06-20 05:23:04 +00:00
Dunqing
b38c34dfce feat(isolated-declarations): support inferring ParenthesizedExpression (#3769) 2024-06-19 15:43:21 +00:00