Skip to content

Commit 9d4dfd1

Browse files
committed
fix(injector): don't import prop-types if it's already imported
1 parent 3c8a9a4 commit 9d4dfd1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: src/injector.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function plugin(propTypes: t.ProgramNode, options: InjectOptions = {}): babel.Pl
3535

3636
let importName = '';
3737
let needImport = false;
38+
let alreadyImported = false;
3839

3940
return {
4041
visitor: {
@@ -48,6 +49,7 @@ function plugin(propTypes: t.ProgramNode, options: InjectOptions = {}): babel.Pl
4849
n.specifiers.length
4950
) {
5051
importName = n.specifiers[0].local.name;
52+
alreadyImported = true;
5153
return true;
5254
}
5355
})
@@ -56,7 +58,7 @@ function plugin(propTypes: t.ProgramNode, options: InjectOptions = {}): babel.Pl
5658
}
5759
},
5860
exit(path) {
59-
if (!needImport) return;
61+
if (alreadyImported || !needImport) return;
6062

6163
const x = babel.template.ast(`import ${importName} from 'prop-types'`);
6264

0 commit comments

Comments
 (0)