Skip to content

Commit

Permalink
fix: allow leading space in i18n description comments (lingui#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodge authored and Photonios committed Dec 9, 2019
1 parent 7fd8358 commit 2cb3734
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-extract-messages/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default function({ types: t }) {
const comment =
path.node.leadingComments &&
path.node.leadingComments.filter(node =>
node.value.startsWith("i18n")
node.value.match(/^\s*i18n/)
)[0]

if (!comment || visited.has(path.node)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,43 @@ Object {
],
Array [
packages/babel-plugin-extract-messages/test/fixtures/js/macro.js,
21,
36,
],
],
},
Message With Description Multiline: Object {
description: description
multiline,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js/macro.js,
20,
],
],
},
Message With Description No Colon: Object {
description: description,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js/macro.js,
13,
],
],
},
Message With Description Spaced: Object {
description: description,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js/macro.js,
9,
],
],
},
Message With {param}: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js/macro.js,
14,
29,
],
],
},
Expand All @@ -66,7 +94,7 @@ Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js/macro.js,
9,
24,
],
],
},
Expand Down
15 changes: 15 additions & 0 deletions packages/babel-plugin-extract-messages/test/fixtures/js/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ const withDescription = /*i18n: description*/{
id: 'Message With Description'
}

const withDescriptionSpaced = /* i18n: description */{
id: 'Message With Description Spaced'
}

const withDescriptionNoColon = /*i18n description */{
id: 'Message With Description No Colon'
}

const withDescriptionMultiline = /*i18n
description
multiline
*/{
id: 'Message With Description Multiline'
}

const withId = /*i18n*/{
id: 'msg.id',
defaults: 'Message With Description'
Expand Down

0 comments on commit 2cb3734

Please sign in to comment.