From 2cb3734db695e1250bc031cb77f0abc2e94d0e2d Mon Sep 17 00:00:00 2001 From: Maxim Zemskov Date: Thu, 18 Oct 2018 19:30:20 +0500 Subject: [PATCH] fix: allow leading space in i18n description comments (#366) --- .../src/index.js | 2 +- .../test/__snapshots__/index.js.snap | 34 +++++++++++++++++-- .../test/fixtures/js/macro.js | 15 ++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-extract-messages/src/index.js b/packages/babel-plugin-extract-messages/src/index.js index 0bbcad9b7..ad0362be2 100644 --- a/packages/babel-plugin-extract-messages/src/index.js +++ b/packages/babel-plugin-extract-messages/src/index.js @@ -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)) { diff --git a/packages/babel-plugin-extract-messages/test/__snapshots__/index.js.snap b/packages/babel-plugin-extract-messages/test/__snapshots__/index.js.snap index 272197833..d1f4deb68 100644 --- a/packages/babel-plugin-extract-messages/test/__snapshots__/index.js.snap +++ b/packages/babel-plugin-extract-messages/test/__snapshots__/index.js.snap @@ -49,7 +49,35 @@ 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, ], ], }, @@ -57,7 +85,7 @@ Object { origin: Array [ Array [ packages/babel-plugin-extract-messages/test/fixtures/js/macro.js, - 14, + 29, ], ], }, @@ -66,7 +94,7 @@ Object { origin: Array [ Array [ packages/babel-plugin-extract-messages/test/fixtures/js/macro.js, - 9, + 24, ], ], }, diff --git a/packages/babel-plugin-extract-messages/test/fixtures/js/macro.js b/packages/babel-plugin-extract-messages/test/fixtures/js/macro.js index ff8da9890..a805b8e7b 100644 --- a/packages/babel-plugin-extract-messages/test/fixtures/js/macro.js +++ b/packages/babel-plugin-extract-messages/test/fixtures/js/macro.js @@ -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'