Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
}
}
if (specifiers.exports.length) {
const exportNames = [];
const exportValues = [];
let hasExportStar = false;
for (const node of specifiers.exports) {
if (t.isExportAllDeclaration(node)) {
hasExportStar = true;
} else if (t.isExportSpecifier(node)) {
exportNames.push(node.exported.name);
exportValues.push(
t.memberExpression(t.identifier(target), node.local),
);
} else {
// todo
}
}
setterBody = setterBody.concat(
constructExportCall(
path,
t.identifier(exportIdent),
exportNames,
exportValues,
hasExportStar ? t.identifier(target) : null,
),
);
}
if (state.ignoreLabeless) return;
// break statements mean something different in this context
if (t.isBreakStatement(node) && state.inSwitchCase) return;
}
state.hasBreakContinue = true;
state.map[loopText] = node;
replace = t.stringLiteral(loopText);
}
if (path.isReturnStatement()) {
state.hasReturn = true;
replace = t.objectExpression([
t.objectProperty(
t.identifier("v"),
node.argument || scope.buildUndefinedNode(),
),
]);
}
if (replace) {
replace = t.returnStatement(replace);
replace[this.LOOP_IGNORE] = true;
path.skip();
path.replaceWith(t.inherits(replace, node));
}
},
};
// element
} else if (
isReactTypeMatch(name, 'Element', 'JSX') ||
isReactTypeMatch(name, 'ReactElement', reactImportedName) ||
isReactTypeMatch(name, 'ComponentElement', reactImportedName) ||
isReactTypeMatch(name, 'FunctionComponentElement', reactImportedName) ||
isReactTypeMatch(name, 'DOMElement', reactImportedName) ||
isReactTypeMatch(name, 'SFCElement', reactImportedName)
) {
return createMember(t.identifier('element'), propTypesImportedName);
// oneOfType
} else if (isReactTypeMatch(name, 'Ref', reactImportedName)) {
return createCall(
t.identifier('oneOfType'),
[
t.arrayExpression([
createMember(t.identifier('string'), propTypesImportedName),
createMember(t.identifier('func'), propTypesImportedName),
createMember(t.identifier('object'), propTypesImportedName),
]),
],
propTypesImportedName,
);
// function
} else if (name.endsWith('Handler')) {
return createMember(t.identifier('func'), propTypesImportedName);
// object
} else if (name.endsWith('Event')) {
test('should recognize simple identifier', () => {
expect(isClassType('ClassName', t.identifier('ClassName'))).toBe(true);
expect(isClassType('ClassName', t.identifier('ClassN'))).toBe(false);
});
);
if (typeNames.length === 0 || propTypesList.length === 0) {
return;
}
const propTypes = findStaticProperty(rootPath, name, 'propTypes');
if (propTypes) {
propTypes.right = mergePropTypes(propTypes.right, propTypesList, state);
} else {
rootPath.insertAfter(
t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(t.identifier(name), t.identifier('propTypes')),
createPropTypesObject(propTypesList, state),
),
),
);
}
}
t.assignmentExpression(
"=",
descriptor,
t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
t.cloneNode(target),
t.cloneNode(property),
t.arrayExpression(
decorators.map(dec => t.cloneNode(dec.expression)),
),
t.objectExpression([
t.objectProperty(
t.identifier("configurable"),
t.booleanLiteral(true),
),
t.objectProperty(
t.identifier("enumerable"),
t.booleanLiteral(true),
),
t.objectProperty(
t.identifier("writable"),
t.booleanLiteral(true),
),
t.objectProperty(t.identifier("initializer"), initializer),
]),
]),
),
]);
} else {
acc = acc.concat(
t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
t.cloneNode(target),
t.cloneNode(property),
function getPropsIdentifier([attribute]) {
if (attribute) {
throwIf(attribute.name.name != "props", Error.INVALID_PROP_NAME);
throwIf(not(t.isStringLiteral(attribute.value)), Error.INVALID_PROP_VALUE);
let { value: name } = attribute.value;
return t.identifier(name);
}
return t.identifier("props");
}
build(left, right) {
return t.callExpression(
t.memberExpression(t.identifier("Math"), t.identifier("pow")),
[left, right],
);
},
}),
setterBody = setterBody.concat(
constructExportCall(
path,
t.identifier(exportIdent),
exportNames,
exportValues,
hasExportStar ? t.identifier(target) : null,
),
);
}
sources.push(t.stringLiteral(specifiers.key));
setters.push(
t.functionExpression(
null,
[t.identifier(target)],
t.blockStatement(setterBody),
),
);
});