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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 542x 14x 14x 14x 14x 14x 14x 14x 542x 542x 542x 542x 542x 542x 542x 542x 542x 776x 4x 4x 772x 776x 776x 776x 776x 776x 22x 22x 750x 750x 754x 740x 740x 1x 1x 740x 750x 750x 776x 740x 768x 10x 10x 8x 8x 8x 8x 8x 10x 750x 773x 20x 18x 18x 2x 20x 1x 1x 2x 2x 730x 730x 776x 542x 542x | import { logger } from '../../core/runtime/AvenxLogger.js';
import { BuildError } from '../errors/BuildError.js';
import { formatCodeFrame } from '../errors/CompilerError.js';
/**
* How many {@link withWarningsSuppressed} calls are currently running. While
* it is above zero, {@link reportWarning} reports nothing.
* @type {number}
*/
let suppressionDepth = 0;
/**
* Runs `fn` without reporting any compiler warning it raises.
*
* For a second pass over source that has already been compiled and reported
* once, such as `avenx stats` re-parsing each template to measure its size.
* Without this, every diagnostic from the first pass was printed again.
* @template T
* @param {() => T} fn - The work to run.
* @returns {T} Whatever `fn` returns.
*/
export function withWarningsSuppressed(fn) {
suppressionDepth++;
try {
return fn();
} finally {
suppressionDepth--;
}
}
/**
* 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) {
if (suppressionDepth > 0) {
return;
}
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;
|