Finished migrating parser to be object orientation free. All tests pass
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import SymbolNode from '/imports/parser/parseTree/SymbolNode.js';
|
||||
import AccessorNode from '/imports/parser/parseTree/AccessorNode.js';
|
||||
import findAncestorByType from '/imports/api/engine/computation/utility/findAncestorByType.js';
|
||||
import { traverse } from '/imports/parser/resolve.js';
|
||||
|
||||
export default function linkCalculationDependencies(dependencyGraph, prop, {propsById}){
|
||||
prop._computationDetails.calculations.forEach(calcObj => {
|
||||
@@ -9,9 +8,9 @@ export default function linkCalculationDependencies(dependencyGraph, prop, {prop
|
||||
// ancestors: {} //this gets added if there are resolved ancestors
|
||||
};
|
||||
// Traverse the parsed calculation looking for variable names
|
||||
calcObj._parsedCalculation.traverse(node => {
|
||||
traverse(calcObj._parsedCalculation, node => {
|
||||
// Skip nodes that aren't symbols or accessors
|
||||
if (!(node instanceof SymbolNode || node instanceof AccessorNode)) return;
|
||||
if (node.parseType !== 'symbol' && node.parseType !== 'accessor') return;
|
||||
// Link ancestor references as direct property dependencies
|
||||
if (node.name[0] === '#'){
|
||||
let ancestorProp = getAncestorProp(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||
import { prettifyParseError, parse } from '/imports/parser/parser.js';
|
||||
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
||||
import applyFnToKey from '/imports/api/engine/computation/utility/applyFnToKey.js';
|
||||
import { get, unset } from 'lodash';
|
||||
import { get } from 'lodash';
|
||||
import errorNode from '/imports/parser/parseTree/error.js'
|
||||
|
||||
export default function parseCalculationFields(prop, schemas){
|
||||
discoverInlineCalculationFields(prop, schemas);
|
||||
@@ -66,6 +66,6 @@ function parseCalculation(calcObj){
|
||||
calcObj.errors ?
|
||||
calcObj.errors.push(error) :
|
||||
calcObj.errors = [error];
|
||||
calcObj._parsedCalculation = new ErrorNode({error});
|
||||
calcObj._parsedCalculation = errorNode.create({error});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { CompilationContext } from '/imports/parser/parser.js';
|
||||
import resolve, { toString } from '/imports/parser/resolve.js';
|
||||
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
||||
import ErrorNode from '/imports/parser/parseTree/ErrorNode.js';
|
||||
|
||||
export default function computeCalculations(computation, node){
|
||||
if (!node.data) return;
|
||||
@@ -15,17 +13,16 @@ export default function computeCalculations(computation, node){
|
||||
}
|
||||
|
||||
function evaluateCalculation(calculation, scope){
|
||||
const context = new CompilationContext();
|
||||
const parseNode = calculation._parsedCalculation;
|
||||
const fn = calculation._parseLevel;
|
||||
const calculationScope = {...calculation._localScope, ...scope};
|
||||
const resultNode = parseNode[fn](calculationScope, context);
|
||||
if (resultNode instanceof ConstantNode){
|
||||
const {result: resultNode, context} = resolve(fn, parseNode, calculationScope);
|
||||
if (resultNode.parseType === 'constant'){
|
||||
calculation.value = resultNode.value;
|
||||
} else if (resultNode instanceof ErrorNode){
|
||||
} else if (resultNode.parseType === 'error'){
|
||||
calculation.value = null;
|
||||
} else {
|
||||
calculation.value = resultNode.toString();
|
||||
calculation.value = toString(resultNode);
|
||||
}
|
||||
if (calculation.errors){
|
||||
calculation.errors = [...calculation.errors, ...context.errors]
|
||||
|
||||
Reference in New Issue
Block a user