Skip to content

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

@machty

Description

@machty
{{#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);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions