formatError.js 695 B

1234567891011121314151617
  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. const { generateCodeFrame } = compiler_1.compiler;
  7. function formatError(err, source, file) {
  8. const loc = err.loc;
  9. if (!loc) {
  10. return;
  11. }
  12. const locString = `:${loc.start.line}:${loc.start.column}`;
  13. const filePath = chalk.gray(`at ${file}${locString}`);
  14. const codeframe = generateCodeFrame(source, loc.start.offset, loc.end.offset);
  15. err.message = `\n${chalk.red(`VueCompilerError: ${err.message}`)}\n${filePath}\n${chalk.yellow(codeframe)}\n`;
  16. }
  17. exports.formatError = formatError;