Skip to content

Commit 8eb0f33

Browse files
authored
fix: Ensure that getShortType regex wildcard is non-greedy (#135)
1 parent c6e980b commit 8eb0f33

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/common.mts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function extractPropertiesFromObjectParam(param: ParameterDeclaration) {
116116
* TODO: Replace with a more robust solution.
117117
*/
118118
export function getShortType(type: string) {
119-
return type.replaceAll(/import\(".*"\)\./g, "");
119+
return type.replaceAll(/import\(".*?"\)\./g, "");
120120
}
121121

122122
export function getClassesFromService(node: SourceFile) {

tests/common.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ describe("common", () => {
8080
const result = getShortType(type);
8181
expect(result).toBe("MyType");
8282
});
83+
84+
test("json", () => {
85+
const type =
86+
'{ import1?: import("/path/to/import1").Import1; import2: import("/path/to/import2").Import2; import3: import("/path/to/import3").Import3; }';
87+
const result = getShortType(type);
88+
expect(result).toBe(
89+
"{ import1?: Import1; import2: Import2; import3: Import3; }",
90+
);
91+
});
8392
});
8493

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

0 commit comments

Comments
 (0)