log.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { map, isString, isFunction, eqNaN, isRegExp } from 'zrender/lib/core/util.js';
  41. var ECHARTS_PREFIX = '[ECharts] ';
  42. var storedLogs = {};
  43. var hasConsole = typeof console !== 'undefined' // eslint-disable-next-line
  44. && console.warn && console.log;
  45. function outputLog(type, str, onlyOnce) {
  46. if (hasConsole) {
  47. if (onlyOnce) {
  48. if (storedLogs[str]) {
  49. return;
  50. }
  51. storedLogs[str] = true;
  52. } // eslint-disable-next-line
  53. console[type](ECHARTS_PREFIX + str);
  54. }
  55. }
  56. export function log(str, onlyOnce) {
  57. outputLog('log', str, onlyOnce);
  58. }
  59. export function warn(str, onlyOnce) {
  60. outputLog('warn', str, onlyOnce);
  61. }
  62. export function error(str, onlyOnce) {
  63. outputLog('error', str, onlyOnce);
  64. }
  65. export function deprecateLog(str) {
  66. if (process.env.NODE_ENV !== 'production') {
  67. // Not display duplicate message.
  68. outputLog('warn', 'DEPRECATED: ' + str, true);
  69. }
  70. }
  71. export function deprecateReplaceLog(oldOpt, newOpt, scope) {
  72. if (process.env.NODE_ENV !== 'production') {
  73. deprecateLog((scope ? "[" + scope + "]" : '') + (oldOpt + " is deprecated, use " + newOpt + " instead."));
  74. }
  75. }
  76. /**
  77. * If in __DEV__ environment, get console printable message for users hint.
  78. * Parameters are separated by ' '.
  79. * @usage
  80. * makePrintable('This is an error on', someVar, someObj);
  81. *
  82. * @param hintInfo anything about the current execution context to hint users.
  83. * @throws Error
  84. */
  85. export function makePrintable() {
  86. var hintInfo = [];
  87. for (var _i = 0; _i < arguments.length; _i++) {
  88. hintInfo[_i] = arguments[_i];
  89. }
  90. var msg = '';
  91. if (process.env.NODE_ENV !== 'production') {
  92. // Fuzzy stringify for print.
  93. // This code only exist in dev environment.
  94. var makePrintableStringIfPossible_1 = function (val) {
  95. return val === void 0 ? 'undefined' : val === Infinity ? 'Infinity' : val === -Infinity ? '-Infinity' : eqNaN(val) ? 'NaN' : val instanceof Date ? 'Date(' + val.toISOString() + ')' : isFunction(val) ? 'function () { ... }' : isRegExp(val) ? val + '' : null;
  96. };
  97. msg = map(hintInfo, function (arg) {
  98. if (isString(arg)) {
  99. // Print without quotation mark for some statement.
  100. return arg;
  101. } else {
  102. var printableStr = makePrintableStringIfPossible_1(arg);
  103. if (printableStr != null) {
  104. return printableStr;
  105. } else if (typeof JSON !== 'undefined' && JSON.stringify) {
  106. try {
  107. return JSON.stringify(arg, function (n, val) {
  108. var printableStr = makePrintableStringIfPossible_1(val);
  109. return printableStr == null ? val : printableStr;
  110. }); // In most cases the info object is small, so do not line break.
  111. } catch (err) {
  112. return '?';
  113. }
  114. } else {
  115. return '?';
  116. }
  117. }
  118. }).join(' ');
  119. }
  120. return msg;
  121. }
  122. /**
  123. * @throws Error
  124. */
  125. export function throwError(msg) {
  126. throw new Error(msg);
  127. }