unassert-js / unassert

Encourages programming with assertions by providing tools to compile them away.
MIT License
192 stars 13 forks source link

Add empty block if parent is non-block statement #8

Closed twada closed 8 years ago

twada commented 8 years ago

Dealing with IfStatement without curly braces.

refs twada/unassert#7

'use strict';

var assert = require('assert');

function add (a, b) {
    if (!isNaN(a)) assert(0 < a);
    if (typeof b === 'number') {
        assert(0 < b);
    }

    if (typeof a === 'number')
        assert(0 < a);
    else if (typeof b === 'number')
        assert(0 < b);
    else
        assert(false);

    return a + b;
}

becomes

'use strict';
function add(a, b) {
    if (!isNaN(a)) {
    }
    if (typeof b === 'number') {
    }
    if (typeof a === 'number') {
    } else if (typeof b === 'number') {
    } else {
    }
    return a + b;
}