Handlebars - Decompile rudders compiled code for handlebars template

Can I decompile pre-compiled Handlebars code into a Handlebars template?

Maybe convert something like this:

function program2(depth0, data) { var buffer = '', stack1; data.buffer.push('<div '); ...... data.buffer.push('</div></div>'); return buffer; }

to

<div>{{name}}</div>
+4
source share
1 answer

Unfortunately, there is currently no built-in way to do this.

One solution would be to write a function that traverses the compiled code, look for where the HTML is being pushed, and then put that HTML code together (a reversible function, essentially).

: depth0 /. , , , IE::

App.Templates = function (Handlebars, depth0, helpers, partials, data) { ... }

, , HTML, , , stack. , Handlebars (..: {{myData}}), ( ).

, :

{{#if stuff}}
    <div id="General" class="content-section">
    <p>{{myData}}</p>
    </div>
{{/if}}

depth0 stuff myData. ( , , , ):

buffer += "\r\n\r\n<div id=\"General\" class=\"content-section\">\r\n"
    + escapeExpression(((stack1 = ((stack1 = (depth0 && depth0.stuff)),
    stack1 == null || stack1 === false ? stack1 : stack1.myData)), 
    typeof stack1 === functionType ? stack1.apply(depth0) : stack1))

, - , , , .

+5

Source: https://habr.com/ru/post/1546950/


All Articles