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

Remove unused exports and modules #219

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 0 additions & 4 deletions src/common/argscheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ function extractParamName (callee, argIndex) {
* @throws {TypeError} if args do not satisfy spec
*/
function checkArgs (spec, functionName, args, opt_callee) {
if (!moduleExports.enableChecks) {
return;
}
var errMsg = null;
var typeName;
for (var i = 0; i < spec.length; ++i) {
Expand Down Expand Up @@ -105,4 +102,3 @@ function getValue (value, defaultValue) {

moduleExports.checkArgs = checkArgs;
moduleExports.getValue = getValue;
moduleExports.enableChecks = true;
131 changes: 0 additions & 131 deletions src/common/builder.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/common/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
*/

var utils = require('cordova/utils');
var nextGuid = 1;

/**
Expand Down Expand Up @@ -171,7 +170,7 @@ Channel.prototype.subscribe = function (eventListenerOrFunction, eventListener)

guid = eventListenerOrFunction.observer_guid;
if (typeof eventListener === 'object') {
handleEvent = utils.close(eventListener, handleEvent);
handleEvent = handleEvent.bind(eventListener);
}

if (!guid) {
Expand Down
64 changes: 56 additions & 8 deletions src/common/modulemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

var builder = require('cordova/builder');
var utils = require('cordova/utils');
var moduleMap = define.moduleMap;
var symbolList;
var deprecationMap;
Expand Down Expand Up @@ -47,10 +47,6 @@ exports.merges = function (moduleName, symbolPath, opt_deprecationMessage) {
addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
};

exports.defaults = function (moduleName, symbolPath, opt_deprecationMessage) {
addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
};

exports.runs = function (moduleName) {
addEntry('r', moduleName, null);
};
Expand All @@ -64,6 +60,58 @@ function prepareNamespace (symbolPath, context) {
}, context);
}

function clobber (obj, key, value) {
var needsProperty = false;
try {
obj[key] = value;
} catch (e) {
needsProperty = true;
}
// Getters can only be overridden by getters.
if (needsProperty || obj[key] !== value) {
utils.defineGetter(obj, key, function () {
return value;
});
}
}

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 {
clobber(obj, key, value);
}
}

/**
* Merge properties from one object onto another recursively. Properties from
* the src object will overwrite existing target property.
*
* @param target Object to merge properties into.
* @param src Object to merge properties from.
*/
function recursiveMerge (target, src) {
for (var prop in src) {
if (src.hasOwnProperty(prop)) {
if (target.prototype && target.prototype.constructor === target) {
// If the target object is a constructor override off prototype.
clobber(target.prototype, prop, src[prop]);
} else {
if (typeof src[prop] === 'object' && typeof target[prop] === 'object') {
recursiveMerge(target[prop], src[prop]);
} else {
clobber(target, prop, src[prop]);
}
}
}
}
}

exports.mapModules = function (context) {
var origSymbols = {};
context.CDV_origSymbols = origSymbols;
Expand All @@ -85,12 +133,12 @@ exports.mapModules = function (context) {
var target = parentObj[lastName];

if (strategy === 'm' && target) {
builder.recursiveMerge(target, module);
} else if ((strategy === 'd' && !target) || (strategy !== 'd')) {
recursiveMerge(target, module);
} else {
if (!(symbolPath in origSymbols)) {
origSymbols[symbolPath] = target;
}
builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
}
}
};
Expand Down
62 changes: 2 additions & 60 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,58 +47,21 @@ utils.defineGetterSetter = function (obj, key, getFunc, opt_setFunc) {
*/
utils.defineGetter = utils.defineGetterSetter;

utils.arrayIndexOf = function (a, item) {
if (a.indexOf) {
return a.indexOf(item);
}
var len = a.length;
for (var i = 0; i < len; ++i) {
if (a[i] === item) {
return i;
}
}
return -1;
};

/**
* Returns whether the item was found in the array.
*/
utils.arrayRemove = function (a, item) {
var index = utils.arrayIndexOf(a, item);
if (index !== -1) {
a.splice(index, 1);
}
return index !== -1;
};

utils.typeName = function (val) {
return Object.prototype.toString.call(val).slice(8, -1);
};

/**
* Returns an indication of whether the argument is an array or not
*/
utils.isArray = Array.isArray ||
function (a) { return utils.typeName(a) === 'Array'; };

/**
* Returns an indication of whether the argument is a Date or not
*/
utils.isDate = function (d) {
return (d instanceof Date);
};

/**
* Does a deep clone of the object.
*/
utils.clone = function (obj) {
if (!obj || typeof obj === 'function' || utils.isDate(obj) || typeof obj !== 'object') {
if (!obj || typeof obj === 'function' || obj instanceof Date || typeof obj !== 'object') {
return obj;
}

var retVal, i;

if (utils.isArray(obj)) {
if (Array.isArray(obj)) {
retVal = [];
for (i = 0; i < obj.length; ++i) {
retVal.push(utils.clone(obj[i]));
Expand All @@ -119,16 +82,6 @@ utils.clone = function (obj) {
return retVal;
};

/**
* Returns a wrapped version of the function
*/
utils.close = function (context, func, params) {
return function () {
var args = params || arguments;
return func.apply(context, args);
};
};

// ------------------------------------------------------------------------------
function UUIDcreatePart (length) {
var uuidpart = '';
Expand Down Expand Up @@ -168,14 +121,3 @@ utils.extend = (function () {
Child.prototype.constructor = Child;
};
}());

/**
* Alerts a message in any available way: alert or console.log.
*/
utils.alert = function (msg) {
if (window.alert) {
window.alert(msg);
} else if (console && console.log) {
console.log(msg);
}
};
10 changes: 0 additions & 10 deletions src/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,6 @@ var cordova = {
cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg, 'error': err });
throw err;
}
},

addConstructor: function (func) {
channel.onCordovaReady.subscribe(function () {
try {
func();
} catch (e) {
console.log('Failed to run constructor: ' + e);
}
});
}
};

Expand Down
5 changes: 0 additions & 5 deletions test/test.argscheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ describe('argscheck', function () {
var testFunc = createTestFunc(true);
expect(function () { testFunc(null, null, null, null, null, new Date()); }).toThrowError('Wrong type for parameter "func" of testFunc: Expected Function, but got Date.');
});
it('Test#011 : should not throw when checking is disabled', function () {
var testFunc = createTestFunc(false);
argscheck.enableChecks = false;
testFunc();
});
it('Test#012 : should be able to extract from all kinds of parameter formats', () => {
const check = args => argscheck.checkArgs('ss', 'testFn', args);

Expand Down