Skip to content
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

blockHelperMissing doesn't get property string when stringParams is enabled #617

Closed
machty opened this issue Sep 27, 2013 · 1 comment
Closed

Comments

@machty
Copy link
Contributor

machty commented Sep 27, 2013

{{#x-foo}}yeaaaah{{/x-foo}

If stringParams is enabled and x-foo isn't in the helpers hash, I'd like to be able to catch this in blockHelperMissing, but the problem is that the first parameter of blockHelperMissing ends up getting the undefined result of currentContext['x-foo'], which completely prevents me from doing something special with this value.

Context: this is important for Ember to be able to hook into for the purposes of detecting container-registered helpers and components. Without fixing this directly in handlebars, I'm forced to do this following terrible hax:

function stringifyLastBlockHelperMissingInvocation(source) {
  var helperInvocation = source[source.length - 1],
      helperName = (/helpers\.(.*)\)/.exec(helperInvocation) || /helpers\['(.*)'/.exec(helperInvocation))[1],
      matches = /(.*blockHelperMissing\.call\(.*)(stack[0-9]+)(,.*)/.exec(helperInvocation);

  source[source.length - 1] = matches[1] + "'" + helperName + "'" + matches[3];
}

var originalBlockValue = Ember.Handlebars.JavaScriptCompiler.prototype.blockValue;
Ember.Handlebars.JavaScriptCompiler.prototype.blockValue = function() {
  originalBlockValue.apply(this, arguments);
  stringifyLastBlockHelperMissingInvocation(this.source);
};

var originalAmbiguousBlockValue = Ember.Handlebars.JavaScriptCompiler.prototype.ambiguousBlockValue;
Ember.Handlebars.JavaScriptCompiler.prototype.ambiguousBlockValue = function() {
  originalAmbiguousBlockValue.apply(this, arguments);
  stringifyLastBlockHelperMissingInvocation(this.source);
};
@kpdecker
Copy link
Collaborator

kpdecker commented Nov 3, 2013

Tracked under #634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants