@@ -8,26 +8,34 @@ import Stylesheet from './css/Stylesheet';
8
8
import { Parsed , CompileOptions , Warning } from './interfaces' ;
9
9
10
10
function normalizeOptions ( options : CompileOptions ) : CompileOptions {
11
- return assign (
12
- {
13
- generate : 'dom' ,
11
+ let normalizedOptions = Object . assign ( { generate : 'dom' } , options ) ;
12
+ const { onwarn, onerror } = normalizedOptions ;
13
+ if ( onwarn ) {
14
+ normalizedOptions . onwarn = ( warning : Warning ) =>
15
+ onwarn ( warning , defaultOnwarn ) ;
16
+ } else {
17
+ normalizedOptions . onwarn = defaultOnwarn ;
18
+ }
19
+ if ( onerror ) {
20
+ normalizedOptions . onerror = ( error : Error ) => onwarn ( error , defaultOnerror ) ;
21
+ } else {
22
+ normalizedOptions . onerror = defaultOnerror ;
23
+ }
24
+ return normalizedOptions ;
25
+ }
14
26
15
- onwarn : ( warning : Warning ) => {
16
- if ( warning . loc ) {
17
- console . warn (
18
- `(${ warning . loc . line } :${ warning . loc . column } ) – ${ warning . message } `
19
- ) ; // eslint-disable-line no-console
20
- } else {
21
- console . warn ( warning . message ) ; // eslint-disable-line no-console
22
- }
23
- } ,
27
+ function defaultOnwarn ( warning : Warning ) {
28
+ if ( warning . loc ) {
29
+ console . warn (
30
+ `(${ warning . loc . line } :${ warning . loc . column } ) – ${ warning . message } `
31
+ ) ; // eslint-disable-line no-console
32
+ } else {
33
+ console . warn ( warning . message ) ; // eslint-disable-line no-console
34
+ }
35
+ }
24
36
25
- onerror : ( error : Error ) => {
26
- throw error ;
27
- } ,
28
- } ,
29
- options
30
- ) ;
37
+ function defaultOnerror ( error : Error ) {
38
+ throw error ;
31
39
}
32
40
33
41
export function compile ( source : string , _options : CompileOptions ) {
0 commit comments