B4J Question [BANano] [SOLVED] Set Minify Option On/Off

Mashiane

Expert
Licensed User
Hi

Just updated to 2.15, nothing seems to work on my code, same code works with 2.09. When i debug there is an expectation of ). I don't even know the cause now as the code compiles without any errors. At first 2.15 didnt work with these strings so I simplied the code and it compiles well, but it doesnt work. Reverting back to 2.09 works well on my demo app.

B4X:
If attribute.StartsWith("data-") Then
If sColor.EndsWith("-text") = False Then
if xColor.Contains("xxx") then
I have compiled both files in debug mode, one compiled with BANano 2.09 and the other with BANano 2.15 and compared them, everything seems to be ok and nothing glaring though.

differences.png


Update:

Please check the sleep const, it has two ; at the end and not after milliseconds))

B4X:
const sleep = (milliseconds) => {
    return new Promise(resolve => setTimeout(resolve, milliseconds))
};;
PS: Thanks a lot for the new update, now I can explore crud for BANanoSQL using the new callback function.
 
Last edited:

alwaysbusy

Expert
Licensed User
Again, impossible to help without a small project demonstrating the problem. The String parser had to be rewritten in 2.15 because of troubles with setters/getters. Quite possible something is broken if you use a programming style that I'm not used to and that my or Kiffis test projects are missing.
 

Mashiane

Expert
Licensed User
@alwaysbusy

javascript can be a pain in the you know where. Lol. I was taking a nap as I disturbed my sleeping patterns, I'm like an owl now! ha ha ha. I have attached a small problem and also found the cause. Here is my screen dump. The transpiler did a perfect job actually, the problem is a trailing ; in the banano generated script which is not part of the transpiled code. I think its the code that comes with banano.

Reproduction and solution

1. Run the attached project with banano 2.15.

transpiler.png


Solution

2. Beautify the generated app.js js code and in about line 345, fix this code.. (The BANano internal code comes minified even in debug mode and it seems thats where the error is, but I could be wrong)

From

B4X:
const sleep = (milliseconds) => {
    return new Promise(resolve => setTimeout(resolve, milliseconds))
};;
To

B4X:
const sleep = (milliseconds) => {
    return new Promise(resolve => setTimeout(resolve, milliseconds));
};
The demo app works perfectly after that removal of the trailing ; and the 'SOLUTION' in my code scripts is un-necessary.

Ta!
 

Attachments

alwaysbusy

Expert
Licensed User
Your 'SOLUTION' lines are definitely needed in 2.15 because it translates:

