Skip to content

Commit

Permalink
Fix for vuePropRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
max-leuthaeuser committed Mar 17, 2023
1 parent d2972f4 commit 571d836
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
28 changes: 10 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const babelParser = require("@babel/parser");
const execFileSync = require("child_process");
const tsc = require("typescript");

const path = require("path");
Expand Down Expand Up @@ -51,9 +50,7 @@ const getAllFiles = (dir, extn, files, result, regex) => {
}
try {
result = getAllFiles(file, extn, fs.readdirSync(file), result, regex);
} catch (error) {
continue;
}
} catch (error) {}
} else {
if (regex.test(file)) {
result.push(file);
Expand Down Expand Up @@ -99,19 +96,17 @@ const getAllSrcJSAndTSFiles = (src) =>
* Convert a single JS/TS file to AST
*/
const toJSAst = (file) => {
const ast = babelParser.parse(
fs.readFileSync(file, "utf-8"),
babelParserOptions
return babelParser.parse(
fs.readFileSync(file, "utf-8"),
babelParserOptions
);
return ast;
};

const vueCleaningRegex = /<\/*script.*>|<style[\s\S]*style>|<\/*br>/ig;
const vueTemplateRegex = /(<template.*>)([\s\S]*)(<\/template>)/ig;
const vueCommentRegex = /<\!--[\s\S]*?-->/ig;
const vueBindRegex = /(:\[)([\s\S]*?)(\])/ig;
const vuePropRegex = /(<[\sa-zA-Z]*?)(:|@|\.)([\s\S]*?=)/ig;

const vuePropRegex = /([\s\S]*?)([.:@])([\s\S]*?)/ig;

/**
* Convert a single vue file to AST
Expand All @@ -129,7 +124,7 @@ const toVueAst = (file) => {
.replace(vuePropRegex, function(match, grA, grB, grC){
return grA +
grB.replaceAll(/\S/g, " ") +
grC.replace(/\.|:|@/g, "-")
grC.replace(/[.:@]/g, "-")
})
.replace(vueTemplateRegex, function(match, grA, grB, grC){
return grA +
Expand All @@ -138,11 +133,10 @@ const toVueAst = (file) => {
.replaceAll("}}", " }") +
grC
});
const ast = babelParser.parse(
cleanedCode,
babelParserOptions
return babelParser.parse(
cleanedCode,
babelParserOptions
);
return ast;
};


Expand Down Expand Up @@ -210,7 +204,7 @@ function createTsc(srcFiles) {
};
} catch (err) {
console.warn("Retrieving types", err.message);
undefined;
return undefined;
}
}

Expand Down Expand Up @@ -330,8 +324,6 @@ const createXAst = async (options) => {
console.error(src_dir, "is invalid");
process.exit(1);
}
const { projectType } = options;
// node.js - package.json
if (
fs.existsSync(path.join(src_dir, "package.json")) ||
fs.existsSync(path.join(src_dir, "rush.json"))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@joernio/astgen",
"version": "2.14.0",
"version": "2.15.0",
"description": "Generate JS/TS AST in json format with Babel",
"exports": "./index.js",
"keywords": [
Expand Down

0 comments on commit 571d836

Please sign in to comment.