11const babelParser = require ( "@babel/parser" ) ;
2- const execFileSync = require ( "child_process" ) ;
32const tsc = require ( "typescript" ) ;
43
54const path = require ( "path" ) ;
@@ -51,9 +50,7 @@ const getAllFiles = (dir, extn, files, result, regex) => {
5150 }
5251 try {
5352 result = getAllFiles ( file , extn , fs . readdirSync ( file ) , result , regex ) ;
54- } catch ( error ) {
55- continue ;
56- }
53+ } catch ( error ) { }
5754 } else {
5855 if ( regex . test ( file ) ) {
5956 result . push ( file ) ;
@@ -99,19 +96,17 @@ const getAllSrcJSAndTSFiles = (src) =>
9996 * Convert a single JS/TS file to AST
10097 */
10198const toJSAst = ( file ) => {
102- const ast = babelParser . parse (
103- fs . readFileSync ( file , "utf-8" ) ,
104- babelParserOptions
99+ return babelParser . parse (
100+ fs . readFileSync ( file , "utf-8" ) ,
101+ babelParserOptions
105102 ) ;
106- return ast ;
107103} ;
108104
109105const vueCleaningRegex = / < \/ * s c r i p t .* > | < s t y l e [ \s \S ] * s t y l e > | < \/ * b r > / ig;
110106const vueTemplateRegex = / ( < t e m p l a t e .* > ) ( [ \s \S ] * ) ( < \/ t e m p l a t e > ) / ig;
111107const vueCommentRegex = / < \! - - [ \s \S ] * ?- - > / ig;
112108const vueBindRegex = / ( : \[ ) ( [ \s \S ] * ?) ( \] ) / ig;
113- const vuePropRegex = / ( < [ \s a - z A - Z ] * ?) ( : | @ | \. ) ( [ \s \S ] * ?= ) / ig;
114-
109+ const vuePropRegex = / ( [ \s \S ] * ?) ( [ . : @ ] ) ( [ \s \S ] * ?) / ig;
115110
116111/**
117112 * Convert a single vue file to AST
@@ -129,7 +124,7 @@ const toVueAst = (file) => {
129124 . replace ( vuePropRegex , function ( match , grA , grB , grC ) {
130125 return grA +
131126 grB . replaceAll ( / \S / g, " " ) +
132- grC . replace ( / \. | : | @ / g, "-" )
127+ grC . replace ( / [ . : @ ] / g, "-" )
133128 } )
134129 . replace ( vueTemplateRegex , function ( match , grA , grB , grC ) {
135130 return grA +
@@ -138,11 +133,10 @@ const toVueAst = (file) => {
138133 . replaceAll ( "}}" , " }" ) +
139134 grC
140135 } ) ;
141- const ast = babelParser . parse (
142- cleanedCode ,
143- babelParserOptions
136+ return babelParser . parse (
137+ cleanedCode ,
138+ babelParserOptions
144139 ) ;
145- return ast ;
146140} ;
147141
148142
@@ -210,7 +204,7 @@ function createTsc(srcFiles) {
210204 } ;
211205 } catch ( err ) {
212206 console . warn ( "Retrieving types" , err . message ) ;
213- undefined ;
207+ return undefined ;
214208 }
215209}
216210
@@ -330,8 +324,6 @@ const createXAst = async (options) => {
330324 console . error ( src_dir , "is invalid" ) ;
331325 process . exit ( 1 ) ;
332326 }
333- const { projectType } = options ;
334- // node.js - package.json
335327 if (
336328 fs . existsSync ( path . join ( src_dir , "package.json" ) ) ||
337329 fs . existsSync ( path . join ( src_dir , "rush.json" ) )
0 commit comments