infernojs / babel-plugin-inferno

Transforms JSX to InfernoJS vNodes
MIT License
79 stars 26 forks source link

HandleWhiteSpace function fails when there are no tabs #2

Closed Havunen closed 8 years ago

Havunen commented 8 years ago

Hi,

In our project we use space as indentation which leads to an issue that HandleWhiteSpace function never removes the whitespace.

Steps to reproduce:

var stringWithWhitespaces = '\n             ';

function handleWhiteSpace(str) {
    str = str.replace(/\t/g, '');
    if(str.indexOf("\n") !== -1) {
        var remove = str.substring(0, str.indexOf("\n")).trim();
        if(remove === '') {
            str = str.substring(str.indexOf("\n") + 1);
        }
        str = handleWhiteSpace(str);
    }
    return str;
}

// call the function
handleWhiteSpace(stringWithWhitespaces)  // Expected result '', instead got '             ';

Sidenote: Should this function also handle Windows ('\r\n') and Mac ('\r') style of line endings?

Havunen

trueadm commented 8 years ago

Well spotted, I'll try and address it today once I get some time.

trueadm commented 8 years ago

Can you let me know if this issues still occurs?

Havunen commented 8 years ago

issue still exists

some example output from the plugin:

        children: ['                                ', {
            tag: 'img',
            attrs: {
                height: '58',
                src: 'img/visma_logo.svg',
                alt: 'visma'
            }
        }, '                                ', {

and

    return {
        tag: 'div',
        attrs: {
            class: 'login-view bg-visma'
        },
        children: ['                ', v0, '            ']
    };

this quick hack fixed it before:

    var testForEmpty = str.trim();
    if (testForEmpty.length === 0) {
        str = testForEmpty;
    }
Havunen commented 8 years ago

This issue has been fixed, closing ticket.