pcardune / handlebars-loader

A handlebars template loader for webpack
551 stars 168 forks source link

MyJavaScriptCompiler.prototype.nameLookup try to resolve context as helper #54

Open JSteunou opened 8 years ago

JSteunou commented 8 years ago

I had a weird compilation error using this loader & hbs v3

After hours I isolated the issue, this loader try to resolve helper path even for context "variable", and it gets crazy when it actually finds a file, taken as the researched helper, totally by coincidence, because a file with the same name that the context "variable" happens to be here.

Example

views/forms/email.hbs
views/forms/email.js
<div class="login-layout__form">

    <h1><strong>{{ title }}</strong></h1>

    <form>
        <div class="o-input">
            <input name="email" type="email" value="{{ email }}" disabled>
        </div>
...      

debug print I got this

Compilation pass 1

nameLookup depth0 title context
nameLookup helpers title helper
nameLookup helpers title helper
nameLookup depth0 email context
nameLookup helpers email helper
nameLookup helpers email helper
Attempting to resolve helpers:
{ '$title': null, '$email': null }
Attempting to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./title
request=./title
Attempting to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./email
request=./email
Failed to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./title
Resolved helper /home/jerome/myProject/src/modules/login/views/forms\./email
Attempting to resolve unclearStuff:
{ '$title': false, '$email': false }
Attempting to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./title
request=./title
Failed to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./title
Attempting to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./email
request=./email
Resolved unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./email
Attempting to resolve partials:
{}

Compilation pass 2
compiler.js:220:12)
    at Object.MustacheStatement (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:196:10)
    at Object.accept (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:109:30)
    at Object.Program (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:120:12)
    at Object.accept (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:109:30)
    at Object.compile (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:90:17)
    at Object.precompile (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:464:40)
    at HandlebarsEnvironment.hb.precompile (/home/jerome/myProject/node_modules/handlebars/dist/cjs/handlebars.js:41:41)
    at compile (/home/jerome/myProject/node_modules/handlebars-loader/index.js:140:18)
    at doneResolving (/home/jerome/myProject/node_modules/handlebars-loader/index.js:247:12)
    at Object.async.each (/home/jerome/myProject/node_modules/handlebars-loader/node_modules/async/lib/async.js:107:20)
    at resolvePartials (/home/jerome/myProject/node_modules/handlebars-loader/index.js:264:10)
    at /home/jerome/myProject/node_modules/handlebars-loader/node_modules/async/lib/async.js:119:25
    at /home/jerome/myProject/node_modules/handlebars-loader/node_modules/async/lib/async.js:24:16
    at /home/jerome/myProject/node_modules/handlebars-loader/index.js:194:5
    at /home/jerome/myProject/node_modules/handlebars-loader/index.js:176:14
    at /home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at /home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:127:10
    at /home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /home/jerome/myProject/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/DirectoryDefaultFilePlugin.js:21:12)
    at Storage.provide (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:52:20)
    at CachedInputFileSystem.stat (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:132:20)
    at Tapable.<anonymous> (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/DirectoryDefaultFilePlugin.js:18:6)
    at Tapable.applyPluginsParallelBailResult (/home/jerome/myProject/node_modules/webpack/node_modules/tapable/lib/Tapable.js:139:14)
    at Tapable.<anonymous> (/home/jerome/myProject/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:103:8)
 @ ./test.js 1:0-54

notice the Resolved helper /home/jerome/myProject/src/modules/login/views/forms\./email and the explosion of handlebars.

and if I rename the variable email by eeemail everything goes fine and I got this

Compilation pass 1

nameLookup depth0 title context
nameLookup helpers title helper
nameLookup helpers title helper
nameLookup depth0 eeeemail context
nameLookup helpers eeeemail helper
nameLookup helpers eeeemail helper
Attempting to resolve helpers:
{ '$title': null, '$eeeemail': null }
Attempting to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./title
request=./title
Attempting to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./eeeemail
request=./eeeemail
Failed to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./title
Failed to resolve helper /home/jerome/myProject/src/modules/login/views/forms\./eeeemail
Attempting to resolve unclearStuff:
{ '$title': false, '$eeeemail': false }
Attempting to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./title
request=./title
Failed to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./title
Attempting to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./eeeemail
request=./eeeemail
Failed to resolve unclearStuff /home/jerome/myProject/src/modules/login/views/forms\./eeeemail
Attempting to resolve partials:
{}
Hash: f958b6461a5757f82fb5
Version: webpack 1.11.0
Time: 1296ms

For having working a little with hbsv1 ast and hbsv3 ast, I think some pieces of this loader are not hbsv3 compatible

noirbizarre commented 8 years ago

I have exactly the same issue. For me it's working with 1.0.2 and not 1.1.0 or 1.1.1.

JSteunou commented 8 years ago

If you're not bound to this loader because of some features, go with handlebars-template-loader @noirbizarre it's very descent, does the job without fuzz and the maintainer is active.

noirbizarre commented 8 years ago

@JSteunou : Thanks, but I need some feature from handlebars-loader and 1.0.2 is working just fine :)

altano commented 8 years ago

Just FYI, I usually look at and fix issues once every 3 months or so. If that's not fast enough for anyone, just submit a pull request. If you submit multiple good pull requests I'll even make you a maintainer.

JSteunou commented 8 years ago

No offence, I just thought this one was very stable and will fit my needs because it's the only one listed on webpack loader list documentation, but I encountered many bugs and frustration then I discover another loader that fit my needs on which I choose to participate on.