diff --git a/packages/extractor-vue/src/__snapshots__/extractor.test.ts.snap b/packages/extractor-vue/src/__snapshots__/extractor.test.ts.snap index d1eb5290f..646453824 100644 --- a/packages/extractor-vue/src/__snapshots__/extractor.test.ts.snap +++ b/packages/extractor-vue/src/__snapshots__/extractor.test.ts.snap @@ -1,5 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`vue extractor should extract message from functional component 1`] = ` +[ + { + comment: undefined, + context: undefined, + id: Render function message, + message: undefined, + origin: [ + functional.vue, + 10, + 33, + ], + }, +] +`; + exports[`vue extractor should extract message from vue file 1`] = ` [ { diff --git a/packages/extractor-vue/src/extractor.test.ts b/packages/extractor-vue/src/extractor.test.ts index e724a758b..4a0a37323 100644 --- a/packages/extractor-vue/src/extractor.test.ts +++ b/packages/extractor-vue/src/extractor.test.ts @@ -61,4 +61,26 @@ describe("vue extractor", () => { expect(messages).toMatchSnapshot() }) + + it("should extract message from functional component", async () => { + const filePath = path.resolve(__dirname, "fixtures/functional.vue") + const code = fs.readFileSync(filePath, "utf-8") + + let messages: ExtractedMessage[] = [] + + await vueExtractor.extract( + "functional.vue", + code, + (res) => { + messages.push(res) + }, + { + linguiConfig, + } + ) + + messages = normalizePath(messages) + + expect(messages).toMatchSnapshot() + }) }) diff --git a/packages/extractor-vue/src/fixtures/functional.vue b/packages/extractor-vue/src/fixtures/functional.vue new file mode 100644 index 000000000..2a1b390a0 --- /dev/null +++ b/packages/extractor-vue/src/fixtures/functional.vue @@ -0,0 +1,12 @@ + diff --git a/packages/extractor-vue/src/vue-extractor.ts b/packages/extractor-vue/src/vue-extractor.ts index 479801a16..6bd9dd901 100644 --- a/packages/extractor-vue/src/vue-extractor.ts +++ b/packages/extractor-vue/src/vue-extractor.ts @@ -18,12 +18,14 @@ export const vueExtractor: ExtractorType = { ignoreEmpty: true, }) - const compiledTemplate = compileTemplate({ - source: descriptor.template.content, - filename, - inMap: descriptor.template.map, - id: filename, - }) + const compiledTemplate = + descriptor.template && + compileTemplate({ + source: descriptor.template.content, + filename, + inMap: descriptor.template.map, + id: filename, + }) const isTsBlock = (block: SFCBlock) => block?.lang === "ts"