bem / bem-xjst

bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server
https://bem.github.io/bem-xjst
Other
116 stars 48 forks source link

Debug: make a function helper with stack trace #333

Open qfox opened 8 years ago

qfox commented 8 years ago

Something like: new Error().stack for usual JS but for bem-xjst templates.

Stack should contains only user templates and external calls and skip internal bem-xjst code. Helper should be possible to call from any user template.

Something like:

bemhtml.compile(function(){
  block('b').def()(function(){ console.log(this.trace()); });
});
bemhtml.apply({block: 'b'});
// Trace
//     at b.def:1:13 (b.bemhtml.js:1:42)
//     at repl:4:1

cc @a-x-

miripiruni commented 8 years ago

@zxqfox BTW you can not use this.trace() with () => console.log(this.trace()) as template body. You need use regular function, not arrow function.

;)

qfox commented 8 years ago

@miripiruni fixed, ty.

miripiruni commented 8 years ago

The question is: «show me trace route how templates work».