Finished migrating parser to be object orientation free. All tests pass

This commit is contained in:
Stefan Zermatten
2021-10-03 13:54:17 +02:00
parent d30184434c
commit b78517b61f
35 changed files with 589 additions and 654 deletions

View File

@@ -0,0 +1,37 @@
import resolve, { toString, traverse } from '../resolve.js';
import constant from './constant.js';
const not = {
create({right}) {
return {
parseType: 'not',
right,
}
},
resolve(fn, node, scope, context){
const {result: right} = resolve(fn, node.right, scope, context);
if (right.parseType !== 'constant'){
return {
result: not.create({
right: right,
}),
context,
};
}
return {
result: constant.create({
value: !right.value,
}),
context,
};
},
toString(node){
return `!${toString(node.right)}`;
},
traverse(node, fn){
fn(node);
traverse(node.right, fn);
}
}
export default not;