Skip to content

Commit

Permalink
throw when calling distance() with 0 arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
brontolosone committed Oct 25, 2024
1 parent 0e7672f commit 70ba459
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class InvalidArgumentError extends Error {
}
}

export type ParameterArityType = 'optional' | 'required' | 'variadic';
export type ParameterArityType = 'optional' | 'required' | 'variadic' | 'variadic+' ;

export type ParameterTypeHint =
// | 'lazy' // TODO: it might be good to *explicitly* mark certain parameters
Expand Down Expand Up @@ -127,6 +127,12 @@ export class FunctionImplementation<Length extends number> {
max: Infinity,
};

case 'variadic+':
return {
min: acc.min + 1,
max: Infinity,
};

default:
throw new UnreachableError(arityType);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/xpath/src/functions/xforms/geo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const sum = (values: readonly number[]) => {

export const distance = new NumberFunction(
'distance',
[{ arityType: 'variadic' }],
[{ arityType: 'variadic+' }],
(context, args) => {
const lines = evaluateLines(context, args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('distance() and area() functions', () => {
});
});

describe('area with nodes', () => {
describe('area and distance with nodes', () => {
beforeEach(() => {
testContext = createXFormsTestContext(`
<root>
Expand Down

0 comments on commit 70ba459

Please sign in to comment.