Skip to content
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: 1 addition & 5 deletions src/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ export class ExpressionExecutor implements IExpresionExecutor {
: false;
}
public getVariables(): Array<string> {
if (!this.operand) return [];

var variables: Array<string> = [];
this.operand.setVariables(variables);
return variables;
return this.operand?.getVariables() ?? [];
}

public hasFunction(): boolean {
Expand Down
34 changes: 22 additions & 12 deletions src/expressions/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class Operand {
}
public abstract getType(): string;
public abstract evaluate(processValue?: ProcessValue): any;
public abstract setVariables(variables: Array<string>): any;
public abstract getVariables(): Array<string>;
public hasFunction(): boolean {
return false;
}
Expand Down Expand Up @@ -110,9 +110,11 @@ export class BinaryOperand extends Operand {
);
}

public setVariables(variables: Array<string>) {
if (this.left != null) this.left.setVariables(variables);
if (this.right != null) this.right.setVariables(variables);
public getVariables(): string[] {
return [
...this.left?.getVariables() ?? [],
...this.right?.getVariables() ?? []
];
}

public hasFunction(): boolean {
Expand Down Expand Up @@ -179,8 +181,9 @@ export class UnaryOperand extends Operand {
let value = this.expression.evaluate(processValue);
return this.consumer.call(this, value);
}
public setVariables(variables: Array<string>) {
this.expression.setVariables(variables);

public getVariables(): Array<string> {
return this.expression.getVariables();
}
}

Expand Down Expand Up @@ -213,10 +216,8 @@ export class ArrayOperand extends Operand {
});
}

public setVariables(variables: Array<string>) {
this.values.forEach((el) => {
el.setVariables(variables);
});
public getVariables(): string[] {
return this.values.flatMap(v => v.getVariables());
}

public hasFunction(): boolean {
Expand Down Expand Up @@ -260,6 +261,10 @@ export class Const extends Operand {
return this.getCorrectValue(this.value);
}

public getVariables(): string[] {
return [];
}

public setVariables(variables: Array<string>) {}
protected getCorrectValue(value: any): any {
if (!value || typeof value != "string") return value;
Expand Down Expand Up @@ -332,6 +337,10 @@ export class Variable extends Const {
? this.getCorrectValue(this.valueInfo.value)
: null;
}

public getVariables(): string[] {
return [this.variableName];
}
public setVariables(variables: Array<string>) {
variables.push(this.variableName);
}
Expand Down Expand Up @@ -392,9 +401,10 @@ export class FunctionOperand extends Operand {
return this.originalValue + "(" + this.parameters.toString(func) + ")";
}

public setVariables(variables: Array<string>) {
this.parameters.setVariables(variables);
public getVariables(): string[] {
return this.parameters.getVariables();
}

public get isReady() {
return this.isReadyValue;
}
Expand Down