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/17 19:42:14 UTC

[2/2] js commit: [all] Deprecation message support to modulemapper.

Updated Branches:
  refs/heads/symbolmapping a9eb0111f -> 24043527d


[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/24043527
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/24043527
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/24043527

Branch: refs/heads/symbolmapping
Commit: 24043527dc7405205d6c5047abed652be1eaddc2
Parents: 4450d43
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jan 17 13:41:34 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jan 17 13:41:34 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/24043527/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/24043527/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/24043527/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);
+    });
 });