Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 329x 329x 329x 329x 329x 329x 329x 329x 329x 329x 329x 329x 201x 201x 201x 201x 201x 9x 9x 192x 192x 195x 190x 190x 190x 192x 192x 201x 190x 196x 2x 2x 2x 192x 201x 12x 11x 11x 1x 12x 1x 1x 180x 180x 201x 329x 329x | import { logger } from '../../core/runtime/AvenxLogger.js';
import { BuildError } from '../errors/BuildError.js';
import { formatCodeFrame } from '../errors/CompilerError.js';
/**
* Reports a compiler warning according to configured warning severities.
* @param {string} code - Avenx error/warning code (e.g. 'AVX_W03').
* @param {string|Error} errOrMessage - An Error object or formatted warning message string.
* @param {object} [config] - The application configuration object containing `warnings` overrides.
* @param {object} [location] - Location metadata { line, column, source, filename, index, length }.
*/
export function reportWarning(code, errOrMessage, config = {}, location = null) {
const warnings = (config && config.warnings) || {};
const rawSeverity = warnings[code];
const severity = typeof rawSeverity === 'string' ? rawSeverity.trim().toLowerCase() : 'warn';
if (severity === 'off' || severity === 'ignore') {
return;
}
let errorObj = null;
if (errOrMessage instanceof Error) {
errorObj = errOrMessage;
if (location && typeof errorObj.setLocation === 'function' && !errorObj.frame) {
errorObj.setLocation(location);
}
}
let message = String(errOrMessage);
if (errorObj && errorObj.message) {
message = errorObj.message;
} else if (typeof errOrMessage === 'string') {
message = errOrMessage;
if (location && location.source && location.line && location.column) {
const frame = formatCodeFrame(location.source, location.line, location.column, location);
if (frame && !message.includes(frame)) {
message += `\n\n${frame}`;
}
}
}
if (severity === 'error') {
if (errorObj) {
throw errorObj;
}
const buildErr = new BuildError(code, message);
if (location) {
buildErr.setLocation(location);
}
throw buildErr;
}
logger.warn(message);
}
export default reportWarning;
|