@@ -32,7 +32,7 @@ const stateMachine: StateMachine = {
3232 if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
3333 if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { skipEmit : true , state : ' ' } // we may need a space
3434 if ( ch == '/' ) return { state : '/' , skipEmit : true }
35- if ( isSymbol ( ch ) ) return ;
35+ if ( isSymbol ( ch ) ) return { state : ';' } ;
3636 return { state : 'x' }
3737 }
3838 } ,
@@ -51,6 +51,9 @@ const stateMachine: StateMachine = {
5151 if ( ch == '/' ) return { state : '/' , skipEmit : true }
5252 if ( isSymbol ( ch ) ) return { state : ';' } ;
5353 return { state : 'x' , emit : ' ' + ch } ;
54+ } ,
55+ flush ( last ) {
56+ if ( ! last ) return { emit : ' ' } ;
5457 }
5558 } ,
5659 '\n' : { // may need new line
@@ -170,7 +173,7 @@ const stateMachine: StateMachine = {
170173 }
171174} ;
172175
173- function createMinifier ( ) : ( next : string , last ?: boolean ) => string {
176+ export function createMinifier ( ) : ( next : string , last ?: boolean ) => string {
174177 let state : State = ';' ;
175178
176179 return ( next , last = false ) => {
@@ -195,11 +198,17 @@ function createMinifier(): (next: string, last?: boolean) => string {
195198 while ( pos < len ) {
196199 const ch = next [ pos ++ ] ;
197200 const reducer = stateMachine [ state ] ;
198- apply ( reducer . next && reducer . next ( ch ) , ch )
201+ const prevState = state ;
202+ const reducerResult = reducer . next && reducer . next ( ch ) ;
203+ apply ( reducerResult , ch )
204+ //console.log('next(', { ch, state: prevState }, '): ', reducerResult, ' -> ', { state, minified });
199205 }
200206
201207 const reducer = stateMachine [ state ] ;
202- apply ( reducer . flush && reducer . flush ( last ) ) ;
208+ const prevState = state ;
209+ const reducerResult = reducer . flush && reducer . flush ( last ) ;
210+ apply ( reducerResult ) ;
211+ //console.log('flush', { state: prevState }, '): ', reducerResult, ' -> ', { state, minified });
203212
204213 return minified ;
205214 }
0 commit comments