bartsqueezy / ember-handlebars-brunch

This Brunch plugin adds support for pre-compiling Ember Handlebars templates prior to runtime
MIT License
9 stars 32 forks source link

Optimizer generates javascript with errors #3

Open huafu opened 11 years ago

huafu commented 11 years ago

I have an application using your plugin, and all works fine until I uses the --optimize options while running brunch build. Other scripts compile correctly while optimizing, I got the ember debug lines in the console, but it's telling me there is an unexpected = in the template.js file:

Uncaught SyntaxError: Unexpected token = templates.js:1
DEBUG: ------------------------------- vendor.js:5
DEBUG: Ember.VERSION : 1.0.0-rc.3 vendor.js:5
DEBUG: Handlebars.VERSION : 1.0.0-rc.3 vendor.js:5
DEBUG: jQuery.VERSION : 1.9.1 vendor.js:5
DEBUG: ------------------------------- vendor.js:5
Uncaught Error: Cannot find module "templates/application"

Here is my config:

    templates:
      precompile: true
      root: 'templates'
      defaultExtension: 'hbs'
      joinTo: 'javascripts/templates.js' : /^app/

And I can see in this javascript, after reformatting it for better reading, where is the unexpected = (in fact there is not only one, but many):

window.require.register("templates/application", function (exports, require, module) {
    Ember.TEMPLATES[= application] = Ember.Handlebars.template(function anonymous(Handlebars, depth0, helpers, partials, data) {
        this.compilerInfo = [2, '>=1.0-rc.3'];
        helpers = helpers || Ember.Handlebars.helpers;
        data = data || {};
        var buffer = '', stack1, hashTypes, helperMissing = helpers.helperMissing, escapeExpression = this.escapeExpression, self = this;

        function program1(depth0, data) {
            var stack1, hashTypes, options;
            hashTypes = {};
            options = {hash:{}, contexts:[depth0], types:[= STRING], hashTypes:hashTypes, data:data};
            data.buffer.push(escapeExpression(((stack1 = helpers.render), stack1 ? stack1.call(depth0, "left-panel", options) : helperMissing.call(depth0, "render", "left-panel", options))))
        }

So as you can see there are problematic = first in Ember.TEMPLATES[= application] (where also application should be surrounded by quotes but isn't), and then in types:[= STRING] (which I can find in any "program" function created).

Feel free to ask for more information(s) to debug if needed.

huafu commented 11 years ago

Just tested with precompile: no and got the same error (except the type:[= STRING]since it's not precompiled of course). Sounds like only the first template got compiled into

window.require.register("templates/application", function(exports, require, module)
{
  Ember.TEMPLATES[=application] = Ember.Handlebars.compile(...

where it should be, as the following ones:

window.require.register("templates/application", function(exports, require, module
{
  Ember.TEMPLATES['application'] = Ember.Handlebars.compile(...