Skip to content

Commit

Permalink
fix: dont break transform when there is no space between function and…
Browse files Browse the repository at this point in the history
… generic parameter (#305)
  • Loading branch information
brc-dd authored May 4, 2024
1 parent 1605db3 commit 7198ba0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/transform/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export function preProcess({ sourceFile }: PreProcessInput): PreProcessOutput {
nextToken.kind >= ts.SyntaxKind.FirstPunctuation && nextToken.kind <= ts.SyntaxKind.LastPunctuation;

if (isPunctuation) {
code.appendLeft(nextToken.getStart(), defaultExport);
const addSpace = code.slice(token.getEnd(), nextToken.getStart()) != " ";
code.appendLeft(nextToken.getStart(), `${addSpace ? " " : ""}${defaultExport}`);
} else {
code.appendRight(token.getEnd(), ` ${defaultExport}`);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testcases/unnamed-default-export-without-space/expected.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @description @TODO
*/
declare function export_default<T extends object>(
object: T,
initializationObject: {
[x in keyof T]: () => Promise<T[x]>;
},
): Promise<void>;
export { export_default as default };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @description @TODO
*/
export default function<T extends object>(
object: T,
initializationObject: {
[x in keyof T]: () => Promise<T[x]>;
},
): Promise<void>;

0 comments on commit 7198ba0

Please sign in to comment.