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
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function extractMessagesForDefineMessages(
const name = ip.name.text;
if (
ts.isPropertyAssignment(ip) &&
ts.isStringLiteral(ip.initializer)
(ts.isStringLiteral(ip.initializer) ||
ts.isNoSubstitutionTemplateLiteral(ip.initializer))
) {
copyIfMessageKey(msg, name, ip.initializer.text);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/app/defineMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const lang = defineMessages({
"defaultMessage": "Hello",
"description": "A description for title"
},
multiLineLiteral: {
id: 'hello.world',
defaultMessage: `Hello, {scope, plural,
=person {human}
=planet {world}
other {thing}
}!`
}
})

// NB not a variable declaration; should be ignored
Expand Down
8 changes: 6 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("<FormattedMessage/>", (t) => {
var content = fs.readFileSync(__dirname + "/app/index.tsx");

var res = p(content.toString());
console.log(res);

var expected = [
{
id: "app",
Expand Down Expand Up @@ -61,9 +61,13 @@ test("defineMessages() should only work with variable declaration", (t) => {
defaultMessage: "Hello",
description: "A description for title",
},
{
id: "hello.world",
defaultMessage: "Hello, {scope, plural,\n =person {human}\n =planet {world}\n other {thing}\n }!",
}
];

t.is(res.length, 2);
t.is(res.length, 3);

t.deepEqual(res, expected);
});
Expand Down