Skip to content

Commit

Permalink
DependencyProcessor empty string expr. setData undefined should becom…
Browse files Browse the repository at this point in the history
…e null.
  • Loading branch information
Geoffrey Hendrey committed Feb 19, 2024
1 parent e14e088 commit dc30470
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/DependencyFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export default class DependencyFinder {
*/
constructor(program: string | ExprNode) {
if (typeof program === 'string') {
// Handle the case where program is a string
this.compiledExpression = jsonata(program);
this.ast = this.compiledExpression.ast();
if(program !== "") {
// Handle the case where program is a string
this.compiledExpression = jsonata(program);
this.ast = this.compiledExpression.ast();
}
} else {
this.ast = program;
}
Expand All @@ -74,6 +76,9 @@ export default class DependencyFinder {
Walk the AST of the JSONata program
*/
findDependencies(node:GeneratedExprNode = this.ast):string[][] {
if(!this.ast){
return [];
}
if (this.currentSteps.length === 0) {
this.currentSteps.push([]); //initialize a container for steps
}
Expand Down
2 changes: 1 addition & 1 deletion src/TemplateProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ export default class TemplateProcessor {
}


async setData(jsonPtr, data, op="set") {
async setData(jsonPtr, data=null, op="set") {
this.isEnabled("debug") && this.logger.debug(`setData on ${jsonPtr} for TemplateProcessor uid=${this.uniqueId}`)
//get all the jsonPtrs we need to update, including this one, to percolate the change
const sortedJsonPtrs = [...this.from(jsonPtr)]; //defensive copy
Expand Down
14 changes: 14 additions & 0 deletions src/test/DependencyFinder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,20 @@ test("homeworldURLs.$fetch($).json()", () => {
expect(deps).toEqual([["homeworldURLs"]]);
});

test("function($planet){$planet.residents.($fetch($).json())}", () => {
const program = "function($planet){$planet.residents.($fetch($).json())}";
const df = new DependencyFinder(program);
const deps = df.findDependencies();
expect(deps).toEqual([]);
});

test("empty string", () => {
const program = "";
const df = new DependencyFinder(program);
const deps = df.findDependencies();
expect(deps).toEqual([]);
});




Expand Down

0 comments on commit dc30470

Please sign in to comment.