Skip to content

Commit

Permalink
Migrated deprecate logs to error 32.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 committed Apr 14, 2020
1 parent 3b7c863 commit f010154
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 92 deletions.
5 changes: 5 additions & 0 deletions errors/32/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Deprecated function or property

This error occurs when using a deprecated function or property. Consult the
[API documentation](https://api.highcharts.com/) for alternatives, if no
replacement is mentioned by the error itself.
7 changes: 6 additions & 1 deletion errors/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
"title": "Non-unique point or node id",
"text": "<h1>Non-unique point or node id</h1><p>This error occurs when using the same <code>id</code> for two or more points or nodes.</p>"
},
"32": {
"title": "Deprecated function or property",
"text": "<h1>Deprecated function or property</h1><p>This error occurs when using a deprecated function or property. Consult the <a href=\"https://api.highcharts.com/\">API documentation</a> for alternatives, if no replacement is mentioned by the error itself.</p>"
},
"meta": {
"files": [
"errors/10/readme.md",
Expand All @@ -112,7 +116,8 @@
"errors/28/readme.md",
"errors/29/readme.md",
"errors/30/readme.md",
"errors/31/readme.md"
"errors/31/readme.md",
"errors/32/readme.md"
]
}
}
7 changes: 6 additions & 1 deletion js/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ H.errorMessages = {
"title": "Non-unique point or node id",
"text": "<h1>Non-unique point or node id</h1><p>This error occurs when using the same <code>id</code> for two or more points or nodes.</p>"
},
"32": {
"title": "Deprecated function or property",
"text": "<h1>Deprecated function or property</h1><p>This error occurs when using a deprecated function or property. Consult the <a href=\"https://api.highcharts.com/\">API documentation</a> for alternatives, if no replacement is mentioned by the error itself.</p>"
},
"meta": {
"files": [
"errors/10/readme.md",
Expand All @@ -127,7 +131,8 @@ H.errorMessages = {
"errors/28/readme.md",
"errors/29/readme.md",
"errors/30/readme.md",
"errors/31/readme.md"
"errors/31/readme.md",
"errors/32/readme.md"
]
}
};
4 changes: 2 additions & 2 deletions js/modules/treemap.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var color = Color.parse;
import LegendSymbolMixin from '../mixins/legend-symbol.js';
import Point from '../parts/Point.js';
import U from '../parts/Utilities.js';
var addEvent = U.addEvent, correctFloat = U.correctFloat, defined = U.defined, deprecate = U.deprecate, error = U.error, extend = U.extend, fireEvent = U.fireEvent, isArray = U.isArray, isNumber = U.isNumber, isObject = U.isObject, isString = U.isString, merge = U.merge, objectEach = U.objectEach, pick = U.pick, seriesType = U.seriesType, stableSort = U.stableSort;
var addEvent = U.addEvent, correctFloat = U.correctFloat, defined = U.defined, error = U.error, extend = U.extend, fireEvent = U.fireEvent, isArray = U.isArray, isNumber = U.isNumber, isObject = U.isObject, isString = U.isString, merge = U.merge, objectEach = U.objectEach, pick = U.pick, seriesType = U.seriesType, stableSort = U.stableSort;
import '../parts/Options.js';
import '../parts/Series.js';
/* eslint-disable no-invalid-this */
Expand Down Expand Up @@ -1259,7 +1259,7 @@ seriesType('treemap', 'scatter'
},
// TODO remove this function at a suitable version.
drillToNode: function (id, redraw) {
deprecate('treemap.drillToNode', 'treemap.setRootNode');
error(32, false, void 0, { 'treemap.drillToNode': 'treemap.setRootNode' });
this.setRootNode(id, redraw);
},
/**
Expand Down
54 changes: 14 additions & 40 deletions js/parts/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,17 @@ var charts = H.charts, doc = H.doc, win = H.win;
*
* @return {void}
*/
var error = H.error = function (code, stop, chart, params) {
function error(code, stop, chart, params) {
var isCode = isNumber(code), message = isCode ?
"Highcharts error #" + code + ": www.highcharts.com/errors/" + code + "/" :
code.toString(), defaultHandler = function () {
if (stop) {
throw new Error(message);
}
// else ...
if (win.console) {
if (win.console &&
error.messages.indexOf(message) === -1 // prevent console flooting
) {
console.log(message); // eslint-disable-line no-console
}
};
Expand All @@ -379,7 +381,12 @@ var error = H.error = function (code, stop, chart, params) {
else {
defaultHandler();
}
};
error.messages.push(message);
}
(function (error) {
error.messages = [];
})(error || (error = {}));
H.error = error;
/* eslint-disable no-invalid-this, valid-jsdoc */
/**
* An animator object used internally. One instance applies to one property
Expand Down Expand Up @@ -1871,7 +1878,7 @@ var getStyle = H.getStyle = function (el, prop, toInt) {
* The index within the array, or -1 if not found.
*/
var inArray = H.inArray = function (item, arr, fromIndex) {
deprecate('Highcharts.inArray', 'Array.indexOf');
error(32, false, void 0, { 'Highcharts.inArray': 'Array.indexOf' });
return arr.indexOf(item, fromIndex);
};
/* eslint-disable valid-jsdoc */
Expand Down Expand Up @@ -1905,39 +1912,6 @@ var find = H.find = Array.prototype.find ?
}
}
};
/**
* Creates a deprecation warning in the console, ones for each context.
*
* @private
*
* @param {string} [fnName]
* Given function name. This skips stack analysis.
*
* @param {string} [newFnName]
* New function name to use.
*/
function deprecate(fnName, newFnName) {
if (!fnName) {
try {
throw new Error();
}
catch (err) {
if (err instanceof Error) {
fnName = (err.stack || '').split('\n')[1];
}
}
}
if (fnName &&
win.console &&
deprecateFnNames.indexOf(fnName) === -1) {
deprecateFnNames.push(fnName);
// eslint-disable-next-line no-console
console.log("Highcharts warning: " + fnName + " is deprecated! " + (newFnName ?
"Please use " + newFnName + " instead." :
'Please consult https://api.highcharts.com for details.'));
}
}
var deprecateFnNames = [];
/**
* Returns an array of a given object's own properties.
*
Expand All @@ -1951,7 +1925,7 @@ var deprecateFnNames = [];
* An array of strings that represents all the properties.
*/
H.keys = function () {
deprecate('Highcharts.keys', 'Object.keys');
error(32, false, void 0, { 'Highcharts.keys': 'Object.keys' });
return Object.keys.apply(arguments);
};
/**
Expand Down Expand Up @@ -2133,7 +2107,8 @@ objectEach({
some: 'some'
}, function (val, key) {
H[key] = function (arr) {
deprecate("Highcharts." + key, "Array." + val);
var _a;
error(32, false, void 0, (_a = {}, _a["Highcharts." + key] = "Array." + val, _a));
return Array.prototype[val].apply(arr, [].slice.call(arguments, 1));
};
});
Expand Down Expand Up @@ -2567,7 +2542,6 @@ var utilitiesModule = {
createElement: createElement,
css: css,
defined: defined,
deprecate: deprecate,
destroyObjectProperties: destroyObjectProperties,
discardElement: discardElement,
erase: erase,
Expand Down
3 changes: 1 addition & 2 deletions ts/modules/treemap.src.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ const {
addEvent,
correctFloat,
defined,
deprecate,
error,
extend,
fireEvent,
Expand Down Expand Up @@ -1994,7 +1993,7 @@ seriesType<Highcharts.TreemapSeries>(
id: string,
redraw?: boolean
): void {
deprecate('treemap.drillToNode', 'treemap.setRootNode');
error(32, false, void 0, { 'treemap.drillToNode': 'treemap.setRootNode' });
this.setRootNode(id, redraw);
},
/**
Expand Down
62 changes: 16 additions & 46 deletions ts/parts/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ var charts = H.charts,
*
* @return {void}
*/
const error = H.error = function (
function error(
code: (number|string),
stop?: boolean,
chart?: Highcharts.Chart,
Expand All @@ -718,7 +718,10 @@ const error = H.error = function (
throw new Error(message);
}
// else ...
if (win.console) {
if (
win.console &&
error.messages.indexOf(message) === -1 // prevent console flooting
) {
console.log(message); // eslint-disable-line no-console
}
};
Expand Down Expand Up @@ -747,7 +750,14 @@ const error = H.error = function (
} else {
defaultHandler();
}
};

error.messages.push(message);
}
namespace error {
export const messages: Array<string> = [];
}
H.error = error;


