index.js
function error(original, fileName) {
  if (
    original == null ||
    original.location == null ||
    original.location.start == null
  ) {
    return original;
  }

  const start = original.location.start;
  const lineNumber = start.line == null ? 1 : start.line;
  const columnNumber = start.column == null ? 1 : start.column;
  const err = new SyntaxError(`Line ${lineNumber}, column ${columnNumber}: ${original.message}`);

  Object.assign(err, {fileName, lineNumber, columnNumber, original});

  if (fileName == null) {
    return err;
  }

  err.stack = `SyntaxError: ${err.message}\n
    at ${fileName}:${lineNumber}:${columnNumber}
  `;

  return err;
}
function error(original, fileName) {
  if (
    original == null ||
    original.location == null ||
    original.location.start == null
  ) {
    return original;
  }

  const start = original.location.start;
  const lineNumber = start.line == null ? 1 : start.line;
  const columnNumber = start.column == null ? 1 : start.column;
  const err = new SyntaxError(`Line ${lineNumber}, column ${columnNumber}: ${original.message}`);

  Object.assign(err, {fileName, lineNumber, columnNumber, original});

  if (fileName == null) {
    return err;
  }

  err.stack = `SyntaxError: ${err.message}\n
    at ${fileName}:${lineNumber}:${columnNumber}
  `;

  return err;
}
function error ( original , fileName ) { if ( original == null || original . location == null || original . location . start == null ) { return original ; } const start = original . location . start ; const lineNumber = start . line == null ? 1 : start . line ; const columnNumber = start . column == null ? 1 : start . column ; const err = new SyntaxError ( ` ${ lineNumber } ${ columnNumber } ${ original . message } ` ) ; Object . assign ( err , { fileName , lineNumber , columnNumber , original } ) ; if ( fileName == null ) { return err ; } err . stack = ` ${ err . message } \n ${ fileName } ${ lineNumber } ${ columnNumber } ` ; return err ; }
Create a SyntaxError with fileName, lineNumber, columnNumber and stack
pointing to the syntax error in the the json file.

@param  {Error}  original  Pegjs syntax error
@param  {string} fileName  JSON file name
@return {Error}
Create a SyntaxError with fileName lineNumber columnNumber and stack pointing to the syntax error in the the json file .