B4X:
If sValue.EndsWith(Delim) Then
to
B4X:
if (_svalue) {
and it should be:
B4X:
if (_svalue.endsWith(_delim)) {
So you don't get an error in the browser (it is valid javascript), but the code is completely not doing what you intended. This has to do with the new String parser system. Will be fixed in the next update.

The errors in the log are very important and are the key to the solution.

Sleep has nothing to do with these errors. The ; will be fixed in the next release but is unrelated.
 

Mashiane

Expert
Licensed User
I should have qualified my
I was taking a nap as I disturbed my sleeping patterns, I'm like an owl now! ha ha ha.
with - 'due to the late response...'

Anyway cool. Glad that the issue will be resolved. Keep up the good work!
 

Mashiane

Expert
Licensed User
Please just bear me a little more, please also take a look at these two methods, the first does not include the return 'value' on the output and the other one looses the left side assignment for sbx. Line 263 and line 186. These are related to the StringBuilder

B4X:
'remove delim from stringbuilder
Sub RemDelimSB(delimiter As String, value As StringBuilder) As StringBuilder
    If value.tostring.EndsWith(delimiter) = True Then
        Dim delimLen As Int = delimiter.length
        value.Remove(value.Length-delimLen,value.Length)
    End If
    Return value
End Sub
and the generated code's return statement is incomplete for line 263 below

B4X:
 // [258] Sub RemDelimSB(delimiter As String, value As StringBuilder) As StringBuilder
                                this.remdelimsb = function (_delimiter, _value) {
                                    if (self == null) self = this;
                                    var _delimlen;
                                    // [259]  If value.tostring.EndsWith(delimiter) = True Then
                                    if (_value.toString().endsWith(_delimiter) == true) {
                                        // [260]  Dim delimLen As Int = delimiter.length
                                        _delimlen = _delimiter.length;
                                        // [261]  value.Remove(value.Length-delimLen,value.Length)
                                        _value.remove(_value.length() - _delimlen, _value.length());
                                        // [262]  End If
                                    }
                                    // [263]  Return value
                                    return;
                                    // End Sub
                                };
The other method is...

B4X:
'build the types of charts to drae
private Sub BuildTypes() As String
    Dim sbx As StringBuilder
    sbx.Initialize
    sbx.Append("types: {")
    sbx.Append(CRLF)
    Dim sTot As Int = series.Size - 1
    Dim sCnt As Int
    For sCnt = 0 To sTot
        Dim seriesm As Map = series.GetValueAt(sCnt)
        Dim sname As String = seriesm.Get("column")
        Dim stype As String = seriesm.Get("type")
        stype = stype.Replace("horizontalbar","bar")
        stype = stype.Replace("stackedbar","bar")
        stype = stype.Replace("grouped-bar","bar")
        If stype.Length > 0 Then
            sbx.Append($"${sname}:"${stype}","$)
        End If
    Next
    sbx = App.RemDelimSB(",",sbx)
    sbx.Append("},")
    Return sbx.tostring
End Sub
The output on line 186 has left out the left side of the assignment

B4X:
// [168] private Sub BuildTypes() As String
    this.buildtypes = function () {
        if (self == null) self = this;
        var _sbx;
        var _stot;
        var _scnt;
        var _seriesm;
        var _sname;
        var _stype;
        // [169]  Dim sbx As StringBuilder
        _sbx = new StringBuilder();
        // [170]  sbx.Initialize
        // BANano: Not Transpiled;
        // [171]  sbx.Append( {35} )
        _sbx.append("types: {");
        // [172]  sbx.Append(CRLF)
        _sbx.append("\n");
        // [173]  Dim sTot As Int = series.Size - 1
        _stot = Object.keys(self._series).length - 1;
        // [174]  Dim sCnt As Int
        _scnt = 0;
        // [175]  For sCnt = 0 To sTot
        for (_scnt = 0; _scnt <= _stot; _scnt++) {
            // [176]  Dim seriesm As Map = series.GetValueAt(sCnt)
            _seriesm = banano_getB4JValueAt(self._series, _scnt);
            // [177]  Dim sname As String = seriesm.Get( {36} )
            _sname = _seriesm["column"];
            // [178]  Dim stype As String = seriesm.Get( {37} )
            _stype = _seriesm["type"];
            // [179]  stype = stype.Replace( {38} , {39} )
            _stype = _stype.split("horizontalbar").join("bar");
            // [180]  stype = stype.Replace( {40} , {41} )
            _stype = _stype.split("stackedbar").join("bar");
            // [181]  stype = stype.Replace( {42} , {43} )
            _stype = _stype.split("grouped-bar").join("bar");
            // [182]  If stype.Length > 0 Then
            if (_stype.length > 0) {
                // [183]  sbx.Append( {3} )
                _sbx.append("" + _sname + ":\"" + _stype + "\",");
                // [184]  End If
            }
            // [185]  Next
        }
        // [186]  sbx = App.RemDelimSB( {44} ,sbx)
        = self._app.remdelimsb(",", );
        // [187]  sbx.Append( {45} )
        _sbx.append("},");
        // [188]  Return sbx.tostring
        return _sbx.toString();
        // End Sub
    };

I will try and move the code up so that I dont have to remove the delimiters at the end however so that my counters start at 1, but so far, I think this is just the other last issue
 
Top