toranb / ember-template-compiler

An npm module for the ember-template-compiler.js file that ships with ember.js
MIT License
30 stars 23 forks source link

{{@index}} fails #16

Closed tkellen closed 9 years ago

tkellen commented 10 years ago
var compiler = require('ember-template-compiler');
compiler.precompile('{{#each thing in things}}{{@index}}{{/each}}');

Works fine with handlebars proper. Any idea what might be up?

toranb commented 10 years ago

Great question ... @rjackson any ideas on this one?

scribu commented 10 years ago

@first also fails.

Given a test.hbs file:

<ul>
{{#each items}}
  <li {{#if @first}}class="first"{{/if}}>{{title}}</li>
{{/each}}
</ul>

and a compile.js file:

var fs = require('fs');
var compiler = require('ember-template-compiler');
var template = fs.readFileSync('test.hbs').toString();
var input = compiler.precompile(template).toString();

console.log(input);

When I run node compile.js, I get a cryptic error:

undefined:10
  stack1 = helpers['if'].call(depth0, , {hash:{},hashTypes:{},hashContexts:{},
                                      ^
SyntaxError: Unexpected token ,
    at Object.Function (<anonymous>)
    at Object.JavaScriptCompiler.createFunctionContext (./node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:189:23)
    at Object.JavaScriptCompiler.compile (./node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:115:17)
    at Object.Ember.Handlebars.precompile (./node_modules/ember-template-compiler/vendor/ember-template-compiler.js:285:52)
    at Object.<anonymous> (./compile.js:4:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

Package versions:

tkellen commented 10 years ago

http://stackoverflow.com/questions/19795562/accessing-index-in-each-in-emberjs

toranb commented 10 years ago

I spoke with an ember core team member this week at EmberConf and it doesn't sound like this will be getting any love w/out a fix from the community. Does anyone want to dive into the ember project and see how to add support for these?

rwjblue commented 9 years ago

Ember does not support @index (or any of the other @data type properties).