-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/isolated-dts): Preserve comments (#9572)
**Related issue:** - Closes #9550
- Loading branch information
Showing
12 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
swc_core: patch | ||
swc: patch | ||
--- | ||
|
||
fix(es/isolated-dts): Preserve comments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
crates/swc/tests/ts-isolated-declaration/issues/input/.swcrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
}, | ||
"experimental": { | ||
"emitIsolatedDts": true | ||
} | ||
}, | ||
"isModule": true | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/swc/tests/ts-isolated-declaration/issues/input/swc-issue-9550.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Sample JSDoc that I wish was in the swc.transform output | ||
* @param a - string param | ||
* @param b - number param | ||
* @returns - object with a and b | ||
*/ | ||
function sampleFunc(a: string, b: number) { | ||
return { a, b }; | ||
} |
6 changes: 6 additions & 0 deletions
6
crates/swc/tests/ts-isolated-declaration/issues/output/swc-issue-9550.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Sample JSDoc that I wish was in the swc.transform output | ||
* @param a - string param | ||
* @param b - number param | ||
* @returns - object with a and b | ||
*/ declare function sampleFunc(a: string, b: number); |
11 changes: 11 additions & 0 deletions
11
crates/swc/tests/ts-isolated-declaration/issues/output/swc-issue-9550.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Sample JSDoc that I wish was in the swc.transform output | ||
* @param a - string param | ||
* @param b - number param | ||
* @returns - object with a and b | ||
*/ function sampleFunc(a, b) { | ||
return { | ||
a: a, | ||
b: b | ||
}; | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/swc/tests/ts-isolated-declaration/oxc/output/async-function.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// Correct | ||
declare async function asyncFunctionGood(): Promise<number>; | ||
declare const asyncFunctionGoo2: () => Promise<number>; | ||
// Need to explicit return type for async functions | ||
// Incorrect | ||
declare async function asyncFunction(); | ||
declare const asyncFunction2: () => any; |
2 changes: 2 additions & 0 deletions
2
crates/swc/tests/ts-isolated-declaration/oxc/output/function-parameters.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
crates/swc/tests/ts-isolated-declaration/oxc/output/generator.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
// Correct | ||
declare function* generatorGood(): Generator<number>; | ||
// Need to explicit return type for async functions | ||
// Incorrect | ||
declare function* generatorGoodBad(); |
1 change: 1 addition & 0 deletions
1
crates/swc/tests/ts-isolated-declaration/oxc/output/infer-expression.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// ParenthesizedExpression | ||
declare const n: any; | ||
declare const s: any; | ||
declare const t: any; | ||
|
3 changes: 3 additions & 0 deletions
3
crates/swc/tests/ts-isolated-declaration/oxc/output/infer-return-type.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
declare function foo(); | ||
// inferred type is number | ||
declare function bar(); | ||
// inferred type is number | undefined | ||
declare function baz(); | ||
// We can't infer return type if there are multiple return statements with different types | ||
declare function qux(); |
2 changes: 2 additions & 0 deletions
2
crates/swc/tests/ts-isolated-declaration/oxc/output/non-exported-binding-elements.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// Correct | ||
declare const [A, B]; | ||
export declare function foo(): number; | ||
// Incorrect | ||
declare const { c, d }; | ||
declare const [e]; | ||
export { c, d, e }; |