You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/21 19:01:39 UTC
[8/10] js commit: [all] Deprecation message support to modulemapper.
[all] Deprecation message support to modulemapper.
Also changes deprecation messages so that they are logged only once.
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/a81f5ba3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/a81f5ba3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/a81f5ba3
Branch: refs/heads/master
Commit: a81f5ba3acbe4903b8ff8a294dbfa13494eca787
Parents: c2fe975
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jan 17 13:41:34 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jan 18 12:22:11 2013 -0500
----------------------------------------------------------------------
lib/common/builder.js | 4 +++-
lib/common/modulemapper.js | 3 ++-
test/test.modulemapper.js | 16 ++++++++++++++++
3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/a81f5ba3/lib/common/builder.js
----------------------------------------------------------------------
diff --git a/lib/common/builder.js b/lib/common/builder.js
index 38760d7..d7fc1ea 100644
--- a/lib/common/builder.js
+++ b/lib/common/builder.js
@@ -43,6 +43,8 @@ function assignOrWrapInDeprecateGetter(obj, key, value, message) {
if (message) {
utils.defineGetter(obj, key, function() {
console.log(message);
+ delete obj[key];
+ clobber(obj, key, value);
return value;
});
} else {
@@ -122,5 +124,5 @@ module.exports = {
include(target, objects, true, true);
},
recursiveMerge: recursiveMerge,
- clobber: clobber
+ assignOrWrapInDeprecateGetter: assignOrWrapInDeprecateGetter
};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/a81f5ba3/lib/common/modulemapper.js
----------------------------------------------------------------------
diff --git a/lib/common/modulemapper.js b/lib/common/modulemapper.js
index da5126f..c539946 100644
--- a/lib/common/modulemapper.js
+++ b/lib/common/modulemapper.js
@@ -66,6 +66,7 @@ exports.mapModules = function(context) {
var lastName = symbolPath.substr(lastDot + 1);
var module = require(moduleName);
+ var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
var parentObj = prepareNamespace(namespace, context);
var target = parentObj[lastName];
@@ -75,7 +76,7 @@ exports.mapModules = function(context) {
if (target) {
origSymbols[symbolPath] = target;
}
- builder.clobber(parentObj, lastName, module);
+ builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
}
}
};
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/a81f5ba3/test/test.modulemapper.js
----------------------------------------------------------------------
diff --git a/test/test.modulemapper.js b/test/test.modulemapper.js
index 6202c9a..bc73042 100644
--- a/test/test.modulemapper.js
+++ b/test/test.modulemapper.js
@@ -173,5 +173,21 @@ describe('modulemapper', function() {
modulemapper.loadMatchingModules(/^foo.*\/symbols$/);
expectCalled(['foo/symbols', 'foo/bar/symbols']);
});
+ it('should log about deprecated property access', function() {
+ var origConsoleLog = console.log;
+ console.log = jasmine.createSpy('console.log');
+ this.after(function() {
+ console.log = origConsoleLog;
+ });
+ modulemapper.clobbers('cordova/testmodule', 'obj', 'Use foo instead');
+ modulemapper.defaults('cordova/testmodule', 'newProp', 'Use foo instead');
+ modulemapper.mapModules(context);
+ context.obj.func();
+ context.obj.func();
+ expect(console.log.callCount).toBe(1);
+ context.newProp.func();
+ context.newProp.func();
+ expect(console.log.callCount).toBe(2);
+ });
});