Skip to content

Commit a45158a

Browse files
committed
Moved new function below existing one to make diff easier to read
1 parent 705dc46 commit a45158a

2 files changed

Lines changed: 59 additions & 59 deletions

File tree

examples/browser/cql4browsers.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6813,6 +6813,35 @@ class FunctionRef extends expression_1.Expression {
68136813
this.library = json.libraryName;
68146814
this.functionDefs = null;
68156815
}
6816+
async exec(ctx) {
6817+
const args = await this.execArgs(ctx);
6818+
// Filter out functions w/ wrong number of arguments.
6819+
const fDefs = this.getFunctionDefs(ctx, args);
6820+
// If there is still > 1 matching function, calculate a score based on quality of matches
6821+
if (fDefs.length > 1) {
6822+
// TODO
6823+
}
6824+
if (fDefs.length === 0) {
6825+
throw new Error('no function with matching signature could be found');
6826+
}
6827+
// Moved context creation below the functionDef checks because it's not needed if
6828+
// there are no matching function defs
6829+
let child_ctx;
6830+
if (this.library) {
6831+
const libCtx = ctx.getLibraryContext(this.library);
6832+
child_ctx = libCtx ? libCtx.childContext() : undefined;
6833+
}
6834+
else {
6835+
child_ctx = ctx.childContext();
6836+
}
6837+
// By this point, we should have only one function, but until implementation is completed,
6838+
// use the last one (no matter how many still remain)
6839+
const functionDef = fDefs[fDefs.length - 1];
6840+
for (let i = 0; i < functionDef.parameters.length; i++) {
6841+
child_ctx.set(functionDef.parameters[i].name, args[i]);
6842+
}
6843+
return functionDef.expression.execute(child_ctx);
6844+
}
68166845
getFunctionDefs(ctx, args) {
68176846
if (this.functionDefs != null) {
68186847
// cache hit
@@ -6850,35 +6879,6 @@ class FunctionRef extends expression_1.Expression {
68506879
this.functionDefs = functionDefs;
68516880
return functionDefs;
68526881
}
6853-
async exec(ctx) {
6854-
const args = await this.execArgs(ctx);
6855-
// Filter out functions w/ wrong number of arguments.
6856-
const fDefs = this.getFunctionDefs(ctx, args);
6857-
// If there is still > 1 matching function, calculate a score based on quality of matches
6858-
if (fDefs.length > 1) {
6859-
// TODO
6860-
}
6861-
if (fDefs.length === 0) {
6862-
throw new Error('no function with matching signature could be found');
6863-
}
6864-
// Moved context creation below the functionDef checks because it's not needed if
6865-
// there are no matching function defs
6866-
let child_ctx;
6867-
if (this.library) {
6868-
const libCtx = ctx.getLibraryContext(this.library);
6869-
child_ctx = libCtx ? libCtx.childContext() : undefined;
6870-
}
6871-
else {
6872-
child_ctx = ctx.childContext();
6873-
}
6874-
// By this point, we should have only one function, but until implementation is completed,
6875-
// use the last one (no matter how many still remain)
6876-
const functionDef = fDefs[fDefs.length - 1];
6877-
for (let i = 0; i < functionDef.parameters.length; i++) {
6878-
child_ctx.set(functionDef.parameters[i].name, args[i]);
6879-
}
6880-
return functionDef.expression.execute(child_ctx);
6881-
}
68826882
}
68836883
exports.FunctionRef = FunctionRef;
68846884
class OperandRef extends expression_1.Expression {

src/elm/reusable.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,36 @@ export class FunctionRef extends Expression {
6868
this.functionDefs = null;
6969
}
7070

71+
async exec(ctx: Context) {
72+
const args = await this.execArgs(ctx);
73+
// Filter out functions w/ wrong number of arguments.
74+
const fDefs = this.getFunctionDefs(ctx, args);
75+
// If there is still > 1 matching function, calculate a score based on quality of matches
76+
if (fDefs.length > 1) {
77+
// TODO
78+
}
79+
80+
if (fDefs.length === 0) {
81+
throw new Error('no function with matching signature could be found');
82+
}
83+
// Moved context creation below the functionDef checks because it's not needed if
84+
// there are no matching function defs
85+
let child_ctx;
86+
if (this.library) {
87+
const libCtx = ctx.getLibraryContext(this.library);
88+
child_ctx = libCtx ? libCtx.childContext() : undefined;
89+
} else {
90+
child_ctx = ctx.childContext();
91+
}
92+
// By this point, we should have only one function, but until implementation is completed,
93+
// use the last one (no matter how many still remain)
94+
const functionDef = fDefs[fDefs.length - 1];
95+
for (let i = 0; i < functionDef.parameters.length; i++) {
96+
child_ctx.set(functionDef.parameters[i].name, args[i]);
97+
}
98+
return functionDef.expression.execute(child_ctx);
99+
}
100+
71101
getFunctionDefs(ctx: Context, args: any) {
72102
if (this.functionDefs != null) {
73103
// cache hit
@@ -105,36 +135,6 @@ export class FunctionRef extends Expression {
105135
this.functionDefs = functionDefs;
106136
return functionDefs;
107137
}
108-
109-
async exec(ctx: Context) {
110-
const args = await this.execArgs(ctx);
111-
// Filter out functions w/ wrong number of arguments.
112-
const fDefs = this.getFunctionDefs(ctx, args);
113-
// If there is still > 1 matching function, calculate a score based on quality of matches
114-
if (fDefs.length > 1) {
115-
// TODO
116-
}
117-
118-
if (fDefs.length === 0) {
119-
throw new Error('no function with matching signature could be found');
120-
}
121-
// Moved context creation below the functionDef checks because it's not needed if
122-
// there are no matching function defs
123-
let child_ctx;
124-
if (this.library) {
125-
const libCtx = ctx.getLibraryContext(this.library);
126-
child_ctx = libCtx ? libCtx.childContext() : undefined;
127-
} else {
128-
child_ctx = ctx.childContext();
129-
}
130-
// By this point, we should have only one function, but until implementation is completed,
131-
// use the last one (no matter how many still remain)
132-
const functionDef = fDefs[fDefs.length - 1];
133-
for (let i = 0; i < functionDef.parameters.length; i++) {
134-
child_ctx.set(functionDef.parameters[i].name, args[i]);
135-
}
136-
return functionDef.expression.execute(child_ctx);
137-
}
138138
}
139139

140140
export class OperandRef extends Expression {

0 commit comments

Comments
 (0)