diff --git a/lib/parser.js b/lib/parser.js index 200e575..94e5e11 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -124,7 +124,11 @@ function deepParse(chunk, state, keepFunctionCalls, skipEmptyValues) { currentKey = tempString.trim(); tempString = ''; } - } + } + } else if (currentKey && (tempString.indexOf('(') !== -1 && tempString.indexOf(')') === -1)) { + // NO-OP: Chances are that we're dealing with a closure that's not on a single line + isBeginningOfLine = true; + continue; } if (tempString || (currentKey && !skipEmptyValues)) { diff --git a/package.json b/package.json index 3f98342..ceb2cdd 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "javascript", "parsing" ], - "files" : [ + "files": [ "lib/", "index.js" ], diff --git a/test/parser.js b/test/parser.js index 6355f86..1b3e21d 100644 --- a/test/parser.js +++ b/test/parser.js @@ -522,6 +522,14 @@ describe('Gradle build file parser', function() { expect(parsedValue).to.deep.equal(expected); }); }); + + it('should be able to parse multiline closure syntax', function() { + var sampleFilePath = 'test/sample-data/issue13.build.gradle'; + var expected = require(process.cwd() + '/test/sample-data/issue13.build.gradle.expected.js').expected; + return parser.parseFile(sampleFilePath).then(function(parsedValue) { + expect(parsedValue).to.deep.equal(expected); + }); + }); // TODO: Add test for ... }); describe('(file parsing)', function() { diff --git a/test/sample-data/issue13.build.gradle b/test/sample-data/issue13.build.gradle new file mode 100644 index 0000000..2b6352a --- /dev/null +++ b/test/sample-data/issue13.build.gradle @@ -0,0 +1,25 @@ +def coverageTaskAndroidJob = task("coverageTaskAndroidJob", + dependsOn: ':android-job:createCovAndroidTestCoverageReport') { + + def dep1 = tasks.getByPath(':android-job:clean') + + def target = tasks.getByPath(':android-job:createCovAndroidTestCoverageReport') + + target.dependsOn dep1 + group = "Coverage" + description 'Runs coverage for android-job' +} + +def coverageTaskVolley = task("coverageTaskVolley", + dependsOn: ':volley:createCovCoverageReport') { + + def dep1 = tasks.getByPath(':volley:clean') + def dep2 = tasks.getByPath(':volley:testCovUnitTest') + + def target = tasks.getByPath(':volley:createCovCoverageReport') + + target.dependsOn dep1 + target.dependsOn dep2 + group = "Coverage" + description 'Runs coverage for volley' +} diff --git a/test/sample-data/issue13.build.gradle.expected.js b/test/sample-data/issue13.build.gradle.expected.js new file mode 100644 index 0000000..0f519ed --- /dev/null +++ b/test/sample-data/issue13.build.gradle.expected.js @@ -0,0 +1,20 @@ +exports.expected = { + coverageTaskAndroidJob: { + dep1: "tasks.getByPath(':android-job:clean')", + description: "Runs coverage for android-job", + group: "Coverage", + target: "tasks.getByPath(':android-job:createCovAndroidTestCoverageReport')", + 'target.dependsOn': "dep1" + }, + coverageTaskVolley: { + dep1: "tasks.getByPath(':volley:clean')", + dep2: "tasks.getByPath(':volley:testCovUnitTest')", + description: "Runs coverage for volley", + group: "Coverage", + target: "tasks.getByPath(':volley:createCovCoverageReport')", + 'target.dependsOn': [ + "dep1", + "dep2" + ] + } +}; \ No newline at end of file