ninetwozero / gradle-to-js

A quick & dirty Gradle build file to JavaScript object parser
Apache License 2.0
47 stars 21 forks source link

Fails on if/else without brackets #10

Closed JPeer264 closed 6 years ago

JPeer264 commented 6 years ago

When I have if statements without any brackets it won't work as expected:

if (condition) properties.put('shouldWork', 'when having an if without brackets')

It needs to renamed with brackets to work:

if (condition) {
    properties.put('shouldWork', 'when having an if without brackets')
}
karllindmark commented 6 years ago

Hey @JPeer264 - thanks for reporting this issue!

I'll attach a proposal for the validation test case below - could you confirm that it matches your expected result? :-)

    it('can skip if clauses without brackets', function() {
      var dsl = multiline.stripIndent(function() {/*
             myVar1 "a"
             if (myBreakfast === "eggs") myVar2 "b"
             myVar2 "c"
             */      });

      var expected = {
        myVar1: 'a',
        myVar2: 'c'
      };
      return parser.parseText(dsl).then(function(parsedValue) {
        expect(parsedValue).to.deep.equal(expected);
      });
});

Furthermore, do we have to account for the following syntax as well?

myVar1 "a"
if (myBreakfast === "eggs")
    myVar2 "b"
myVar2 "c"
JPeer264 commented 6 years ago

could you confirm that it matches your expected result?

Sure that is just as expected

Furthermore, do we have to account for the following syntax as well?

Hm, in my case it is not necessary, but would be neat for having that (don't know how difficult this case would be to implement).

karllindmark commented 6 years ago

I'll hopefully have time to look at this during the weekend, @JPeer264. :-)

JPeer264 commented 6 years ago

Ya no hurry 👍

karllindmark commented 6 years ago

Hey @JPeer264, I finally had time to wrap this one up. Could you give #12 a look when you have some spare time on your hands?

karllindmark commented 6 years ago

gradle-to-js version 1.1.0 should now be available on NPM, and once again - thanks for reporting this issue!