Skip to content

Commit

Permalink
Remove undefined return type from joinTracedToNode (#1711)
Browse files Browse the repository at this point in the history
Since it calls the function returned by `traceToNode`, which
always returns `CompositeGeneratorNode`, it can never return `undefined`
  • Loading branch information
aabounegm authored Oct 14, 2024
1 parent d0522c1 commit b52cb60
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/langium/src/generate/node-joiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function joinToNode<T>(
* arguments as expected by {@link joinToNode}, i.e. an `iterable`, a function `toGenerated`
* converting each element into a `Generated`, as well as some `options`.
*
* That function than joins the elements of `iterable` by delegating to {@link joinToNode}.
* That function then joins the elements of `iterable` by delegating to {@link joinToNode}.
* Via {@link traceToNode} the resulting generator node is supplemented with the provided tracing
* information in form of `{astNode, property?, index?}`, and finally returned. In addition,
* if `property` is given each element's generator node representation is augmented with the
Expand All @@ -153,7 +153,7 @@ export function joinToNode<T>(
* `.appendNewLine()
*/
export function joinTracedToNode<T extends AstNode>(astNode: T, property?: Properties<T>): // eslint-disable-next-line @typescript-eslint/indent
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode | undefined;
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode;

/**
* Convenience function for joining the elements of some `iterable` and gathering tracing information
Expand All @@ -163,7 +163,7 @@ export function joinTracedToNode<T extends AstNode>(astNode: T, property?: Prope
* arguments as expected by {@link joinToNode}, i.e. an `iterable`, a function `toGenerated`
* converting each element into a `Generated`, as well as some `options`.
*
* That function than joins the elements of `iterable` by delegating to {@link joinToNode}.
* That function then joins the elements of `iterable` by delegating to {@link joinToNode}.
* Via {@link traceToNode} the resulting generator node is supplemented with the provided tracing
* information, and finally returned. Elementwise tracing need to be implemented by client code
* within `toGenerated`, if required.
Expand All @@ -179,7 +179,7 @@ export function joinTracedToNode<T extends AstNode>(astNode: T, property?: Prope
* `.appendNewLine()
*/
export function joinTracedToNode(sourceRegion: SourceRegion | undefined): // eslint-disable-next-line @typescript-eslint/indent
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode | undefined;
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode;

/**
* Convenience function for joining the elements of some `iterable` and gathering tracing information
Expand All @@ -189,7 +189,7 @@ export function joinTracedToNode(sourceRegion: SourceRegion | undefined): // esl
* arguments as expected by {@link joinToNode}, i.e. an `iterable`, a function `toGenerated`
* converting each element into a `Generated`, as well as some `options`.
*
* That function than joins the elements of `iterable` by delegating to {@link joinToNode}.
* That function then joins the elements of `iterable` by delegating to {@link joinToNode}.
* Via {@link traceToNode} the resulting generator node is supplemented with the provided tracing
* information, and finally returned. Elementwise tracing need to be implemented by client code
* within `toGenerated`, if required.
Expand All @@ -208,11 +208,11 @@ export function joinTracedToNode(sourceRegion: SourceRegion | undefined): // esl
* `.appendNewLine()
*/
export function joinTracedToNode(sourceRegions: SourceRegion[]): // eslint-disable-next-line @typescript-eslint/indent
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode | undefined;
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode;

// implementation:
export function joinTracedToNode<T extends AstNode>(source: T | undefined | SourceRegion | SourceRegion[], property?: Properties<T>): // eslint-disable-next-line @typescript-eslint/indent
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode | undefined {
<E>(iterable: Iterable<E> | E[], toGenerated?: ((element: E, index: number, isLast: boolean) => Generated) | JoinOptions<E>, options?: JoinOptions<E>) => CompositeGeneratorNode {
return (iterable, toGeneratedOrOptions, options) => {
options ??= typeof toGeneratedOrOptions === 'object' ? toGeneratedOrOptions : undefined;
const toGenerated = typeof toGeneratedOrOptions === 'function' ? toGeneratedOrOptions : defaultToGenerated;
Expand All @@ -234,7 +234,7 @@ export function joinTracedToNode<T extends AstNode>(source: T | undefined | Sour
* and that expects same list of arguments as expected by {@link joinToNode}, i.e. an `iterable`,
* a function `toGenerated` converting each element into a `Generated`, as well as some `options`.
*
* That function than joins the elements of `iterable` by delegating to {@link joinToNode}.
* That function then joins the elements of `iterable` by delegating to {@link joinToNode}.
* Via {@link traceToNode} the resulting generator node is supplemented with the provided tracing
* information, and finally returned. In addition, if `property` is given each element's
* generator node representation is augmented with the provided tracing information
Expand Down Expand Up @@ -267,7 +267,7 @@ export function joinTracedToNodeIf<T extends AstNode>(condition: boolean, astNod
* and that expects same list of arguments as expected by {@link joinToNode}, i.e. an `iterable`,
* a function `toGenerated` converting each element into a `Generated`, as well as some `options`.
*
* That function than joins the elements of `iterable` by delegating to {@link joinToNode}.
* That function then joins the elements of `iterable` by delegating to {@link joinToNode}.
* Via {@link traceToNode} the resulting generator node is supplemented with the provided tracing
* information, and finally returned. Element-wise tracing need to be implemented by client code
* within `toGenerated`, if required.
Expand Down Expand Up @@ -299,7 +299,7 @@ export function joinTracedToNodeIf(condition: boolean, sourceRegion: SourceRegio
* and that expects same list of arguments as expected by {@link joinToNode}, i.e. an `iterable`,
* a function `toGenerated` converting each element into a `Generated`, as well as some `options`.
*
* That function than joins the elements of `iterable` by delegating to {@link joinToNode}.
* That function then joins the elements of `iterable` by delegating to {@link joinToNode}.
* Via {@link traceToNode} the resulting generator node is supplemented with the provided tracing
* information, and finally returned. Element-wise tracing need to be implemented by client code
* within `toGenerated`, if required.
Expand Down

0 comments on commit b52cb60

Please sign in to comment.