Skip to content

Commit

Permalink
fix: Ensure that getShortType regex wildcard is non-greedy (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
collink authored Aug 7, 2024
1 parent c6e980b commit 8eb0f33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common.mts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function extractPropertiesFromObjectParam(param: ParameterDeclaration) {
* TODO: Replace with a more robust solution.
*/
export function getShortType(type: string) {
return type.replaceAll(/import\(".*"\)\./g, "");
return type.replaceAll(/import\(".*?"\)\./g, "");
}

export function getClassesFromService(node: SourceFile) {
Expand Down
9 changes: 9 additions & 0 deletions tests/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ describe("common", () => {
const result = getShortType(type);
expect(result).toBe("MyType");
});

test("json", () => {
const type =
'{ import1?: import("/path/to/import1").Import1; import2: import("/path/to/import2").Import2; import3: import("/path/to/import3").Import3; }';
const result = getShortType(type);
expect(result).toBe(
"{ import1?: Import1; import2: Import2; import3: Import3; }",
);
});
});

test("formatOptions - converts string boolean to boolean (false)", () => {
Expand Down

0 comments on commit 8eb0f33

Please sign in to comment.