Files
ask262/engine262/src/static-semantics/ExpectedArgumentCount.mts
T

27 lines
679 B
TypeScript

import type { ParseNode } from '../parser/ParseNode.mts';
import { HasInitializer } from './all.mts';
export function ExpectedArgumentCount(FormalParameterList: ParseNode.FormalParameters) {
if (FormalParameterList.length === 0) {
return 0;
}
let count = 0;
for (const FormalParameter of FormalParameterList.slice(0, -1)) {
const BindingElement = FormalParameter;
if (HasInitializer(BindingElement)) {
return count;
}
count += 1;
}
const last = FormalParameterList[FormalParameterList.length - 1];
if (last.type === 'BindingRestElement') {
return count;
}
if (HasInitializer(last)) {
return count;
}
return count + 1;
}