Skip to content

Commit

Permalink
fixup! [New] Components.detect tracks React imports
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Nov 28, 2021
1 parent ab7dafa commit 8c39df4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/util/Components.js
Expand Up @@ -189,8 +189,8 @@ class Components {
*
* @returns {ASTNode} React default import node
*/
getDefaultReactImport() {
return ReactImports.get(this).defaultReactImport;
getDefaultReactImports() {
return ReactImports.get(this).defaultReactImports;
}

/**
Expand All @@ -211,7 +211,7 @@ class Components {
addDefaultReactImport(specifier) {
const info = ReactImports.get(this);
ReactImports.set(this, Object.assign({}, info, {
defaultReactImport: specifier,
defaultReactImports: (info.defaultReactImports || []).concat(specifier),
}));
}

Expand Down
10 changes: 6 additions & 4 deletions tests/util/Component.js
Expand Up @@ -77,12 +77,14 @@ describe('Components', () => {
testComponentsDetect({
code: 'import React, { useCallback, useState } from \'react\'',
}, (_context, components) => {
const defaultReactImport = components.getDefaultReactImport();
assert(defaultReactImport.local.name === 'React', 'default React import identifier should be "React"');
assert.deepEqual(
components.getDefaultReactImports().map((specifier) => specifier.local.name),
['React'],
'default React import identifier should be "React"'
);

const namedReactImports = components.getNamedReactImports();
assert.deepEqual(
namedReactImports.map((specifier) => specifier.local.name),
components.getNamedReactImports().map((specifier) => specifier.local.name),
['useCallback', 'useState'],
'named React import identifiers should be "useCallback" and "useState"'
);
Expand Down

0 comments on commit 8c39df4

Please sign in to comment.