type errors

This commit is contained in:
ThatOneCalculator 2023-02-15 10:29:49 -08:00
parent be44679420
commit 8490b00609
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
1 changed files with 11 additions and 3 deletions

View File

@ -5,6 +5,11 @@ import { Plugin } from 'rollup';
import { createFilter, dataToEsm } from '@rollup/pluginutils';
import { RollupJsonOptions } from '@rollup/plugin-json';
interface Json5SyntaxError extends SyntaxError {
lineNumber: number;
columnNumber: number;
}
export default function json5(options: RollupJsonOptions = {}): Plugin {
const filter = createFilter(options.include, options.exclude);
const indent = 'indent' in options ? options.indent : '\t';
@ -27,9 +32,12 @@ export default function json5(options: RollupJsonOptions = {}): Plugin {
map: { mappings: '' },
};
} catch (err) {
const message = 'Could not parse JSON file';
const position = parseInt(/[\d]/.exec(err.message)[0], 10);
this.warn({ message, id, position });
if (!(err instanceof SyntaxError)) {
throw err;
}
const message = 'Could not parse JSON5 file';
const { lineNumber, columnNumber } = err as Json5SyntaxError;
this.warn({ message, id, loc: { line: lineNumber, column: columnNumber } });
return null;
}
},