Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiline closures-ish #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"javascript",
"parsing"
],
"files" : [
"files": [
"lib/",
"index.js"
],
Expand Down
8 changes: 8 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions test/sample-data/issue13.build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
20 changes: 20 additions & 0 deletions test/sample-data/issue13.build.gradle.expected.js
Original file line number Diff line number Diff line change
@@ -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"
]
}
};