From b91f650ffc767002449b01f25c31ae52a508a6c3 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Thu, 22 Nov 2018 10:29:08 -0800 Subject: [PATCH] Disable warnings through comments. --- src/compile/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compile/index.ts b/src/compile/index.ts index 59e204b816..a851a10fba 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -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]+)`); + return regex.test(frame); +} + function default_onwarn({ start, message }: Warning) { if (start) { console.warn(`(${start.line}:${start.column}) – ${message}`);