The templates variable in the Hulk console output is never declared before attempting to initialize it, resulting in Uncaught ReferenceErrors. This is currently causing the Hulk tests to fail when attempting to eval(stdout) and errors to occur in the browser when importing the template as a script.
Variable scope issues (outputdir)
When passing the --outputdir flag to Hulk, individual .js templates are generated for each file, but these individual templates cannot be imported/loaded as they are missing a templates variable declaration. The output only includes the compiled template with its wrapper:
templates["test"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<p>");t.b(t.v(t.f("test",c,p,0)));t.b("</p>");return t.fl(); },partials: {}, subs: { }});
Without the variable declaration, there isn't much of a point in generating the individual .js templates, as they cannot be imported as-is. It could be argued they are not meant to be imported individually, but rather concatenated and wrapped by an additional process, but in that case it makes more sense to pipe the console output to a file.
Wildcard with sub-directories issue
If a wildcard is passed to Hulk for a directory which contains sub-directories, Hulk will attempt to process those sub-directories as files with fs.readFileSync(sub-directory, 'utf-8'). Since a directory cannot be read as a file, this results in an illegal operation on a directory error.
Miscellaneous
Added line-breaks where necessary to standardize on two line-breaks before comments.
Summary of Issues fixed in this Pull Request
Variable scope issues (console)
The templates variable in the Hulk console output is never declared before attempting to initialize it, resulting in Uncaught
ReferenceErrors
. This is currently causing the Hulk tests to fail when attempting toeval(stdout)
and errors to occur in the browser when importing the template as a script.Variable scope issues (outputdir)
When passing the
--outputdir
flag to Hulk, individual.js
templates are generated for each file, but these individual templates cannot be imported/loaded as they are missing a templates variable declaration. The output only includes the compiled template with its wrapper:Without the variable declaration, there isn't much of a point in generating the individual
.js
templates, as they cannot be imported as-is. It could be argued they are not meant to be imported individually, but rather concatenated and wrapped by an additional process, but in that case it makes more sense to pipe the console output to a file.Wildcard with sub-directories issue
If a wildcard is passed to Hulk for a directory which contains sub-directories, Hulk will attempt to process those sub-directories as files with
fs.readFileSync(sub-directory, 'utf-8')
. Since a directory cannot be read as a file, this results in anillegal operation on a directory
error.Miscellaneous
Added line-breaks where necessary to standardize on two line-breaks before comments.