log.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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'
  44. // eslint-disable-next-line
  45. && console.warn && console.log;
  46. function outputLog(type, str, onlyOnce) {
  47. if (hasConsole) {
  48. if (onlyOnce) {
  49. if (storedLogs[str]) {
  50. return;
  51. }
  52. storedLogs[str] = true;
  53. }
  54. // eslint-disable-next-line
  55. console[type](ECHARTS_PREFIX + str);
  56. }
  57. }
  58. export function log(str, onlyOnce) {
  59. outputLog('log', str, onlyOnce);
  60. }
  61. export function warn(str, onlyOnce) {
  62. outputLog('warn', str, onlyOnce);
  63. }
  64. export function error(str, onlyOnce) {
  65. outputLog('error', str, onlyOnce);
  66. }
  67. export function deprecateLog(str) {
  68. if (process.env.NODE_ENV !== 'production') {
  69. // Not display duplicate message.
  70. outputLog('warn', 'DEPRECATED: ' + str, true);
  71. }
  72. }
  73. export function deprecateReplaceLog(oldOpt, newOpt, scope) {
  74. if (process.env.NODE_ENV !== 'production') {
  75. deprecateLog((scope ? "[" + scope + "]" : '') + (oldOpt + " is deprecated, use " + newOpt + " instead."));
  76. }
  77. }
  78. /**
  79. * If in __DEV__ environment, get console printable message for users hint.
  80. * Parameters are separated by ' '.
  81. * @usage
  82. * makePrintable('This is an error on', someVar, someObj);
  83. *
  84. * @param hintInfo anything about the current execution context to hint users.
  85. * @throws Error
  86. */
  87. export function makePrintable() {
  88. var hintInfo = [];
  89. for (var _i = 0; _i < arguments.length; _i++) {
  90. hintInfo[_i] = arguments[_i];
  91. }
  92. var msg = '';
  93. if (process.env.NODE_ENV !== 'production') {
  94. // Fuzzy stringify for print.
  95. // This code only exist in dev environment.
  96. var makePrintableStringIfPossible_1 = function (val) {
  97. 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;
  98. };
  99. msg = map(hintInfo, function (arg) {
  100. if (isString(arg)) {
  101. // Print without quotation mark for some statement.
  102. return arg;
  103. } else {
  104. var printableStr = makePrintableStringIfPossible_1(arg);
  105. if (printableStr != null) {
  106. return printableStr;
  107. } else if (typeof JSON !== 'undefined' && JSON.stringify) {
  108. try {
  109. return JSON.stringify(arg, function (n, val) {
  110. var printableStr = makePrintableStringIfPossible_1(val);
  111. return printableStr == null ? val : printableStr;
  112. });
  113. // In most cases the info object is small, so do not line break.
  114. } catch (err) {
  115. return '?';
  116. }
  117. } else {
  118. return '?';
  119. }
  120. }
  121. }).join(' ');
  122. }
  123. return msg;
  124. }
  125. /**
  126. * @throws Error
  127. */
  128. export function throwError(msg) {
  129. throw new Error(msg);
  130. }