File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -232,13 +232,13 @@ export default function ({ types: t }) {
232232 path . node . properties
233233 . filter ( ( { key } ) => copyProps . indexOf ( key . name ) !== - 1 )
234234 . forEach ( ( { key, value } , i ) => {
235- if ( key . name === "comment" && ! t . isStringLiteral ( value ) ) {
235+ if ( key . name === "comment" && ! ( t . isStringLiteral ( value ) || t . isTemplateLiteral ( value ) ) ) {
236236 throw path
237237 . get ( `properties.${ i } .value` )
238238 . buildCodeFrameError ( "Only strings are supported as comments." )
239239 }
240240
241- props [ key . name ] = value . value
241+ props [ key . name ] = value . value || t . isTemplateLiteral ( value ) && value . quasis [ 0 ] ?. value ?. cooked || ``
242242 } )
243243
244244 collectMessage ( path , file , props )
Original file line number Diff line number Diff line change @@ -16,6 +16,27 @@ Object {
1616
1717exports [` @lingui/babel-plugin-extract-messages should extract all messages from JS files (macros) 1` ] = `
1818Object {
19+ : Object {
20+ extractedComments: Array [],
21+ origin: Array [
22+ Array [
23+ js - with - macros .js ,
24+ 32 ,
25+ ],
26+ ],
27+ },
28+ Backtick : Object {
29+ extractedComments: Array [
30+ description for translators ,
31+ ],
32+ message: Message with backtick id ,
33+ origin: Array [
34+ Array [
35+ js - with - macros .js ,
36+ 24 ,
37+ ],
38+ ],
39+ },
1940 Description : Object {
2041 extractedComments: Array [
2142 description ,
Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ const withTId = t({
2121 message : "Message with id some"
2222} )
2323
24+ const withTIdBacktick = t ( {
25+ id : `Backtick` ,
26+ comment : `description for translators` ,
27+ message : `Message with backtick id`
28+ } )
29+
2430const id = 'message id'
2531
2632const withUnknownId = t ( {
Original file line number Diff line number Diff line change @@ -162,6 +162,21 @@ export default [
162162 });
163163 ` ,
164164 } ,
165+ {
166+ name : "Support id & comment in template literal" ,
167+ input : `
168+ import { t } from '@lingui/macro'
169+ const msg = t({ id: \`msgId\`, comment: \`description for translators\` })
170+ ` ,
171+ expected : `import { i18n } from "@lingui/core";
172+ const msg =
173+ i18n._(/*i18n*/
174+ {
175+ id: \`msgId\`,
176+ comment: \`description for translators\`
177+ });
178+ ` ,
179+ } ,
165180 {
166181 name : "Newlines after continuation character are removed" ,
167182 filename : "js-t-continuation-character.js" ,
You can’t perform that action at this time.
0 commit comments