Skip to content

Commit

Permalink
Merge pull request #154 from canjs/debugger-key-lookup
Browse files Browse the repository at this point in the history
adding `debugger` as a reserved scope key
  • Loading branch information
phillipskevin authored Mar 20, 2018
2 parents 06b22d0 + 4205201 commit b8b6f04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scope-key-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var CIDSet = require("can-cid/set/set");
var makeComputeLike = require("./make-compute-like");
var canReflectDeps = require('can-reflect-dependencies');
var valueEventBindings = require("can-event-queue/value/value");
var stacheHelpers = require('can-stache-helpers');

var dispatchSymbol = canSymbol.for("can.dispatch");

Expand Down Expand Up @@ -64,6 +65,19 @@ var ScopeKeyData = function(scope, key, options){
this.read = this.read.bind(this);
this.dispatch = this.dispatch.bind(this);

// special case debugger helper so that it is called with helperOtions
// when you do {{debugger}} as it already is with {{debugger()}}
if (key === "debugger") {
// prevent "Unable to find key" warning
this.startingScope = { _context: stacheHelpers };

this.read = function() {
var helperOptions = { scope: scope };
var debuggerHelper = stacheHelpers["debugger"];
return debuggerHelper(helperOptions);
};
}

//!steal-remove-start
Object.defineProperty(this.read, "name", {
value: "{{" + this.key + "}}::ScopeKeyData.read",
Expand Down
14 changes: 14 additions & 0 deletions test/scope-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,3 +1132,17 @@ QUnit.test("functions have correct `thisArg` so they can be called even with `pr
QUnit.equal(parentFunc.value, func, "parentFunc.value === func");
QUnit.equal(parentFunc.thisArg, parentData, "rootFunc.thisArg === parentData");
});

QUnit.test("debugger is a reserved scope key for calling debugger helper", function() {
var scope = new Scope({ name: "Kevin" });

var debuggerHelper = function(options) {
return options.scope.read("name").value;
};
canStacheHelpers["debugger"] = debuggerHelper;

var debuggerScopeKey = scope.compute("debugger");
QUnit.equal(canReflect.getValue(debuggerScopeKey), "Kevin", "debugger called with correct helper options");

delete canStacheHelpers["debugger"];
});

0 comments on commit b8b6f04

Please sign in to comment.