A basic compiler based off of thejameskyle's super-tiny-compiler

fs.js 554B

123456789101112131415161718192021222324252627282930
  1. var fs = require("fs")
  2. const builtins = {
  3. readIn: function (path) {
  4. let str = fs.readFileSync(path.value, { encoding: 'utf-8' })
  5. return {
  6. value: str
  7. }
  8. }
  9. }
  10. const my_handler = {
  11. get: function (target, prop) {
  12. let methods = Object.keys(builtins)
  13. if (methods.includes(prop)) {
  14. return builtins[prop]
  15. } else {
  16. console.error("Undefined function call! No such function: ", prop)
  17. }
  18. },
  19. }
  20. const proxy_obj = new Proxy({}, my_handler)
  21. let _
  22. module.exports = function (self) {
  23. _ = self
  24. return proxy_obj
  25. }