Skip to content

Commit aa21c44

Browse files
fix(native-tools): extract in projects with jsxRuntime "vue" (#291)
1 parent 4dc83f9 commit aa21c44

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎packages/native-tools/__test__/index.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ describe('createSwcExtractor', () => {
192192
expect(await extract(extractor, linguiConfig)).toEqual(['From custom package'])
193193
})
194194

195+
test('extracts with a jsxRuntime the native macro does not implement', async () => {
196+
// `@lingui/vue/config` sets `jsxRuntime: "vue"`
197+
const linguiConfig = makeConfig(
198+
{locales: ['en'], macro: {jsxRuntime: 'vue'} as LinguiConfigNormalized['macro']},
199+
{skipValidation: true},
200+
)
201+
202+
expect(await extract(createSwcExtractor(), linguiConfig)).toEqual(['From default package'])
203+
})
204+
195205
describe('source maps', () => {
196206
const linguiConfig = makeConfig({locales: ['en']}, {skipValidation: true})
197207

‎packages/native-tools/src-js/index.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ export function createSwcExtractor(options: ExtractorOptions = {}): ExtractorTyp
189189
code += `\n//# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(ctx.sourceMaps)).toString('base64')}`
190190
}
191191

192-
const {messages} = await extractMessages(code, filename, {
193-
...options,
194-
macro: mapOptions(ctx.linguiConfig, options.macro),
195-
})
192+
// `jsxRuntime` doesn't affect extracted messages, and the native side rejects values it doesn't know, e.g. "vue".
193+
const {jsxRuntime: _jsxRuntime, ...macro} = mapOptions(ctx.linguiConfig, options.macro)
194+
195+
const {messages} = await extractMessages(code, filename, {...options, macro})
196196

197197
messages.forEach((msg) => {
198198
onMessageExtracted(mapMessage(msg))

0 commit comments

Comments
 (0)