Skip to content

Commit

Permalink
Disable warnings through comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Johnson committed Nov 22, 2018
1 parent 28dd6a8 commit da4b9c0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ 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) {
return (new RegExp(`(?:${start.line - 1}:\\s*|${start.line}:[^\\n]+)<!--\\s*warn-disable\\s+${code}.*?-->`)).test(frame)
}

function default_onwarn({ start, message }: Warning) {
if (start) {
console.warn(`(${start.line}:${start.column}) – ${message}`);
Expand Down

0 comments on commit da4b9c0

Please sign in to comment.