prevwong/reka.js

Enhancement: Supporting Template Literals in Parser

K1NZ54 opened this issue · 0 comments

K1NZ54 commented

Hello,

Following the recent suggestion by @prevwong regarding supporting template literals for parsing JavaScript:


Reka.create({
  externals: {
    functions: (self) => {
       return [
         t.externalFunc({ name: "js", func: (args) => {
              const fn = new Function(`return ${args.expr}`);
              return fn();
         }})
       ]
    }
  }
});
val str = "hello world";
$js(`console.log(${str})`);

While this approach seems promising and can potentially streamline some operations, I have concerns regarding how we can update internal variables using this mechanism. Specifically, executing return statements is straightforward, but what's the proposed method for internal value updates? I'd appreciate any insights or suggested best practices on this.

Thank you for considering this enhancement and looking forward to the team's feedback.