Fixed computation bug for compile level calcs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { CompilationContext } from '/imports/parser/parser.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;
|
||||
@@ -21,8 +22,10 @@ function evaluateCalculation(calculation, scope){
|
||||
const resultNode = parseNode[fn](calculationScope, context);
|
||||
if (resultNode instanceof ConstantNode){
|
||||
calculation.value = resultNode.value;
|
||||
} else if (resultNode instanceof ErrorNode){
|
||||
calculation.value = null;
|
||||
} else {
|
||||
calculation.value = NaN;
|
||||
calculation.value = resultNode.toString();
|
||||
}
|
||||
if (calculation.errors){
|
||||
calculation.errors = [...calculation.errors, ...context.errors]
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function(){
|
||||
assert.equal(prop.usesLeft, 2);
|
||||
|
||||
const rolled = computation.propsById['rolledDescriptionId'];
|
||||
assert.equal(rolled.summary.value, 'test roll gets compiled {1d4 + 4} properly');
|
||||
assert.equal(rolled.summary.value, 'test roll gets compiled 1d4 + 4 properly');
|
||||
|
||||
const itemConsumed = prop.resources.itemsConsumed[0];
|
||||
assert.equal(itemConsumed.quantity.value, 3);
|
||||
|
||||
@@ -17,6 +17,10 @@ export default function(){
|
||||
prop('parseErrorId').baseValue.errors.length, 1,
|
||||
'Parse errors should be added to calculation errors'
|
||||
);
|
||||
assert.equal(
|
||||
prop('parseErrorId').baseValue.value, null,
|
||||
'Parse errors should null the value'
|
||||
);
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
|
||||
Reference in New Issue
Block a user