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

adding debugger as a reserved scope key #154

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"];
});