Skip to content

Commit d2492b1

Browse files
committed
refactor: minor improvements
1 parent 44cfbdb commit d2492b1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/core/src/utils/is-initialized-from-react.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ function getRequireExpressionArguments(node: TSESTree.Node) {
2323
/**
2424
* Check if an identifier is initialized from react
2525
* @param name The top-level identifier's name
26-
* @param source The import source to check against
26+
* @param importSource The import source to check against
2727
* @param initialScope Initial scope to search for the identifier
2828
* @returns Whether the identifier is initialized from react
2929
*/
3030
export function isInitializedFromReact(
3131
name: string,
32-
source: string,
32+
importSource: string,
3333
initialScope: Scope,
3434
): boolean {
3535
if (name.toLowerCase() === "react") return true;
@@ -38,23 +38,23 @@ export function isInitializedFromReact(
3838
const { node, parent } = latestDef;
3939
if (node.type === T.VariableDeclarator && node.init != null) {
4040
const { init } = node;
41-
// check for: `variable = Source.variable`
41+
// check for: `variable = React.variable`
4242
if (init.type === T.MemberExpression && init.object.type === T.Identifier) {
43-
return isInitializedFromReact(init.object.name, source, initialScope);
43+
return isInitializedFromReact(init.object.name, importSource, initialScope);
4444
}
45-
// check for: `{ variable } = Source`
45+
// check for: `{ variable } = React`
4646
if (init.type === T.Identifier) {
47-
return isInitializedFromReact(init.name, source, initialScope);
47+
return isInitializedFromReact(init.name, importSource, initialScope);
4848
}
49-
// check for: `variable = require('source')` or `variable = require('source').variable`
49+
// check for: `variable = require('react')` or `variable = require('react').variable`
5050
const args = getRequireExpressionArguments(init);
5151
const arg0 = args?.[0];
5252
if (arg0 == null || !AST.isKindOfLiteral(arg0, "string")) {
5353
return false;
5454
}
55-
// check for: `require('source')` or `require('source/...')`
56-
return arg0.value === source || arg0.value.startsWith(`${source}/`);
55+
// check for: `require('react')` or `require('react/...')`
56+
return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
5757
}
58-
// latest definition is an import declaration: import { variable } from 'source'
59-
return parent?.type === T.ImportDeclaration && parent.source.value === source;
58+
// latest definition is an import declaration: import { variable } from 'react'
59+
return parent?.type === T.ImportDeclaration && parent.source.value === importSource;
6060
}

0 commit comments

Comments
 (0)