Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/babel-plugin-extract-messages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export default function ({ types: t }) {
.get(`properties.${i}.value`)
.buildCodeFrameError("Only strings are supported as comments.")
}

props[key.name] = value.value
const isIdLiteral = !value.value && key.name === "id" && t.isTemplateLiteral(value)
props[key.name] = isIdLiteral ? value?.quasis[0]?.value?.cooked : value.value
})

collectMessage(path, file, props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Object {

exports[`@lingui/babel-plugin-extract-messages should extract all messages from JS files (macros) 1`] = `
Object {
Backtick: Object {
extractedComments: Array [],
origin: Array [
Array [
js-with-macros.js,
24,
],
],
},
Description: Object {
extractedComments: Array [
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const withTId = t({
message: "Message with id some"
})

const withTIdBacktick = t({
id: `Backtick`
})

const id = 'message id'

const withUnknownId = t({
Expand Down
14 changes: 14 additions & 0 deletions packages/macro/test/js-t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ export default [
});
`,
},
{
name: "Support id in template literal",
input: `
import { t } from '@lingui/macro'
const msg = t({ id: \`msgId\` })
`,
expected: `import { i18n } from "@lingui/core";
const msg =
i18n._(/*i18n*/
{
id: \`msgId\`
});
`,
},
{
name: "Newlines after continuation character are removed",
filename: "js-t-continuation-character.js",
Expand Down