From 0bf87d92865cfa1c312b3b461f8f94713c68d477 Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Mon, 15 Oct 2018 15:08:55 +0300 Subject: [PATCH 1/2] [Tools] Fix pug regular expression --- src/dev/i18n/extractors/pug.js | 2 +- src/dev/i18n/extractors/pug.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dev/i18n/extractors/pug.js b/src/dev/i18n/extractors/pug.js index 61b4ba0ca866c..0f964f308403d 100644 --- a/src/dev/i18n/extractors/pug.js +++ b/src/dev/i18n/extractors/pug.js @@ -26,7 +26,7 @@ import { createFailError } from '../../run'; /** * Matches `i18n(...)` in `#{i18n('id', { defaultMessage: 'Message text' })}` */ -const PUG_I18N_REGEX = /(?<=\#\{)i18n\((([^)']|'([^'\\]|\\.)*')*\)(?=\}))/g; +const PUG_I18N_REGEX = /i18n\((([^)']|'([^'\\]|\\.)*')*)\)/g; /** * Example: `#{i18n('message-id', { defaultMessage: 'Message text' })}` diff --git a/src/dev/i18n/extractors/pug.test.js b/src/dev/i18n/extractors/pug.test.js index 7f901d1d992db..19afcd4191d4e 100644 --- a/src/dev/i18n/extractors/pug.test.js +++ b/src/dev/i18n/extractors/pug.test.js @@ -31,7 +31,7 @@ describe('dev/i18n/extractors/pug', () => { test('throws on empty id', () => { const source = Buffer.from(`\ -#{i18n('', { defaultMessage: 'Default message', context: 'Message context' })} +h1= i18n('', { defaultMessage: 'Default message', context: 'Message context' }) `); expect(() => extractPugMessages(source).next()).toThrowErrorMatchingSnapshot(); From bb343adc8c656cc83e3acd0305bfaf74a0f7dbbf Mon Sep 17 00:00:00 2001 From: Leanid Shutau Date: Tue, 16 Oct 2018 17:40:54 +0300 Subject: [PATCH 2/2] Add one more test --- .../i18n/extractors/__snapshots__/pug.test.js.snap | 12 +++++++++++- src/dev/i18n/extractors/pug.test.js | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap b/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap index c95fb0d149cd0..f8d0f45db63b5 100644 --- a/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap +++ b/src/dev/i18n/extractors/__snapshots__/pug.test.js.snap @@ -1,6 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`dev/i18n/extractors/pug extracts messages from pug template 1`] = ` +exports[`dev/i18n/extractors/pug extracts messages from pug template with interpolation 1`] = ` +Array [ + "message-id", + Object { + "context": "Message context", + "message": "Default message", + }, +] +`; + +exports[`dev/i18n/extractors/pug extracts messages from pug template without interpolation 1`] = ` Array [ "message-id", Object { diff --git a/src/dev/i18n/extractors/pug.test.js b/src/dev/i18n/extractors/pug.test.js index 19afcd4191d4e..3bfa2a14fa7e0 100644 --- a/src/dev/i18n/extractors/pug.test.js +++ b/src/dev/i18n/extractors/pug.test.js @@ -20,7 +20,7 @@ import { extractPugMessages } from './pug'; describe('dev/i18n/extractors/pug', () => { - test('extracts messages from pug template', () => { + test('extracts messages from pug template with interpolation', () => { const source = Buffer.from(`\ #{i18n('message-id', { defaultMessage: 'Default message', context: 'Message context' })} `); @@ -29,6 +29,15 @@ describe('dev/i18n/extractors/pug', () => { expect(messageObject).toMatchSnapshot(); }); + test('extracts messages from pug template without interpolation', () => { + const source = Buffer.from(`\ +.kibanaWelcomeText(data-error-message=i18n('message-id', { defaultMessage: 'Default message', context: 'Message context' })) +`); + const [messageObject] = extractPugMessages(source); + + expect(messageObject).toMatchSnapshot(); + }); + test('throws on empty id', () => { const source = Buffer.from(`\ h1= i18n('', { defaultMessage: 'Default message', context: 'Message context' })