Disable warnings through comments.

pull/1861/head
Timothy Johnson 7 years ago
parent 28dd6a899a
commit b91f650ffc

@ -11,13 +11,24 @@ function normalize_options(options: CompileOptions): CompileOptions {
let normalized = assign({ generate: 'dom', dev: false }, options);
const { onwarn } = normalized;
normalized.onwarn = onwarn
? (warning: Warning) => onwarn(warning, default_onwarn)
: default_onwarn;
normalized.onwarn = (warning: Warning) => {
if (!should_ignore(warning)) {
onwarn ? onwarn(warning, default_onwarn) : default_onwarn(warning);
}
}
return normalized;
}
function should_ignore({ start, code, frame }: Warning) {
if (!(start && code && frame)) {
return false;
}
const regex = new RegExp(`(?:${start.line - 1}:\\s*|${start.line}:[^\\n]+)<!--\\s*warn-disable\\s+${code}.*?-->`);
return regex.test(frame);
}
function default_onwarn({ start, message }: Warning) {
if (start) {
console.warn(`(${start.line}:${start.column}) ${message}`);

Loading…
Cancel
Save