formatError.js 664 B

12345678910111213141516
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.formatError = void 0;
  4. const compiler_1 = require("./compiler");
  5. const chalk = require("chalk");
  6. function formatError(err, source, file) {
  7. const loc = err.loc;
  8. if (!loc) {
  9. return;
  10. }
  11. const locString = `:${loc.start.line}:${loc.start.column}`;
  12. const filePath = chalk.gray(`at ${file}${locString}`);
  13. const codeframe = compiler_1.compiler.generateCodeFrame(source, loc.start.offset, loc.end.offset);
  14. err.message = `\n${chalk.red(`VueCompilerError: ${err.message}`)}\n${filePath}\n${chalk.yellow(codeframe)}\n`;
  15. }
  16. exports.formatError = formatError;