eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
https://eta.js.org
MIT License
1.41k stars 65 forks source link

adding debug:true causes a crash #255

Closed morandd closed 1 year ago

morandd commented 1 year ago

Adding debug:true to the Eta constructor causes crashes.

templates/mypage.eta template page:

--- start of mypage.eta ---
<%~ 
/* According to 'merge' principle in the documentation, header.eta should receive it.lang and it.name */
include('header.eta',{name:'Ben'}); %>
--- end of mypage.eta ---

which uses the header templates/header.eta partial:

--header.eta
<html lang="<%~ it?.lang%>">
hi I am a header
<tag lang="<%~ JSON.stringify(it) %>">
--end header.eta

And we execute it using a simple script test.js:


import { Eta } from "https://deno.land/x/eta@v3.1.0/src/index.ts";
// WORKS: 
const etaDebugFalse = new Eta({ views:  Deno.cwd() + '/templates' });
// CAUSES A CRASH IN eta.render()
const etaDebugTrue = new Eta({ views:  Deno.cwd() + '/templates', debug:true });

console.log( etaDebugFalse.render("mypage.eta", { lang: "en" }) );
console.log( etaDebugTrue.render("mypage.eta", { lang: "en" }) );

Originally posted by @morandd in https://github.com/eta-dev/eta/issues/254#issuecomment-1680389686

nebrelbug commented 1 year ago

@morandd yep, that's definitely a bug :)

The error was in compile-string.ts:29. I just released a patch that fixes the issue with eta@3.1.1.

Thanks for filing this!