From a36cffef8dffe9c721e3db820c1369c69a002880 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sun, 25 Nov 2018 11:36:21 -0800 Subject: [PATCH] Move regex test into compile --- src/compile/Component.ts | 7 +++++++ src/compile/index.ts | 17 +++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index ca0ff8b5ba..73cec311ec 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -556,6 +556,13 @@ export default class Component { const frame = getCodeFrame(this.source, start.line - 1, start.column); + if (start && warning.code && frame) { + const regex = new RegExp(`(?:${start.line - 1}:\\s*`); + if (regex.test(frame)) { + return; + } + } + this.stats.warn({ code: warning.code, message: warning.message, diff --git a/src/compile/index.ts b/src/compile/index.ts index 50c1019ae9..59e204b816 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -11,24 +11,13 @@ function normalize_options(options: CompileOptions): CompileOptions { let normalized = assign({ generate: 'dom', dev: false }, options); const { onwarn } = normalized; - normalized.onwarn = (warning: Warning) => { - if (!should_ignore(warning)) { - onwarn ? onwarn(warning, default_onwarn) : default_onwarn(warning); - } - } + normalized.onwarn = onwarn + ? (warning: Warning) => onwarn(warning, default_onwarn) + : default_onwarn; return normalized; } -function should_ignore({ start, code, frame }: Warning) { - if (!(start && code && frame)) { - return false; - } - - const regex = new RegExp(`(?:${start.line - 1}:\\s*`); - return regex.test(frame); -} - function default_onwarn({ start, message }: Warning) { if (start) { console.warn(`(${start.line}:${start.column}) – ${message}`);