From 0867f497cc2edd8ce1163f58dbe286aed8af063d Mon Sep 17 00:00:00 2001 From: Kevin Phillips Date: Fri, 1 Dec 2017 14:57:25 -0600 Subject: [PATCH] not warning when functions are not called due to proxyMethods=false --- can-stache-key-test.js | 19 +++++++++++++++++-- can-stache-key.js | 35 +++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/can-stache-key-test.js b/can-stache-key-test.js index ce399a9..389e137 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -272,8 +272,23 @@ testHelpers.dev.devOnlyTest("a warning is not displayed when functions are read var reads = observeReader.reads("@func"); observeReader.read(data, reads, { - callMethodsOnObservables: true, - warnOnFunctionCall: "A Warning" + callMethodsOnObservables: true + }); + + QUnit.equal(teardown(), 0, "warning not displayed"); +}); + +testHelpers.dev.devOnlyTest("a warning is not displayed when functions are read but not called due to proxyMethods=false (#15)", function() { + var teardown = testHelpers.dev.willWarn(/"func" is being called as a function/); + var func = function() { + QUnit.ok(false, "method not called"); + }; + var data = new SimpleMap({ func: func }); + var reads = observeReader.reads("func"); + + observeReader.read(data, reads, { + isArgument: true, + proxyMethods: false }); QUnit.equal(teardown(), 0, "warning not displayed"); diff --git a/can-stache-key.js b/can-stache-key.js index bc16d08..1322938 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -150,22 +150,41 @@ observeReader = { } //!steal-remove-start - dev.warn( - (options.filename ? options.filename + ':' : '') + - (options.lineNumber ? options.lineNumber + ': ' : '') + - '"' + reads[0].key + '" is being called as a function.\n' + - '\tThis will not happen automatically in an upcoming release.\n' + - '\tYou should call it explicitly using "' + reads[0].key + '()".\n\n' - ); + var showWarning = function() { + dev.warn( + (options.filename ? options.filename + ':' : '') + + (options.lineNumber ? options.lineNumber + ': ' : '') + + '"' + reads[0].key + '" is being called as a function.\n' + + '\tThis will not happen automatically in an upcoming release.\n' + + '\tYou should call it explicitly using "' + reads[0].key + '()".\n\n' + ); + }; //!steal-remove-end + if(options.callMethodsOnObservables && canReflect.isObservableLike(prev) && canReflect.isMapLike(prev)) { + //!steal-remove-start + showWarning(); + //!steal-remove-end + return value.apply(prev, options.args || []); } else if ( options.isArgument && i === reads.length ) { - return options.proxyMethods !== false ? value.bind(prev) : value; + if (options.proxyMethods === false) { + return value; + } + + //!steal-remove-start + showWarning(); + //!steal-remove-end + + return value.bind(prev); } + //!steal-remove-start + showWarning(); + //!steal-remove-end + return value.apply(prev, options.args || []); } },