Skip to content

Commit

Permalink
fix: Report the right file name in the compact-errors mode, if multip…
Browse files Browse the repository at this point in the history
…le files or directories are engtered
  • Loading branch information
prantlf committed May 18, 2019
1 parent 383e50a commit 7c80326
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ if (options.comments) {
parser = new parser.ParserWithComments;
}

var currentFileName = '<stdin>'
if (options.compact) {
var fileName = options.args.length ? options.args[0] + ': ' : '';
parser.parseError = parser.lexer.parseError = function(str, hash) {
console.error(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
console.error(currentFileName + ': line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
throw new Error(str);
};
}
Expand Down Expand Up @@ -103,10 +103,10 @@ function schemaError (str, err) {
}

function processFile(file) {
var src = path.normalize(file);
var source = parse(fs.readFileSync(src, "utf8"), src);
currentFileName = path.normalize(file);
var source = parse(fs.readFileSync(currentFileName, "utf8"), currentFileName);
if (options.inPlace) {
fs.writeSync(fs.openSync(src,'w+'), source, 0, "utf8");
fs.writeSync(fs.openSync(currentFileName,'w+'), source, 0, "utf8");
} else {
if (! options.quiet) { console.log(source)};
}
Expand Down

0 comments on commit 7c80326

Please sign in to comment.