Parser now works with variables passed into scope

This commit is contained in:
Stefan Zermatten
2020-09-10 11:38:28 +02:00
parent ede4e1367d
commit 5dec760452
6 changed files with 93 additions and 17 deletions

View File

@@ -13,15 +13,32 @@ export default class SymbolNode extends ParseNode {
compile(scope){
let value = scope && scope[this.name];
let type = typeof value;
// For objects, get their value
if (type === 'object'){
value = value.value;
type = typeof value;
}
if (type === 'string' || type === 'number' || type === 'boolean'){
return new ConstantNode({value, type, previousNodes: [this]});
} else if (type === 'undefined'){
return new ErrorNode({
node: this,
error: `${this.name} could not be resolved`,
return new SymbolNode({
name: this.name,
previousNodes: [this],
});
} else {
throw new Meteor.Error(`Unexpected case: ${this.name} resolved to ${value}`);
}
}
reduce(scope){
let result = this.compile(scope);
if (result instanceof SymbolNode){
return new ErrorNode({
node: result,
error: `${this.toString()} could not be resolved`,
previousNodes: [result],
});
} else {
return result;
}
}
}