Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"?" instead of type parameter value for Linq functions #97

Open
YImhof opened this issue Jul 2, 2024 · 0 comments
Open

"?" instead of type parameter value for Linq functions #97

YImhof opened this issue Jul 2, 2024 · 0 comments

Comments

@YImhof
Copy link

YImhof commented Jul 2, 2024

Using the option outputFormatting in H5 configuration file, transpilled JS code can be directly minified.
This worked great with Bridge.Net and also with H5, but now I have a project whose H5 compilation raises the following exception:
[fail] [10:20:27] Error minifiying code. Saved output to [/path/to/tmp/file]
System.NullReferenceException: Object reference not set to an instance of an object.

H5 is actually using NUglify 1.20.7 for this operation. So using a minimal project, I tried to find the line(s) causing the NUglify exception(s), feeding it with H5's temp output.

What I found is that for an unknown reason, when I am using System.Linq functions, H5 define the type variable with a type named "?" instead of the real type name, like "Element" for example. When I manually change the "?" for the correct type name, then NUglify correctly proceeds the code ... until the next misnamed type parameter.

This problem does not occur in a systematic way, as for example in my minimal project, which is a copy-paste of several classes of the original project, type parameters are correctly transpilled. I have to admit that this project's H5 formatted result (so its beautified javascript output) is about 3.7 [Mb] (~ 32'000 lines length), which is why I'm using the minified option. I tried for example to use intermediate IEnumerable<Element> variables in C# code, but H5 keeps using "?" as type parameter value

Is there any size limit for H5 compiler? Am I doing something wrong? Any other idea?

Example illustrating transpilation error

Original C# code example (rootContainer is a H5.Core.dom.HTMLDivElement and is inherited) :

namespace ANamespace
{
    public class AClassName : AParentClassName
    {
        public int Index
        {
            get
            {
                if (rootContainer.parentNode != null)
                    return rootContainer.parentElement.children.ToList().IndexOf(rootContainer);
                else
                    return -1;
            }
        }
    }
}

Javascript transpilation result of the H5 compiler (from temp saved output):
Notice the return ($t = ?, in the beginning of the line 8.

H5.define("ANamespace.AClassName", {
    inherits: [AParentClassName],
    props: {
        Index: {
            get: function () {
                var $t;
                /*##|24,186,17|##*/if (/*##|24,186,21|##*/this.rootContainer.parentNode != /*##|24,186,49|##*/null) {
                    /*##|24,187,21|##*/return /*##|24,187,28|##*/($t = /*##|24,187,58|##*/?, System.Linq.Enumerable.from(/*##|24,187,79|##*/this.rootContainer.parentElement.children, $t).toList($t)).indexOf(/*##|24,187,125|##*/this.rootContainer);
                } else {
                    /*##|24,189,21|##*/return /*##|24,189,28|##*/-1;
                }
            }
        }
    }
});
@YImhof YImhof changed the title "?" instead of parameter type value for Linq functions "?" instead of type parameter value for Linq functions Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant