Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolveDefinition(definition, types) {
if (isReactCreateClassCall(definition)) {
// return argument
const resolvedPath = resolveToValue(definition.get('arguments', 0));
if (types.ObjectExpression.check(resolvedPath.node)) {
return resolvedPath;
}
} else if (isReactComponentClass(definition) || isDecoratedBy(definition, 'cn')) {
normalizeClassDefinition(definition);
return definition;
} else if (isStatelessComponent(definition)) {
return definition;
}
return null;
}
function resolveDefinition(definition, types) {
if (isReactCreateClassCall(definition)) {
// return argument
var resolvedPath = resolveToValue(definition.get('arguments', 0));
if (types.ObjectExpression.check(resolvedPath.node)) {
return resolvedPath;
}
} else if (isReactComponentClass(definition)) {
normalizeClassDefinition(definition);
return definition;
} else if (isStatelessComponent(definition)) {
return definition;
} else if (isSimpleTag(definition)) {
var resolvedPath = resolveToValue(definition.get('arguments', 0));
return resolvedPath;
} else if (isWithMDC(definition)) {
var resolvedPath = resolveToValue(definition.get('arguments', 0));
return resolvedPath;
}
function resolveDefinition(definition, types) {
if (isReactCreateClassCall(definition)) {
// return argument
var resolvedPath = resolveToValue(definition.get('arguments', 0));
if (types.ObjectExpression.check(resolvedPath.node)) {
return resolvedPath;
}
} else if (isReactComponentClass(definition)) {
normalizeClassDefinition(definition);
return definition;
} else if (isStatelessComponent(definition)) {
return definition;
} else if (isSimpleTag(definition)) {
var resolvedPath = resolveToValue(definition.get('arguments', 0));
return resolvedPath;
} else if (isWithMDC(definition)) {
var resolvedPath = resolveToValue(definition.get('arguments', 0));
return resolvedPath;
}
return null;
}
visitAssignmentExpression(path) {
// Ignore anything that is not `exports.X = ...;` or
// `module.exports = ...;`
if (!isExportsOrModuleAssignment(path)) {
return false;
}
// Resolve the value of the right hand side. It should resolve to a call
// expression, something like React.createClass
path = resolveToValue(path.get('right'));
if (!isComponentDefinition(path)) {
path = resolveToValue(resolveHOC(path));
if (!isComponentDefinition(path)) {
return false;
}
}
if (definition) {
// If a file exports multiple components, ... complain!
throw new Error(ERROR_MULTIPLE_DEFINITIONS);
}
definition = resolveDefinition(path, types);
return false;
}
});
.reduce((acc, def) => {
if (isComponentDefinition(def)) {
acc.push(def);
return acc;
}
const resolved = resolveToValue(resolveHOC(def));
if (isComponentDefinition(resolved)) {
acc.push(resolved);
return acc;
}
if (isDecoratedBy(def, 'cn') && def.get('superClass')) {
const superClass = def.get('superClass');
if (!originalClassName) { // save original component name and use it to patch parent class
originalClassName = def.get('id').value.name;
}
const src = getSourceFileContent(importedModules[superClass.value.name], filePath);
filePath = src.filePath; // update file path, so we can correctly resolve imports
linkedFile = recast.parse(src.content, { esprima: babylon });
return acc;
}
visitAssignmentExpression(path) {
// Ignore anything that is not `exports.X = ...;` or
// `module.exports = ...;`
if (!isExportsOrModuleAssignment(path)) {
return false;
}
// Resolve the value of the right hand side. It should resolve to a call
// expression, something like React.createClass
path = resolveToValue(path.get('right'));
if (!isComponentDefinition(path)) {
path = resolveToValue(resolveHOC(path));
if (!isComponentDefinition(path)) {
return false;
}
}
if (definition) {
// If a file exports multiple components, ... complain!
throw new Error(ERROR_MULTIPLE_DEFINITIONS);
}
definition = resolveDefinition(path, types);
return false;
}
});
return definitions.map(definition => resolveToValue(definition));
}