Skip to content

Commit

Permalink
Fixed Vue.js parsing for open img tags
Browse files Browse the repository at this point in the history
  • Loading branch information
max-leuthaeuser committed Dec 7, 2023
1 parent 4caf141 commit 608059a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const vueTemplateRegex = /(<template.*>)([\s\S]*)(<\/template>)/ig;
const vueCommentRegex = /<\!--[\s\S]*?-->/ig;
const vueBindRegex = /(:\[)([\S]*?)(\])/ig;
const vuePropRegex = /\s([.:@])([\S]*?=)/ig;
const vueOpenImgTag = /(<img)((?!>)[\s\S]+?)( [^\/]>)/ig;

/**
* Convert a single vue file to AST
Expand All @@ -200,7 +201,10 @@ const toVueAst = (file) => {
.replace(vueTemplateRegex, function (match, grA, grB, grC) {
return grA +
grB.replace(vuePropRegex, function (match, grA, grB) {
return " " + grA.replace(/[.:@]/g, " ") + grB.replaceAll(".", "-")
return " " + grA.replace(/[.:@]/g, " ") + grB.replaceAll(".", "-")
})
.replace(vueOpenImgTag, function (match, grA, grB, grC) {
return grA + grB + grC.replace(" >", "/>")
})
.replaceAll("{{", "{ ")
.replaceAll("}}", " }") +
Expand Down Expand Up @@ -327,7 +331,7 @@ const createJSAst = async (options) => {
* Generate AST for .vue files
*/
const createVueAst = async (options) => {
const srcFiles = getAllFiles(options.src, ".vue");
const srcFiles = await getAllFiles(options.src, ".vue");
for (const file of srcFiles) {
try {
const ast = toVueAst(file);
Expand Down

0 comments on commit 608059a

Please sign in to comment.