Skip to content

Commit

Permalink
Correct non-empty tuples in all cases where that was intended
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelidlessness committed Jul 25, 2024
1 parent 47b4fbc commit 16719b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/xforms-engine/src/parse/xpath/semantic-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const isCallToLocalNamedFunction = <LocalName extends string>(
return localNameNode?.text === localName;
};

type ArgumentTypes = readonly AnySyntaxType[];
type ArgumentTypes = readonly [AnySyntaxType, ...AnySyntaxType[]];

const hasCallSignature = (syntaxNode: FunctionCallNode, expected: ArgumentTypes[]): boolean => {
const hasCallSignature = (
syntaxNode: FunctionCallNode,
expected: readonly ArgumentTypes[]
): boolean => {
const [, ...argumentNodes] = syntaxNode.children;

if (argumentNodes.length === 0 && expected.length === 0) {
Expand Down
8 changes: 4 additions & 4 deletions packages/xforms-engine/src/parse/xpath/syntax-traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type TypedSyntaxNode<Type extends AnySyntaxType> = Extract<
type CollectedNodes<Type extends AnySyntaxType> = Identity<ReadonlyArray<TypedSyntaxNode<Type>>>;

const isTypedNodeMatch = <const Type extends AnySyntaxType>(
types: readonly [...Type[]],
types: readonly [Type, ...Type[]],
syntaxNode: AnySyntaxNode
): syntaxNode is TypedSyntaxNode<Type> => {
return types.includes(syntaxNode.type as Type);
Expand All @@ -25,7 +25,7 @@ interface CollectNodesOptions {
}

const collectTypedChildren = <const Type extends AnySyntaxType>(
types: readonly [...Type[]],
types: readonly [Type, ...Type[]],
currentNode: AnySyntaxNode,
options: CollectNodesOptions = {}
): CollectedNodes<Type> => {
Expand All @@ -48,7 +48,7 @@ const collectTypedChildren = <const Type extends AnySyntaxType>(
* identifying all LocationPaths referenced by a broader expression.
*/
export const collectTypedNodes = <const Type extends AnySyntaxType>(
types: readonly [...Type[]],
types: readonly [Type, ...Type[]],
currentNode: AnySyntaxNode,
options: CollectNodesOptions = {}
): CollectedNodes<Type> => {
Expand Down Expand Up @@ -112,7 +112,7 @@ export const isCompleteSubExpression = (
* in `foo[position() = 2]`).
*/
export const findTypedPrincipalExpressionNode = <const Type extends AnySyntaxType>(
types: readonly [...Type[]],
types: readonly [Type, ...Type[]],
xpathNode: XPathNode
): TypedSyntaxNode<Type> | null => {
const [first, ...rest] = collectTypedNodes(types, xpathNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('XPath syntax traversal', () => {
interface CollectTypedNodesCase {
readonly expressionDescription: string;
readonly expression: string;
readonly types: readonly AnySyntaxType[];
readonly types: readonly [AnySyntaxType, ...AnySyntaxType[]];
readonly deep?: true;
readonly resultsDescription: string;
readonly expected: readonly ExpectedSyntaxNode[];
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('XPath syntax traversal', () => {
interface FindTypedPrincipalExpressionNodeCase {
readonly expressionDescription: string;
readonly expression: string;
readonly types: readonly AnySyntaxType[];
readonly types: readonly [AnySyntaxType, ...AnySyntaxType[]];
readonly resultDescription: string;
readonly expected: ExpectedSyntaxNode | null;
}
Expand Down

0 comments on commit 16719b4

Please sign in to comment.