Move regex test into compile

pull/1861/head
Timothy Johnson 7 years ago
parent 21c301b81a
commit a36cffef8d

@ -556,6 +556,13 @@ export default class Component {
const frame = getCodeFrame(this.source, start.line - 1, start.column); const frame = getCodeFrame(this.source, start.line - 1, start.column);
if (start && warning.code && frame) {
const regex = new RegExp(`(?:${start.line - 1}:\\s*<!--\\s*svelte-disable-next-line|${start.line}:[^\\n]+<!--\\s*svelte-disable-line)\\s+${warning.code}.*?-->`);
if (regex.test(frame)) {
return;
}
}
this.stats.warn({ this.stats.warn({
code: warning.code, code: warning.code,
message: warning.message, message: warning.message,

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

Loading…
Cancel
Save