fix(isolated_declarations): try fix new line issue

This commit is contained in:
Boshen 2024-09-21 01:14:40 +08:00
parent ee748b0c05
commit 9b3f763a49
No known key found for this signature in database
GPG key ID: 67715A371E534061
23 changed files with 55 additions and 2 deletions

View file

@ -29,7 +29,8 @@ fn transform(path: &Path, source_text: &str) -> String {
.build(&id_ret.program) .build(&id_ret.program)
.source_text; .source_text;
let mut snapshot = format!("==================== .D.TS ====================\n\n{code}\n\n"); let mut snapshot =
format!("```\n==================== .D.TS ====================\n\n{code}\n\n");
if !id_ret.errors.is_empty() { if !id_ret.errors.is_empty() {
let source = Arc::new(source_text.to_string()); let source = Arc::new(source_text.to_string());
let error_messages = id_ret let error_messages = id_ret
@ -41,7 +42,7 @@ fn transform(path: &Path, source_text: &str) -> String {
.join("\n"); .join("\n");
snapshot.push_str(&format!( snapshot.push_str(&format!(
"==================== Errors ====================\n\n{error_messages}\n\n" "==================== Errors ====================\n\n{error_messages}\n\n```"
)); ));
} }

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/arrow-function-return-type.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare function A(): unknown; declare function A(): unknown;
@ -38,3 +39,6 @@ declare const D: () => string;
: ^ : ^
10 | 10 |
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/as-const.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/as-const.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare const F: { declare const F: {

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/async-function.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/async-function.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare function asyncFunctionGood(): Promise<number>; declare function asyncFunctionGood(): Promise<number>;
@ -44,3 +45,6 @@ declare class AsyncClassBad {
: ^^^^^^ : ^^^^^^
26 | return 42; 26 | return 42;
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/class.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/class.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export declare class Foo { export declare class Foo {

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare function MyFunction(): string; declare function MyFunction(): string;

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2 } from "mod"; import { AExtend, BExtend, Type, CImplements1, CImplements2, CType, ThisType1, ThisType2 } from "mod";

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/empty-export.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/empty-export.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
type A = string; type A = string;

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/empty-export2.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/empty-export2.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export {}; export {};

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export declare function foo(): void; export declare function foo(): void;
@ -60,3 +61,6 @@ export default qux;
: ^^^^^^^^^^ : ^^^^^^^^^^
11 | } 11 | }
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/function-overloads.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare function a(a: number): number; declare function a(a: number): number;

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export declare function fnDeclGood(p?: T, rParam?: string): void; export declare function fnDeclGood(p?: T, rParam?: string): void;
@ -73,3 +74,6 @@ export declare function withUnknown(a: unknown, b: string): void;
: ^^^^^^^^^^^^^^^^^^^^^^^ : ^^^^^^^^^^^^^^^^^^^^^^^
27 | return 2; 27 | return 2;
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/generator.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/generator.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare function generatorGood(): Generator<number>; declare function generatorGood(): Generator<number>;
@ -33,3 +34,6 @@ declare class GeneratorClassBad {
: ^^^^^^ : ^^^^^^
22 | yield 50; 22 | yield 50;
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-expression.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-expression.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare const n: number; declare const n: number;
@ -41,3 +42,6 @@ declare const unaryE: {};
18 | const unaryE = {E: -"str"} as const 18 | const unaryE = {E: -"str"} as const
: ^^^^^^ : ^^^^^^
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-return-type.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-return-type.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare function foo(): number; declare function foo(): number;
@ -21,3 +22,6 @@ declare function quux(): string;
: ^^^ : ^^^
15 | if (a) { 15 | if (a) {
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-template-literal.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/infer-template-literal.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export declare const CSS_VARS_HELPER = "useCssVars"; export declare const CSS_VARS_HELPER = "useCssVars";
@ -33,3 +34,6 @@ export declare let BAD2: unknown;
14 | export let BAD2 = `useCssV${v}ars` as const 14 | export let BAD2 = `useCssV${v}ars` as const
: ^^^^ : ^^^^
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/mapped-types.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/mapped-types.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
import { K } from "foo"; import { K } from "foo";

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
import "foo"; import "foo";

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding-elements.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding-elements.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export declare function foo(): number; export declare function foo(): number;
@ -53,3 +54,6 @@ export declare const;
: ^ : ^
10 | export { c, d, e } 10 | export { c, d, e }
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/readonly.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/readonly.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export declare const EMPTY_OBJ: { readonly [key: string]: any }; export declare const EMPTY_OBJ: { readonly [key: string]: any };

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/set-get-accessor.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/set-get-accessor.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare class Cls { declare class Cls {
@ -28,3 +29,6 @@ declare class ClsBad {
: ^ : ^
22 | return; 22 | return;
`---- `----
```

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/signatures.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/signatures.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
export interface X { export interface X {

View file

@ -2,6 +2,7 @@
source: crates/oxc_isolated_declarations/tests/mod.rs source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/strip-internal.ts input_file: crates/oxc_isolated_declarations/tests/fixtures/strip-internal.ts
--- ---
```
==================== .D.TS ==================== ==================== .D.TS ====================
declare class StripInternalClassFields {} declare class StripInternalClassFields {}