Skip to content

Commit c930e0d

Browse files
authored
fix: respecting quote style in type imports (#257)
1 parent 1bbf9ee commit c930e0d

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ function writeImportDetailsToSpec(
732732
: `{${typeString}}`;
733733
importClauses.push(namedImportClause);
734734
}
735-
spec.description = `${importClauses.join(", ")} from "${src}"`;
735+
const quote = options.singleQuote ? "'" : '"';
736+
spec.description = `${importClauses.join(", ")} from ${quote}${src}${quote}`;
736737
}
737738

738739
/**

tests/__snapshots__/typeScript.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ exports[`max width challenge 1`] = `
159159
"
160160
`;
161161
162+
exports[`type import with single quote 1`] = `
163+
"/**
164+
* @import {B} from 'bar'
165+
* @import {A} from 'foo'
166+
*/
167+
"
168+
`;
169+
162170
exports[`type imports 1`] = `
163171
"/**
164172
* @import {A} from "modulea"
@@ -177,6 +185,14 @@ exports[`type imports 1`] = `
177185
"
178186
`;
179187
188+
exports[`type imports with double quote 1`] = `
189+
"/**
190+
* @import {B} from "bar"
191+
* @import {A} from "foo"
192+
*/
193+
"
194+
`;
195+
180196
exports[`type imports with import merging turned off 1`] = `
181197
"/**
182198
* @import {A} from "modulea"

tests/typeScript.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,30 @@ test("type imports with no import formatting", async () => {
295295
expect(result).toMatchSnapshot();
296296
});
297297

298+
test("type import with single quote", async () => {
299+
const result = await subject(
300+
`
301+
/**
302+
* @import { A } from "foo"
303+
* @import { B } from 'bar'
304+
*/
305+
`,
306+
{ singleQuote: true },
307+
);
308+
309+
expect(result).toMatchSnapshot();
310+
});
311+
312+
test("type imports with double quote", async () => {
313+
const result = await subject(
314+
`
315+
/**
316+
* @import { A } from 'foo'
317+
* @import { B } from "bar"
318+
*/
319+
`,
320+
{ singleQuote: false },
321+
);
322+
323+
expect(result).toMatchSnapshot();
324+
});

0 commit comments

Comments
 (0)