11import * as ts from 'typescript' ;
22import { isNoSubstitutionTemplateLiteral , isTemplateExpression } from './ts-is-kind' ;
33
4- type State = ';' | 'x' | ' ' | '"' | '\'' | '/' | '//' | '/$' | '//$' | '/*' | '/**' | '/*$' | '/*$*' ;
4+ type State = ';' | 'x' | ' ' | '"' | '(' | ' \'' | '/' | '//' | '/$' | '//$' | '/*' | '/**' | '/*$' | '/*$*' ;
55type ReducerResult = { emit ?: string ; skipEmit ?: boolean ; state ?: State } | void ;
66type StateMachine = {
77 [ K in State ] : {
@@ -11,13 +11,13 @@ type StateMachine = {
1111} ;
1212
1313function isSymbol ( ch : string ) {
14- return ch == ';' || ch == ':' || ch == '{' || ch == '}' ;
14+ return ch == ';' || ch == ':' || ch == '{' || ch == '}' || ch == ',' ;
1515}
1616
1717const stateMachine : StateMachine = {
1818 ';' : {
1919 next ( ch ) {
20- if ( ch == '\'' || ch == '"' ) return { state : ch }
20+ if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
2121 if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { skipEmit : true }
2222 if ( ch == '/' ) return { state : '/' , skipEmit : true }
2323 if ( isSymbol ( ch ) ) return ;
@@ -26,15 +26,15 @@ const stateMachine: StateMachine = {
2626 } ,
2727 'x' : {
2828 next ( ch ) {
29- if ( ch == '\'' || ch == '"' ) return { state : ch }
29+ if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
3030 if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { state : ' ' , skipEmit : true }
3131 if ( ch == '/' ) return { state : '/' , skipEmit : true }
3232 if ( isSymbol ( ch ) ) return { state : ';' } ;
3333 }
3434 } ,
3535 ' ' : { // may need space
3636 next ( ch ) {
37- if ( ch == '\'' || ch == '"' ) return { state : ch }
37+ if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch , emit : ' ' + ch }
3838 if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { state : ' ' , skipEmit : true }
3939 if ( ch == '/' ) return { state : '/' , skipEmit : true }
4040 if ( isSymbol ( ch ) ) return { state : ';' } ;
@@ -51,6 +51,11 @@ const stateMachine: StateMachine = {
5151 if ( ch == '"' ) return { state : ';' } ;
5252 }
5353 } ,
54+ '(' : {
55+ next ( ch ) {
56+ if ( ch == ')' ) return { state : ';' } ; // maybe return ' '? then it'd always add space after
57+ }
58+ } ,
5459 '/' : {
5560 next ( ch ) {
5661 if ( ch == '/' ) return { state : '//' , skipEmit : true }
0 commit comments