Parser now works with variables passed into scope
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user