Skip to content

Commit 571d836

Browse files
Fix for vuePropRegex
1 parent d2972f4 commit 571d836

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

index.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const babelParser = require("@babel/parser");
2-
const execFileSync = require("child_process");
32
const tsc = require("typescript");
43

54
const 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
*/
10198
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
105102
);
106-
return ast;
107103
};
108104

109105
const vueCleaningRegex = /<\/*script.*>|<style[\s\S]*style>|<\/*br>/ig;
110106
const vueTemplateRegex = /(<template.*>)([\s\S]*)(<\/template>)/ig;
111107
const vueCommentRegex = /<\!--[\s\S]*?-->/ig;
112108
const vueBindRegex = /(:\[)([\s\S]*?)(\])/ig;
113-
const vuePropRegex = /(<[\sa-zA-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"))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@joernio/astgen",
3-
"version": "2.14.0",
3+
"version": "2.15.0",
44
"description": "Generate JS/TS AST in json format with Babel",
55
"exports": "./index.js",
66
"keywords": [

0 commit comments

Comments
 (0)