ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
169 stars 9 forks source link

Cannot access getters of class instance #19

Closed dz4k closed 7 months ago

dz4k commented 10 months ago
import vento from "https://deno.land/x/vento/mod.ts"

class Context {
    get value() {
        return 2;
    }
}

console.log(await vento().runString("{{ value }}", new Context()))

Expected: 2

Actual: ReferenceError: value is not defined

oscarotero commented 10 months ago

The way to merge the default values with custom values is with Object.assign() (see code here), and looks like it doesn't detect getter properties.

I guess the only way to detect them is by making it enumerable (with Object.defineProperty()) but not sure if it makes sense because I assume you want to get the value dynamically? Like, for example:

class Context {
        // Return a different value every time
    get value() {
        return Math.random();
    }
}