From 7241f979bfc4a37785b6165524792d872809053a Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 31 Mar 2023 12:40:48 +0200 Subject: [PATCH 1/9] feat: parse template tag for vue files --- src/lib/extract.ts | 13 +++++++++++++ tests/commands/__snapshots__/test_extract.ts.snap | 6 ++++++ tests/fixtures/vueTest/testVueParse.vue | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/extract.ts b/src/lib/extract.ts index 3c72676..49eabdb 100644 --- a/src/lib/extract.ts +++ b/src/lib/extract.ts @@ -38,6 +38,19 @@ export async function extractAll( switch (extname(filepath)) { case ".vue": { const source = fs.readFileSync(filepath).toString(); + const template = parseComponent(source).template; + if (template) { + const lineCount = + source.slice(0, template.start).split(/\r\n|\r|\n/) + .length - 1; + babel.transformSync( + "\n".repeat(lineCount) + template.content, + { + filename: filepath, + ...babelOptions + } + ); + } const script = parseComponent(source).script; if (script) { const lineCount = diff --git a/tests/commands/__snapshots__/test_extract.ts.snap b/tests/commands/__snapshots__/test_extract.ts.snap index 02c1cba..ab81528 100644 --- a/tests/commands/__snapshots__/test_extract.ts.snap +++ b/tests/commands/__snapshots__/test_extract.ts.snap @@ -161,6 +161,12 @@ msgstr \\"\\" \\"Content-Type: text/plain; charset=utf-8\\\\n\\" \\"Plural-Forms: nplurals=2; plural=(n!=1);\\\\n\\" +#: tests/fixtures/vueTest/testVueParse.vue:2 +msgid \\"test from vue file (template)\\" +msgstr \\"\\" +" +`; + #: tests/fixtures/vueTest/testVueParse.vue:10 msgid \\"test from vue file\\" msgstr \\"\\" diff --git a/tests/fixtures/vueTest/testVueParse.vue b/tests/fixtures/vueTest/testVueParse.vue index 5593cfc..3cdfb41 100644 --- a/tests/fixtures/vueTest/testVueParse.vue +++ b/tests/fixtures/vueTest/testVueParse.vue @@ -1,5 +1,5 @@