/* eslint-disable no-invalid-this, valid-jsdoc */
/**
Expand Down Expand Up @@ -2661,7 +2671,7 @@ const getStyle = H.getStyle = function (
* The index within the array, or -1 if not found.
*/
const inArray = H.inArray = function (item: any, arr: Array<any>, fromIndex?: number): number {
deprecate('Highcharts.inArray', 'Array.indexOf');
error(32, false, void 0, { 'Highcharts.inArray': 'Array.indexOf' });
return arr.indexOf(item, fromIndex);
};

Expand Down Expand Up @@ -2699,45 +2709,6 @@ const find = H.find = (Array.prototype as any).find ?
}
};

/**
* Creates a deprecation warning in the console, ones for each context.
*
* @private
*
* @param {string} [fnName]
* Given function name. This skips stack analysis.
*
* @param {string} [newFnName]
* New function name to use.
*/
function deprecate(fnName?: string, newFnName?: string): void {
if (!fnName) {
try {
throw new Error();
} catch (err) {
if (err instanceof Error) {
fnName = (err.stack || '').split('\n')[1];
}
}
}
if (
fnName &&
win.console &&
deprecateFnNames.indexOf(fnName) === -1
) {
deprecateFnNames.push(fnName);
// eslint-disable-next-line no-console
console.log(
`Highcharts warning: ${fnName} is deprecated! ` + (
newFnName ?
`Please use ${newFnName} instead.` :
'Please consult https://api.highcharts.com for details.'
)
);
}
}
const deprecateFnNames: Array<string> = [];

/**
* Returns an array of a given object's own properties.
*
Expand All @@ -2751,7 +2722,7 @@ const deprecateFnNames: Array<string> = [];
* An array of strings that represents all the properties.
*/
H.keys = function (): Array<string> {
deprecate('Highcharts.keys', 'Object.keys');
error(32, false, void 0, { 'Highcharts.keys': 'Object.keys' });
return Object.keys.apply(arguments);
};

Expand Down Expand Up @@ -2949,7 +2920,7 @@ objectEach({
some: 'some'
}, function (val: any, key: string): void {
(H as any)[key] = function (arr: Array<any>): any {
deprecate(`Highcharts.${key}`, `Array.${val}`);
error(32, false, void 0, { [`Highcharts.${key}`]: `Array.${val}` });
return Array.prototype[val].apply(
arr,
[].slice.call(arguments, 1)
Expand Down Expand Up @@ -3498,7 +3469,6 @@ const utilitiesModule = {
createElement,
css,
defined,
deprecate,
destroyObjectProperties,
discardElement,
erase,
Expand Down

0 comments on commit f010154

Please sign in to comment.