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

Add filename and line number to warnings #108

Merged
merged 2 commits into from
Oct 30, 2017
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "can-view-scope",
"version": "3.5.0",
"version": "3.5.1",
"description": "Observable scopes",
"homepage": "http://canjs.com",
"repository": {
Expand Down
29 changes: 22 additions & 7 deletions template-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var canSymbol = require("can-symbol");
var SimpleMap = require("can-simple-map");
var defineLazyValue = require("can-define-lazy-value");
var dev = require("can-log/dev/dev");
var observation = require('can-observation');

var getKeyValueSymbol = canSymbol.for("can.getKeyValue"),
setKeyValueSymbol = canSymbol.for("can.setKeyValue");
Expand All @@ -16,26 +17,40 @@ var nonObservableVars = {
event: true,
viewModel: true,
arguments: true,
lineNumber: true
lineNumber: true,
filename: true
};

var getKeyAndParent = function(parent, key) {
var getKeyAndParent = observation.ignore(function(templateContext, key) {

var parent = templateContext;
//!steal-remove-start
var filename = templateContext.nonObservableVars.filename;
var lineNumber = templateContext.nonObservableVars.lineNumber;
//!steal-remove-end

if (key.substr(0, 6) === "scope.") {
key = key.substr(6);
parent = parent;
} else if (key === "*self") {
key = "view";
parent = parent;

//!steal-remove-start
dev.warn("{{>*self}} is deprecated. Use {{>scope.view}} instead.");
dev.warn(
(filename ? filename + ':' : '') +
(lineNumber ? lineNumber + ': ' : '') +
"{{>*self}} is deprecated. Use {{>scope.view}} instead."
);
//!steal-remove-end
} else if (key.substr(0, 1) === "*") {
key = key.substr(1);
parent = parent.vars;

//!steal-remove-start
dev.warn("{{*" + key + "}} is deprecated. Use {{scope.vars." + key + "}} instead.");
dev.warn(
(filename ? filename + ':' : '') +
(lineNumber ? lineNumber + ': ' : '') +
"{{*" + key + "}} is deprecated. Use {{scope.vars." + key + "}} instead."
);
//!steal-remove-end
}

Expand All @@ -52,7 +67,7 @@ var getKeyAndParent = function(parent, key) {
key: key,
parent: parent
};
};
});

var TemplateContext = SimpleMap.extend("TemplateContext", {});

Expand Down
8 changes: 6 additions & 2 deletions test/scope-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,22 @@ QUnit.test("scope can be used to read the templateContext", function() {
});

testHelpers.dev.devOnlyTest("using {{>*self}} should show deprecation warning", function() {
var teardown = testHelpers.dev.willWarn("{{>*self}} is deprecated. Use {{>scope.view}} instead.");
var teardown = testHelpers.dev.willWarn("filename:10: {{>*self}} is deprecated. Use {{>scope.view}} instead.");

var scope = new Scope({});
scope.set("scope.filename", "filename");
scope.set("scope.lineNumber", "10");
scope.peek("*self");

QUnit.equal(teardown(), 1, "deprecation warning displayed");
});

testHelpers.dev.devOnlyTest("using *foo should show deprecation warning", function() {
var teardown = testHelpers.dev.willWarn("{{*foo}} is deprecated. Use {{scope.vars.foo}} instead.");
var teardown = testHelpers.dev.willWarn("filename:5: {{*foo}} is deprecated. Use {{scope.vars.foo}} instead.");

var scope = new Scope({});
scope.set("scope.filename", "filename");
scope.set("scope.lineNumber", "5");
scope.peek("*foo");

QUnit.equal(teardown(), 1, "deprecation warning displayed");
Expand Down