tested and fixed constant node computations

This commit is contained in:
Stefan Zermatten
2021-09-23 12:03:25 +02:00
parent 347bd8e476
commit e63dd2560a
3 changed files with 42 additions and 6 deletions

View File

@@ -9,18 +9,22 @@ export default class SymbolNode extends ParseNode {
toString(){
return `${this.name}`
}
compile(scope, context){
compile(scope, context, calledFromReduce = false){
let value = scope && scope[this.name];
let type = typeof value;
// For parse nodes, compile and return
if (value instanceof ParseNode){
return value.compile(scope, context);
}
// For objects, default to their .value
if (type === 'object'){
value = value.value;
type = typeof value;
}
// For parse nodes, compile and return
if (value instanceof ParseNode){
if (calledFromReduce){
return value.reduce(scope, context);
} else {
return value.compile(scope, context);
}
}
if (type === 'string' || type === 'number' || type === 'boolean'){
return new ConstantNode({value, type});
} else if (type === 'undefined'){
@@ -32,7 +36,7 @@ export default class SymbolNode extends ParseNode {
}
}
reduce(scope, context){
let result = this.compile(scope);
let result = this.compile(scope, context, true);
if (result instanceof SymbolNode){
if (context) context.storeError({
type: 'info',