MCPcopy Index your code
hub / github.com/reactjs/react-codemod / findRequirePathAndBinding

Function findRequirePathAndBinding

transforms/class.js:421–456  ·  view source on GitHub ↗
(moduleName)

Source from the content-addressed store, hash-verified

419 );
420
421 const findRequirePathAndBinding = (moduleName) => {
422 let result = null;
423 const requireCall = root.find(j.VariableDeclarator, {
424 id: {type: 'Identifier'},
425 init: {
426 callee: {name: 'require'},
427 arguments: [{value: moduleName}],
428 },
429 });
430
431 const importStatement = root.find(j.ImportDeclaration, {
432 source: {
433 value: moduleName,
434 },
435 });
436
437 if (importStatement.size()) {
438 importStatement.forEach(path => {
439 result = {
440 path,
441 binding: path.value.specifiers[0].local.name,
442 type: 'import',
443 };
444 });
445 } else if (requireCall.size()) {
446 requireCall.forEach(path => {
447 result = {
448 path,
449 binding: path.value.id.name,
450 type: 'require',
451 };
452 });
453 }
454
455 return result;
456 };
457
458 const pureRenderMixinPathAndBinding = findRequirePathAndBinding(PURE_MIXIN_MODULE_NAME);
459

Callers 1

class.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected