arogozine / LinqToTypeScript

LINQ to TypeScript
https://arogozine.github.io/linqtotypescript/
MIT License
139 stars 18 forks source link

esbuild outerLoop' error #29

Open mellogrand opened 9 months ago

mellogrand commented 9 months ago

moving to angular 17 i get a blocking issue using esbuild (does not happen with webpack) Illegal continue statement: 'outerLoop' does not denote an iteration statement

just wandering if this will affect your great job in the future thanks

arogozine commented 8 months ago

Does this esbuild tool support continue label?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

nikel01 commented 7 months ago

Firstly I want to say thank you for this great package. I have been really glad using it.

I am using Angular 17 and Node 20.11.0

It seems the issue comes from this file, when using esbuild.

import { IAsyncEnumerable, IAsyncEqualityComparer } from "../../types"
import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable"

export const distinctAsync = <TSource>(
    source: AsyncIterable<TSource>,
    comparer: IAsyncEqualityComparer<TSource>): IAsyncEnumerable<TSource> => {

    async function* iterator() {
        const distinctElements: TSource[] = []
        outerLoop:
        for await (const item of source) {
            for (const distinctElement of distinctElements) {
                const found = await comparer(distinctElement, item)
                if (found) {
                    continue outerLoop
                }
            }

            distinctElements.push(item)
            yield item
        }
    }

    return new BasicAsyncEnumerable(iterator)
}

If the label and continue was replaced with a break statement, wouldn't the functionality be retained?

import { IAsyncEnumerable, IAsyncEqualityComparer } from "../../types"
import { BasicAsyncEnumerable } from "../BasicAsyncEnumerable"

export const distinctAsync = <TSource>(
    source: AsyncIterable<TSource>,
    comparer: IAsyncEqualityComparer<TSource>): IAsyncEnumerable<TSource> => {

    async function* iterator() {
        const distinctElements: TSource[] = []
        for await (const item of source) {
            for (const distinctElement of distinctElements) {
                const found = await comparer(distinctElement, item)
                if (found) {
                    break
                }
            }

            distinctElements.push(item)
            yield item
        }
    }

    return new BasicAsyncEnumerable(iterator)
}

I have exactly 0 experience in writing advanced JavaScript and TypeScript as this packages is, so I do not know if this is dead wrong.

And thanks again for this npm package :)

Venom1991 commented 3 months ago

Yeah, this just bit me as well. I'm also using Angular 17. Too bad.

michaelmairegger commented 3 months ago

@nikel01 Your code looks wrong, since you are only breakint the inner for loop, not the outer one. I have created a PR to address this issue

@arogozine The issue is introduced when swapping e.g. @angular-devkit/build-angular:browser, @angular-devkit/build-angular:application

evanw commented 3 months ago

Hello! I'm the author of esbuild. FWIW I noticed this issue and just fixed this bug in esbuild: https://github.com/evanw/esbuild/releases/tag/v0.21.4. So another solution is potentially to update esbuild instead.

michaelmairegger commented 3 months ago

@evanw I will try this and report back. Thanks

michaelmairegger commented 3 months ago

Unfortunately installing esbuild or esbuild-wasm with the 0.21.5 as dev dependency does not solve the problem