mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-19 00:31:06 +00:00
27 lines
679 B
TypeScript
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;
|
|
}
|