1
1
const babelParser = require ( "@babel/parser" ) ;
2
- const execFileSync = require ( "child_process" ) ;
3
2
const tsc = require ( "typescript" ) ;
4
3
5
4
const path = require ( "path" ) ;
@@ -51,9 +50,7 @@ const getAllFiles = (dir, extn, files, result, regex) => {
51
50
}
52
51
try {
53
52
result = getAllFiles ( file , extn , fs . readdirSync ( file ) , result , regex ) ;
54
- } catch ( error ) {
55
- continue ;
56
- }
53
+ } catch ( error ) { }
57
54
} else {
58
55
if ( regex . test ( file ) ) {
59
56
result . push ( file ) ;
@@ -99,19 +96,17 @@ const getAllSrcJSAndTSFiles = (src) =>
99
96
* Convert a single JS/TS file to AST
100
97
*/
101
98
const 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
105
102
) ;
106
- return ast ;
107
103
} ;
108
104
109
105
const vueCleaningRegex = / < \/ * s c r i p t .* > | < s t y l e [ \s \S ] * s t y l e > | < \/ * b r > / ig;
110
106
const vueTemplateRegex = / ( < t e m p l a t e .* > ) ( [ \s \S ] * ) ( < \/ t e m p l a t e > ) / ig;
111
107
const vueCommentRegex = / < \! - - [ \s \S ] * ?- - > / ig;
112
108
const vueBindRegex = / ( : \[ ) ( [ \s \S ] * ?) ( \] ) / ig;
113
- const vuePropRegex = / ( < [ \s a - z A - Z ] * ?) ( : | @ | \. ) ( [ \s \S ] * ?= ) / ig;
114
-
109
+ const vuePropRegex = / ( [ \s \S ] * ?) ( [ . : @ ] ) ( [ \s \S ] * ?) / ig;
115
110
116
111
/**
117
112
* Convert a single vue file to AST
@@ -129,7 +124,7 @@ const toVueAst = (file) => {
129
124
. replace ( vuePropRegex , function ( match , grA , grB , grC ) {
130
125
return grA +
131
126
grB . replaceAll ( / \S / g, " " ) +
132
- grC . replace ( / \. | : | @ / g, "-" )
127
+ grC . replace ( / [ . : @ ] / g, "-" )
133
128
} )
134
129
. replace ( vueTemplateRegex , function ( match , grA , grB , grC ) {
135
130
return grA +
@@ -138,11 +133,10 @@ const toVueAst = (file) => {
138
133
. replaceAll ( "}}" , " }" ) +
139
134
grC
140
135
} ) ;
141
- const ast = babelParser . parse (
142
- cleanedCode ,
143
- babelParserOptions
136
+ return babelParser . parse (
137
+ cleanedCode ,
138
+ babelParserOptions
144
139
) ;
145
- return ast ;
146
140
} ;
147
141
148
142
@@ -210,7 +204,7 @@ function createTsc(srcFiles) {
210
204
} ;
211
205
} catch ( err ) {
212
206
console . warn ( "Retrieving types" , err . message ) ;
213
- undefined ;
207
+ return undefined ;
214
208
}
215
209
}
216
210
@@ -330,8 +324,6 @@ const createXAst = async (options) => {
330
324
console . error ( src_dir , "is invalid" ) ;
331
325
process . exit ( 1 ) ;
332
326
}
333
- const { projectType } = options ;
334
- // node.js - package.json
335
327
if (
336
328
fs . existsSync ( path . join ( src_dir , "package.json" ) ) ||
337
329
fs . existsSync ( path . join ( src_dir , "rush.json" ) )
0 commit comments