Skip to content

Latest version breaks with RequireJS (global is undefined) #1004

@boskee

Description

@boskee

Hello,

It looks like the latest version breaks when used with RequireJS (specifically handlebars.amd.js and handlebars.amd.min.js)

The problem exists in the following piece of code (starting at line 3859 in handlebars.amd.js):

  var $Handlebars = global.Handlebars;
  /* istanbul ignore next */
  inst.noConflict = function () {
    if (global.Handlebars === inst) {
      global.Handlebars = $Handlebars;
    }
  };

And it can be fixed by using the snippet starting at line 724 of the same file:

  var root = typeof global !== 'undefined' ? global : window,
      $Handlebars = root.Handlebars;
  /* istanbul ignore next */
  Handlebars.noConflict = function () {
    if (root.Handlebars === Handlebars) {
      root.Handlebars = $Handlebars;
    }
  };

So the code in question should become:

  var root = typeof global !== 'undefined' ? global : window,
      $Handlebars = root.Handlebars;
  /* istanbul ignore next */
  inst.noConflict = function () {
    if (root.Handlebars === inst) {
      root.Handlebars = $Handlebars;
    }
  };

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