Fix sig in player 638ec5c6 (#10)

This commit is contained in:
sepro
2025-10-22 20:48:45 +02:00
committed by GitHub
parent bf12d399b2
commit 6a73fa37ba
3 changed files with 57 additions and 7 deletions

View File

@@ -22,6 +22,11 @@ export function matchesStructure<T extends ESTree.Node>(
// Handle `{ or: [a, b] }`
return structure.or.some((node) => matchesStructure(obj, node));
}
if ("anykey" in structure && Array.isArray(structure.anykey)) {
// Handle `{ anykey: [a, b] }`
const haystack = Array.isArray(obj) ? obj : Object.values(obj);
return structure.anykey.every(value => haystack.some((el) => matchesStructure(el, value)));
}
for (const [key, value] of Object.entries(structure)) {
if (!matchesStructure(obj[key as keyof typeof obj], value)) {
return false;

View File

@@ -82,6 +82,20 @@ const identifier = {
type: "FunctionDeclaration",
params: [{}, {}, {}],
},
{
type: "VariableDeclaration",
declarations: {
anykey: [
{
type: "VariableDeclarator",
init: {
type: "FunctionExpression",
params: [{}, {}, {}],
},
},
],
},
},
],
} as const;
@@ -93,14 +107,27 @@ export function extract(
) {
return null;
}
const block =
node.type === "ExpressionStatement" &&
let block: ESTree.BlockStatement | undefined | null;
if (node.type === "ExpressionStatement" &&
node.expression.type === "AssignmentExpression" &&
node.expression.right.type === "FunctionExpression"
? node.expression.right.body
: node.type === "FunctionDeclaration"
? node.body
: null;
node.expression.right.type === "FunctionExpression") {
block = node.expression.right.body;
} else if (node.type === "VariableDeclaration") {
for (const decl of node.declarations) {
if (
decl.type === "VariableDeclarator" &&
decl.init?.type === "FunctionExpression" &&
decl.init?.params.length === 3
) {
block = decl.init.body;
break;
}
}
} else if (node.type === "FunctionDeclaration") {
block = node.body;
} else {
return null;
}
const relevantExpression = block?.body.at(-2);
if (!matchesStructure(relevantExpression!, logicalExpression)) {
return null;

View File

@@ -253,6 +253,24 @@ export const tests: {
},
],
},
{
// TODO: es6/tv_es6 variants currently fail
player: "638ec5c6",
variants: ["main", "tcc", "tce", "es5", "tv", "phone", "tablet"],
n: [
// Synthetic test
{ input: "ZdZIqFPQK-Ty8wId", expected: "1qov8-KM-yH" },
],
sig: [
// Synthetic test
{
input:
"gN7a-hudCuAuPH6fByOk1_GNXN0yNMHShjZXS2VOgsEItAJz0tipeavEOmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
expected:
"MhudCuAuP-6fByOk1_GNXN7gNHHShjyXS2VOgsEItAJz0tipeav0OmNdYN-wUtcEqD3bCXjc0iyKfAyZxCBGgIARwsSdQfJ2CJtt",
},
],
},
];
export const players = new Map([