From f482927a59b8d320abd1e4b4cf9291dc6d676676 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Fri, 28 Dec 2018 22:23:51 -0500 Subject: [PATCH] simplify option normalization --- src/compile/index.ts | 15 +++------------ src/interfaces.ts | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/compile/index.ts b/src/compile/index.ts index 4037a6def7..8557bcdc75 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -6,17 +6,6 @@ import renderSSR from './render-ssr/index'; import { CompileOptions, Warning, Ast } from '../interfaces'; import Component from './Component'; -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; - - return normalized; -} - function default_onwarn({ start, message }: Warning) { if (start) { console.warn(`(${start.line}:${start.column}) – ${message}`); @@ -45,10 +34,12 @@ function validate_options(options: CompileOptions, stats: Stats) { } export default function compile(source: string, options: CompileOptions = {}) { - options = normalize_options(options); + options = assign({ generate: 'dom', dev: false }, options); const stats = new Stats({ onwarn: options.onwarn + ? (warning: Warning) => options.onwarn(warning, default_onwarn) + : default_onwarn }); let ast: Ast; diff --git a/src/interfaces.ts b/src/interfaces.ts index c358ca20ed..ab2fcb1944 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -60,7 +60,7 @@ export interface CompileOptions { preserveComments?: boolean | false; - onwarn?: (warning: Warning) => void; + onwarn?: (warning: Warning, default_onwarn?: (warning: Warning) => void) => void; } export interface Visitor {