Include Utils.Component() in BailOnCapitalizedFunctionCalls

`Utils.Component()` wasn't caught by the bailout, and there are such usage on 
WWW 

Fixes #671
This commit is contained in:
Tianyu Yao
2022-10-17 14:41:26 -07:00
parent 46d7f4f8af
commit 4712017744
@@ -53,17 +53,18 @@ export function run(
const funcBody = func.get("body");
if (context.opts.flags.bailOnCapitalizedFunctionCalls) {
function isValidFunctionCallName(name: string): boolean {
return (
ALLOWED_CAPITALIZED_STDLIB_FUNCTIONS.has(name) ||
context.opts.allowedCapitalizedUserFunctions.has(name) ||
!/^[A-Z]/.test(name)
);
}
funcBody.traverse({
CallExpression(path) {
const callee = path.get("callee");
if (t.isIdentifier(callee.node)) {
const name = callee.node.name;
if (
ALLOWED_CAPITALIZED_STDLIB_FUNCTIONS.has(name) ||
context.opts.allowedCapitalizedUserFunctions.has(name)
) {
return;
}
// Allow `Module().method()`;
if (
t.isMemberExpression(path.parent) ||
@@ -71,13 +72,28 @@ export function run(
) {
return;
}
if (/^[A-Z]/.test(name)) {
const name = callee.node.name;
if (!isValidFunctionCallName(name)) {
context.bailout("BailOnCapitalizedFunctionCalls", {
code: "E0018",
path: callee,
context: null,
});
}
} else if (
t.isMemberExpression(callee.node) ||
t.isOptionalMemberExpression(callee.node)
) {
const { object, property } = callee.node;
if (t.isIdentifier(object) && t.isIdentifier(property)) {
if (!isValidFunctionCallName(`${object.name}.${property.name}`)) {
context.bailout("BailOnCapitalizedFunctionCalls", {
code: "E0018",
path: callee,
context: null,
});
}
}
}
},
});