@@ -39,59 +39,35 @@ export interface CompileLogOptions {
3939 column ?: number
4040}
4141
42- const suppressedCompileLogs : Array < ( ) => void > = [ ]
43-
44- let isSuppressed = false
45-
46- export function suppressVueCompileLog ( suppressed : boolean ) {
47- isSuppressed = suppressed
48- if ( ! suppressed ) {
49- suppressedCompileLogs . forEach ( ( fn ) => fn ( ) )
50- suppressedCompileLogs . length = 0
51- }
52- }
53-
5442export function onCompileLog (
5543 type : 'warn' | 'error' ,
5644 error : CompileLogError ,
5745 code : string ,
5846 relativeFileName : string ,
5947 options ?: CompileLogOptions
6048) {
61- if ( isSuppressed ) {
62- // 不会导致内存泄漏吧?
63- suppressedCompileLogs . push ( print )
64- return
65- }
66- print ( )
67- function print ( ) {
68- const char =
69- type === 'warn' ? SPECIAL_CHARS . WARN_BLOCK : SPECIAL_CHARS . ERROR_BLOCK
70- if ( options ?. plugin ) {
71- // CSS 插件格式
72- const colorFn = type === 'warn' ? colors . yellow : ( s : string ) => s
73- console [ type ] (
74- char + colorFn ( `[plugin:${ options . plugin } ] ${ error . message } ` )
75- )
76- let msg = formatAtFilename ( relativeFileName , options . line , options . column )
77- if ( options . line && options . column ) {
78- msg += `\n${ generateCodeFrame ( code , {
79- line : options . line ,
80- column : options . column ,
81- } ) . replace ( / \t / g, ' ' ) } \n`
82- }
83- console . log ( msg + char )
84- } else {
85- console [ type ] (
86- char + type + ': ' + error . message + ( error . loc ? '' : char )
49+ const char =
50+ type === 'warn' ? SPECIAL_CHARS . WARN_BLOCK : SPECIAL_CHARS . ERROR_BLOCK
51+ if ( options ?. plugin ) {
52+ // CSS 插件格式
53+ const colorFn = type === 'warn' ? colors . yellow : ( s : string ) => s
54+ console [ type ] ( char + colorFn ( `[plugin:${ options . plugin } ] ${ error . message } ` ) )
55+ let msg = formatAtFilename ( relativeFileName , options . line , options . column )
56+ if ( options . line && options . column ) {
57+ msg += `\n${ generateCodeFrame ( code , {
58+ line : options . line ,
59+ column : options . column ,
60+ } ) . replace ( / \t / g, ' ' ) } \n`
61+ }
62+ console . log ( msg + char )
63+ } else {
64+ console [ type ] ( char + type + ': ' + error . message + ( error . loc ? '' : char ) )
65+ if ( error . loc ) {
66+ const start = error . loc . start
67+ console . log (
68+ 'at ' + relativeFileName + ':' + start . line + ':' + start . column
8769 )
88- if ( error . loc ) {
89- const start = error . loc . start
90- console . log (
91- 'at ' + relativeFileName + ':' + start . line + ':' + start . column
92- )
93- console . log ( generateCodeFrameColumns ( code , error . loc ) + char )
94- }
70+ console . log ( generateCodeFrameColumns ( code , error . loc ) + char )
9571 }
9672 }
9773}
0 commit comments