-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug with namespace function + AMD #108
Comments
Can you post your working non-amd and amd configs? |
@bmaland Do you use the FYI my templates can be in
And the full handlebars configuration:
|
@stephanebachelier your example works because you have a static namespace ('templates'), this bug occurs when you have a namespace function in combination with AMD. Here's a full repo showcasing the issue: https://github.com/bmaland/grunt-handlebars-sample As you can see in the built The bug is actually quite obvious when you look at https://github.com/gruntjs/grunt-contrib-handlebars/blob/master/tasks/handlebars.js#L179 and https://github.com/gruntjs/grunt-contrib-handlebars/blob/master/tasks/handlebars.js#L90 (nsInfo is overwritten in the loop, last entry wins). |
@bmaland I'm not sure I understand what you want. Correct me if I'm wrong, but for me By the way I think there is something wrong at the end of the file |
@stephanebachelier The error on |
@bmaland now it's clear :) Your first comment was indeed clear. |
Btw the config in my sample repo works just fine with |
@bmaland, can you try this against master and see if it's fixed now? |
Still seeing the same issue, only the second module is returned (last line of templates.js is still |
@bmaland I think this should fix your problem. |
@stephanebachelier your patch does indeed fix the problem |
@bmaland glad it helps. You can close this issue now. |
@stephanebachelier can you do a pull request with your fix? :) |
@stephanebachelier I just noticed that #124 wasn't merged. The commit which fixes the problem (096b9f7078d1c19128bccbd05245091136a2ee3) is not included the master branch or the 0.9.1 release. Your fork works fine though. |
@bmaland nice catch. I make a new PR. |
@bmaland it's merged in v0.9.2 |
This is a backwards incompatible bug fix and may have some issues in it. The precompile templates file now generated by a few of my projects were coded to return the specific namespace configured in options, but now it returns the lowest level namespace. Before 0.9.2
After 0.9.2
All of the templates in this file belong to JS.templates.foo. The issue being reported is valid, but I don't know that this solution is complete. "The namespace in which the precompiled templates will be assigned." If I assign namespace to "JS.templates.foo", the nsDeclarations will show 3 declarations, but the new 'extractGlobalNamespace' function will only get "JS", which isn't correct for the configured namespace. |
@lostthetrail I've added a new test to fix this issue while not changing any existing tests. IMHO it's normal to return If you don't agree share your configuration because I'm not sure I understand what you want. |
@lostthetrail if I understand you want all the precompiled templates to be under the namespace |
@lostthetrail sorry for the spam. I think I got it. Correct me if I am wrong, but if you set a namespace with any dots in it, you will only have the first part of the namespace.
The precompiled template file will ends with :
instead of
|
@lostthetrail test my branch in #131 as it should fixes your bug. |
@stephanebachelier This looks like the correct solution. I will check out your branch and test it tomorrow morning. Thank you for responding quickly to the issue. |
@stephanebachelier If you have a function that returns a dot based namespace, you will still have the issue.
|
@lostthetrail I will try to update my fix #131 with this case |
I'm using a namespace function which appends the folder name to the template namespace, resulting in the following namespaces: JST.shared/JST.module1/JST.module2. This works fine without AMD.
The problem is that when AMD is enabled, the last namespace "wins" because of the following code:
output.push("return "+nsInfo.namespace+";");
nsInfo
is here modified in the forEach loop, which leaves it at JST.module2 in my case. Alas, only JST.module2 is returned from the compiled template file instead of the root JST namespace.I'm not sure how to fix this other than adding a new configuration option. Guessing the root namespace seems hard (you can't simply remove all dots), but maybe I'm missing something.
The text was updated successfully, but these errors were encountered: