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

str.js 565B

12345678910111213141516171819202122232425262728293031
  1. const builtins = {
  2. concat: function () {
  3. let str = ""
  4. for (let i = 0; i < arguments.length; i++) {
  5. str += arguments[i].value
  6. }
  7. return {
  8. value: str
  9. }
  10. }
  11. }
  12. const my_handler = {
  13. get: function (target, prop) {
  14. let methods = Object.keys(builtins)
  15. if (methods.includes(prop)) {
  16. return builtins[prop]
  17. } else {
  18. console.error("Undefined function call! No such function: ", prop)
  19. }
  20. },
  21. }
  22. const proxy_obj = new Proxy({}, my_handler)
  23. let _
  24. module.exports = function (self) {
  25. _ = self
  26. return proxy_obj
  27. }