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

Fix userInvocationTable for toString #157

Open
wants to merge 2 commits into
base: master
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
3 changes: 2 additions & 1 deletion src/fhirpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ function makeParam(ctx, parentData, type, param) {
}

function doInvoke(ctx, fnName, data, rawParams){
var invoc = ctx.userInvocationTable?.[fnName] ?? engine.invocationTable[fnName];
var invoc = Object.prototype.hasOwnProperty.call(ctx.userInvocationTable, fnName) ?
ctx.userInvocationTable[fnName] : engine.invocationTable[fnName];
var res;
if(invoc) {
if(!invoc.arity){
Expand Down
17 changes: 17 additions & 0 deletions test/user-invocation-table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ describe('concept', () => {
expr = "next.concept().select($this | $this.next.concept()).display";
retrieved = fhirpath.evaluate(concepts.a, expr, null, null, options);
expect(retrieved).toEqual(["B", "C"]);
});
});

describe("toString", () => {
it("Works when userInvocationTable passed without overriding toString", () => {
const options = {
userInvocationTable: {},
};

let result = fhirpath.evaluate(
{ index: 0 },
"index.toString()",
null,
null,
options
);

expect(result).toEqual(["0"]);
});
});