Skip to content

Commit 8d4b974

Browse files
committed
update-react-imports: Preserve quotes
1 parent e0e076c commit 8d4b974

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { Fragment, useState } from "react";
1+
import { Fragment, useState } from 'react';
22

3-
<Fragment />
3+
<Fragment />

transforms/update-react-imports.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ module.exports = function(file, api, options) {
7171
}
7272

7373
const reactPath = reactPaths.paths()[0];
74+
// Reuse the node so that we can preserve quoting style.
75+
const reactLiteral = reactPath.value.source;
7476

7577
const isDefaultImport = reactPath.value.specifiers.some(
7678
specifier =>
@@ -276,12 +278,12 @@ module.exports = function(file, api, options) {
276278

277279
if (regularImports.length > 0) {
278280
j(reactPath).insertAfter(
279-
j.importDeclaration(regularImports, j.literal('react')),
281+
j.importDeclaration(regularImports, reactLiteral),
280282
);
281283
}
282284
if (typeImports.length > 0) {
283285
j(reactPath).insertAfter(
284-
j.importDeclaration(typeImports, j.literal('react'), 'type'),
286+
j.importDeclaration(typeImports, reactLiteral, 'type'),
285287
);
286288
}
287289

@@ -301,7 +303,7 @@ module.exports = function(file, api, options) {
301303
j(path).insertAfter(
302304
j.importDeclaration(
303305
[j.importDefaultSpecifier(j.identifier('React'))],
304-
j.literal('react'),
306+
reactLiteral,
305307
'type',
306308
),
307309
);
@@ -326,7 +328,7 @@ module.exports = function(file, api, options) {
326328
j(reactPath).insertAfter(
327329
j.importDeclaration(
328330
[j.importNamespaceSpecifier(j.identifier('React'))],
329-
j.literal('react'),
331+
reactLiteral,
330332
),
331333
);
332334
}
@@ -345,12 +347,12 @@ module.exports = function(file, api, options) {
345347
}
346348
if (regularImports.length > 0) {
347349
j(reactPath).insertAfter(
348-
j.importDeclaration(regularImports, j.literal('react')),
350+
j.importDeclaration(regularImports, reactLiteral),
349351
);
350352
}
351353
if (typeImports.length > 0) {
352354
j(reactPath).insertAfter(
353-
j.importDeclaration(typeImports, j.literal('react'), 'type'),
355+
j.importDeclaration(typeImports, reactLiteral, 'type'),
354356
);
355357
}
356358
}

0 commit comments

Comments
 (0)