@@ -26,7 +26,7 @@ const IGNORE_DIRS = [
2626 "build" ,
2727] ;
2828
29- const IGNORE_FILE_PATTERN = new RegExp ( "(conf|test|spec)\\.(js|ts)$" , "i" ) ;
29+ const IGNORE_FILE_PATTERN = new RegExp ( "(conf|test|spec|\\.d )\\.(js|ts)$" , "i" ) ;
3030
3131const getAllFiles = ( dir , extn , files , result , regex ) => {
3232 files = files || fs . readdirSync ( dir ) ;
@@ -137,7 +137,6 @@ const toVueAst = (file) => {
137137 ) ;
138138} ;
139139
140-
141140function createTsc ( srcFiles ) {
142141 try {
143142 const program = tsc . createProgram ( srcFiles , {
@@ -158,7 +157,7 @@ function createTsc(srcFiles) {
158157 }
159158 }
160159
161- function safeTypeToString ( node , context ) {
160+ function safeTypeWithContextToString ( node , context ) {
162161 try {
163162 return typeChecker . typeToString ( node , context ,
164163 tsc . TypeFormatFlags . NoTruncation | tsc . TypeFormatFlags . InTypeAlias
@@ -185,10 +184,10 @@ function createTsc(srcFiles) {
185184 if ( funcSignature ) {
186185 typeStr = safeTypeToString ( funcSignature . getReturnType ( ) ) ;
187186 } else {
188- typeStr = safeTypeToString ( typeChecker . getTypeAtLocation ( node ) , node ) ;
187+ typeStr = safeTypeWithContextToString ( typeChecker . getTypeAtLocation ( node ) , node ) ;
189188 }
190189 } else {
191- typeStr = safeTypeToString ( typeChecker . getTypeAtLocation ( node ) , node ) ;
190+ typeStr = safeTypeWithContextToString ( typeChecker . getTypeAtLocation ( node ) , node ) ;
192191 }
193192 seenTypes . set ( node . getStart ( ) , typeStr ) ;
194193 tsc . forEachChild ( node , addType ) ;
@@ -206,7 +205,6 @@ function createTsc(srcFiles) {
206205 }
207206}
208207
209-
210208/**
211209 * Generate AST for JavaScript or TypeScript
212210 */
@@ -231,6 +229,7 @@ const createJSAst = async (options) => {
231229 const tsAst = ts . program . getSourceFile ( file ) ;
232230 tsc . forEachChild ( tsAst , ts . addType ) ;
233231 writeTypesFile ( file , ts . seenTypes , options ) ;
232+ ts . seenTypes . clear ( ) ;
234233 } catch ( err ) {
235234 console . warn ( "Retrieving types" , file , ":" , err . message ) ;
236235 }
@@ -258,7 +257,6 @@ const createVueAst = async (options) => {
258257 }
259258} ;
260259
261-
262260/**
263261 * Deal with cyclic reference in json
264262 */
@@ -313,7 +311,6 @@ const writeTypesFile = (file, seenTypes, options) => {
313311 console . log ( "Converted types for" , relativePath , "to" , outTypeFile ) ;
314312} ;
315313
316-
317314const createXAst = async ( options ) => {
318315 const src_dir = options . src ;
319316 try {
@@ -328,7 +325,7 @@ const createXAst = async (options) => {
328325 ) {
329326 return await createJSAst ( options ) ;
330327 }
331- console . error ( src_dir , "unkown project type" ) ;
328+ console . error ( src_dir , "unknown project type" ) ;
332329 process . exit ( 1 ) ;
333330} ;
334331
0 commit comments