summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/handlebars6
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js20
-rw-r--r--package.json4
-rw-r--r--spec/regressions.js20
4 files changed, 36 insertions, 14 deletions
diff --git a/bin/handlebars b/bin/handlebars
index 7645adf..deb809b 100755
--- a/bin/handlebars
+++ b/bin/handlebars
@@ -1,6 +1,6 @@
#!/usr/bin/env node
-var optimist = require('optimist')
+var yargs = require('yargs')
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...', {
'f': {
'type': 'string',
@@ -110,7 +110,7 @@ var optimist = require('optimist')
});
-var argv = optimist.argv;
+var argv = yargs.argv;
argv.files = argv._;
delete argv._;
@@ -121,7 +121,7 @@ Precompiler.loadTemplates(argv, function(err, opts) {
}
if (opts.help || (!opts.templates.length && !opts.version)) {
- optimist.showHelp();
+ yargs.showHelp();
} else {
Precompiler.cli(opts);
}
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index 1708032..ed1b83e 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -503,7 +503,7 @@ JavaScriptCompiler.prototype = {
if (this.hash) {
this.hashes.push(this.hash);
}
- this.hash = {values: [], types: [], contexts: [], ids: []};
+ this.hash = {values: {}};
},
popHash: function() {
let hash = this.hash;
@@ -701,11 +701,11 @@ JavaScriptCompiler.prototype = {
child = children[i];
compiler = new this.compiler(); // eslint-disable-line new-cap
- let index = this.matchExistingProgram(child);
+ let existing = this.matchExistingProgram(child);
- if (index == null) {
+ if (existing == null) {
this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
- index = this.context.programs.length;
+ let index = this.context.programs.length;
child.index = index;
child.name = 'program' + index;
this.context.programs[index] = compiler.compile(child, options, this.context, !this.precompile);
@@ -714,12 +714,14 @@ JavaScriptCompiler.prototype = {
this.useDepths = this.useDepths || compiler.useDepths;
this.useBlockParams = this.useBlockParams || compiler.useBlockParams;
+ child.useDepths = this.useDepths;
+ child.useBlockParams = this.useBlockParams;
} else {
- child.index = index;
- child.name = 'program' + index;
+ child.index = existing.index;
+ child.name = 'program' + existing.index;
- this.useDepths = this.useDepths || child.useDepths;
- this.useBlockParams = this.useBlockParams || child.useBlockParams;
+ this.useDepths = this.useDepths || existing.useDepths;
+ this.useBlockParams = this.useBlockParams || existing.useBlockParams;
}
}
},
@@ -727,7 +729,7 @@ JavaScriptCompiler.prototype = {
for (let i = 0, len = this.context.environments.length; i < len; i++) {
let environment = this.context.environments[i];
if (environment && environment.equals(child)) {
- return i;
+ return environment;
}
}
},
diff --git a/package.json b/package.json
index 6957dab..9d37d8a 100644
--- a/package.json
+++ b/package.json
@@ -22,8 +22,8 @@
},
"dependencies": {
"async": "^1.4.0",
- "optimist": "^0.6.1",
- "source-map": "^0.4.4"
+ "source-map": "^0.4.4",
+ "yargs": "^3.32.0"
},
"optionalDependencies": {
"uglify-js": "^2.6"
diff --git a/spec/regressions.js b/spec/regressions.js
index a1eec2f..4dc2ac8 100644
--- a/spec/regressions.js
+++ b/spec/regressions.js
@@ -268,4 +268,24 @@ describe('Regressions', function() {
' 1. IF: John--\n'
+ ' 2. MYIF: John==\n');
});
+
+ it('GH-1186: Support block params for existing programs', function() {
+ var string =
+ '{{#*inline "test"}}{{> @partial-block }}{{/inline}}'
+ + '{{#>test }}{{#each listOne as |item|}}{{ item }}{{/each}}{{/test}}'
+ + '{{#>test }}{{#each listTwo as |item|}}{{ item }}{{/each}}{{/test}}';
+
+ shouldCompileTo(string, { listOne: ['a'], listTwo: ['b']}, 'ab', '');
+ });
+
+ it('should allow hash with protected array names', function() {
+ var obj = {array: [1], name: 'John'};
+ var helpers = {
+ helpa: function(options) {
+ return options.hash.length;
+ }
+ };
+
+ shouldCompileTo('{{helpa length="foo"}}', [obj, helpers], 'foo');
+ });
});