From 8d464a493804bfff3f2648ef466e3c87917870b1 Mon Sep 17 00:00:00 2001 From: Alexander Sennikov Date: Tue, 12 Apr 2022 14:49:53 +0400 Subject: [PATCH] Fix error position property set for errors in functions --- src/jsonata.js | 6 +++--- test/implementation-tests.js | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/jsonata.js b/src/jsonata.js index 19b09409..a46ac6dc 100644 --- a/src/jsonata.js +++ b/src/jsonata.js @@ -1412,7 +1412,7 @@ var jsonata = (function() { throw { code: "T1005", stack: (new Error()).stack, - position: expr.position, + position: expr.position - 1, token: expr.procedure.steps[0].value }; } @@ -1447,7 +1447,7 @@ var jsonata = (function() { } catch (err) { if(!err.position) { // add the position field to the error - err.position = expr.position; + err.position = expr.position - 1; } if (!err.token) { // and the function identifier @@ -1539,7 +1539,7 @@ var jsonata = (function() { if (typeof err.token == 'undefined' && typeof proc.token !== 'undefined') { err.token = proc.token; } - err.position = proc.position; + err.position = proc.position - 1; } throw err; } diff --git a/test/implementation-tests.js b/test/implementation-tests.js index 9c58a0dc..f539643a 100644 --- a/test/implementation-tests.js +++ b/test/implementation-tests.js @@ -347,7 +347,7 @@ describe("Tests that bind Javascript functions", () => { expr.evaluate({}); }) .to.throw(DOMException) - .to.deep.contain({ message: 'Here is my message', position: 12, token: 'throwDomEx' }); + .to.deep.contain({ message: 'Here is my message', position: 11, token: 'throwDomEx' }); }); }); @@ -557,7 +557,7 @@ describe("Tests that bind Javascript functions", () => { var result = expr.evaluate(); var expected = [true, false]; expect(result).to.deep.equal(expected); - }) + }); }); }); @@ -736,7 +736,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "D3040", token: "match", index: 3, value: -3 }); + .to.deep.contain({ position: 6, code: "D3040", token: "match", index: 3, value: -3 }); }); }); @@ -747,7 +747,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "T0410", token: "match", index: 3, value: null }); + .to.deep.contain({ position: 6, code: "T0410", token: "match", index: 3, value: null }); }); }); @@ -758,7 +758,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "T0410", token: "match", index: 3, value: "2" }); + .to.deep.contain({ position: 6, code: "T0410", token: "match", index: 3, value: "2" }); }); }); @@ -769,7 +769,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "T0410", token: "match", index: 2, value: "ab" }); + .to.deep.contain({ position: 6, code: "T0410", token: "match", index: 2, value: "ab" }); }); }); @@ -780,7 +780,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "T0410", token: "match", index: 2, value: true }); + .to.deep.contain({ position: 6, code: "T0410", token: "match", index: 2, value: true }); }); }); @@ -791,7 +791,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "T0410", token: "match", index: 1, value: 12345 }); + .to.deep.contain({ position: 6, code: "T0410", token: "match", index: 1, value: 12345 }); }); }); @@ -802,7 +802,7 @@ describe("Tests that are specific to a Javascript runtime", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ position: 7, code: "T0410", token: "match", index: 1 }); + .to.deep.contain({ position: 6, code: "T0410", token: "match", index: 1 }); }); }); }); @@ -829,7 +829,7 @@ describe("Tests that include infinite recursion", () => { expr.evaluate(); }) .to.throw() - .to.deep.contain({ token: "inf", position: 32, code: "U1001" }); + .to.deep.contain({ token: "inf", position: 31, code: "U1001" }); }); });