Skip to content

Releases: kgrz/babel-plugin-console-groupify

Skip generating grouping if log comes after return

08 Aug 17:25
Compare
Choose a tag to compare

Before this change, code like the following would output a nested group
titles with empty log statement (since it won't actually get hit).

    function something() {
        if (somecondition) return null;
        console.log('wut');
    }

    for (var i = 0; i < 10; ++i) {
        something();
    }

Compiled output:

    function something() {
                console.group('something');
                return null;
                console.log('wut');
                console.groupEnd();
    }

    for (var i = 0; i < 10; ++i) {
                something();
    }

When executed:

    something
      something
        something
          something
                something
                  something
                        something
                          something
                                something
                                  something

This fix adds an extra check for this state.