Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
properties.forEach(property => {
if (t.isObjectProperty(property) && t.isIdentifier(property.key)) {
existingProps[property.key.name] = true;
}
});
// Add to the beginning of the array so existing/custom prop types aren't overwritten
propTypes.forEach(propType => {
if (t.isIdentifier(propType.key) && !existingProps[propType.key.name]) {
properties.unshift(propType);
}
});
// Wrap with forbid
if (wrapForbid && state.options.forbidExtraProps) {
return t.callExpression(t.identifier(state.airbnbPropTypes.forbidImport), [expr]);
}
return expr;
}
function replaceSuperNamedCall(path, node, superClassName, methodName) {
// .call() is better for simple args (or not args) but doesn't work right for spread args
// if it gets further transpiled by babel spread args transform (will be .call.apply(...).
const thisEx = t.thisExpression();
const hasSpread = node.arguments.some(t.isSpreadElement);
const caller = hasSpread ? "apply" : "call";
const callArgs = hasSpread
? [thisEx, t.arrayExpression(node.arguments)]
: [thisEx, ...node.arguments];
path.replaceWith(
t.callExpression(
t.identifier(`${superClassName}.prototype.${methodName}.${caller}`),
callArgs
)
);
}
t.cloneNode(superRef),
t.identifier("call"),
);
}
call = t.logicalExpression("||", bareSuperNode, t.thisExpression());
} else {
bareSuperNode = optimiseCall(
t.callExpression(classState.file.addHelper("getPrototypeOf"), [
t.cloneNode(classState.classRef),
]),
t.thisExpression(),
bareSuperNode.arguments,
);
call = t.callExpression(
classState.file.addHelper("possibleConstructorReturn"),
[t.thisExpression(), bareSuperNode],
);
}
if (
bareSuper.parentPath.isExpressionStatement() &&
bareSuper.parentPath.container === body.node.body &&
body.node.body.length - 1 === bareSuper.parentPath.key
) {
// this super call is the last statement in the body so we can just straight up
// turn it into a return
if (classState.superThises.length) {
call = t.assignmentExpression("=", thisRef(), call);
}
const args = values(outsideRefs).map(id => t.cloneNode(id));
const params = args.map(id => t.cloneNode(id));
const isSwitch = this.blockPath.isSwitchStatement();
// build the closure that we're going to wrap the block with, possible wrapping switch(){}
const fn = t.functionExpression(
null,
params,
t.blockStatement(isSwitch ? [block] : block.body),
);
// continuation
this.addContinuations(fn);
let call = t.callExpression(t.nullLiteral(), args);
let basePath = ".callee";
// handle generators
const hasYield = traverse.hasType(
fn.body,
"YieldExpression",
t.FUNCTION_TYPES,
);
if (hasYield) {
fn.generator = true;
call = t.yieldExpression(call, true);
basePath = ".argument" + basePath;
}
// handlers async functions
const hasAsync = traverse.hasType(
function pushInheritsToBody() {
if (!classState.isDerived || classState.pushedInherits) return;
setState({ pushedInherits: true });
// Unshift to ensure that the constructor inheritance is set up before
// any properties can be assigned to the prototype.
classState.body.unshift(
t.expressionStatement(
t.callExpression(
classState.file.addHelper(
classState.isLoose ? "inheritsLoose" : "inherits",
),
[t.cloneNode(classState.classRef), t.cloneNode(classState.superName)],
),
),
);
}
t.nullLiteral(), // instanceDescriptors
t.nullLiteral(), // staticDescriptors
];
if (instanceProps) args[1] = instanceProps;
if (staticProps) args[2] = staticProps;
let lastNonNullIndex = 0;
for (let i = 0; i < args.length; i++) {
if (!t.isNullLiteral(args[i])) lastNonNullIndex = i;
}
args = args.slice(0, lastNonNullIndex + 1);
body.push(
t.expressionStatement(
t.callExpression(classState.file.addHelper("createClass"), args),
),
);
}
clearDescriptors();
}
YieldExpression({ node }, state) {
if (!node.delegate) return;
const callee = state.addHelper("asyncGeneratorDelegate");
node.argument = t.callExpression(callee, [
t.callExpression(state.addHelper("asyncIterator"), [node.argument]),
state.addHelper("awaitAsyncGenerator"),
]);
},
};
const ensureKey = (expr, helpers, key) => {
if (!key) return expr;
const withKey = helpers.importHelper("withKey");
return t.callExpression(withKey, [key, expr]);
};
build(left, right) {
return t.callExpression(
t.memberExpression(t.identifier("Math"), t.identifier("pow")),
[left, right],
);
},
}),