Netjs icon indicating copy to clipboard operation
Netjs copied to clipboard

char literals are not transpiled correctly (using charCodeAt instead of charAt)

Open ZaneDubya opened this issue 9 years ago • 1 comments

C# code:

                char c = line[i];
                if (c == '\"')
                {
                    if (inDoubleQuote)
                    {
                        inDoubleQuote = false;
                        dataFields.Add('\"' + field);
                        field = string.Empty;
                    }
                    else
                    {
                        inDoubleQuote = true;
                    }
                }

Is transpiled to:

                    var c: number = line.charCodeAt(i);
                    if (c === 34/*'"'*/)
                    {
                        if (flag)
                        {
                            flag = false;
                            list.Add(34 + /*'"'*/text);
                            text = NString.Empty;
                        }
                        else
                        {
                            flag = true;
                        }
                    }

Obviously, this breaks string + char addition where the char came from a string (see the 'list.Add' line). Is there a way to prefer using charAt instead of charCodeAt?

ZaneDubya avatar Jun 23 '15 02:06 ZaneDubya

Ouch. I will need to think about this. I did have a reason to prefer charCode, but I don't recall what it was. I'll look into it.

praeclarum avatar Nov 04 '18 02:11 praeclarum