From f3437aaa6f13a6dedb51ca00ab223dd8fa586d56 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Wed, 31 May 2017 11:04:06 +0200 Subject: [PATCH] Enable dynamicImport plugin in babylon (#27) Currently i18n-extract crashes on files which use dynamic import statements. This can be fixed by activating the corresponding babylon plugin. --- src/extractFromCode.js | 1 + src/extractFromCode.spec.js | 8 ++++++++ src/extractFromCodeFixtures/dynamicImport.js | 7 +++++++ 3 files changed, 16 insertions(+) create mode 100644 src/extractFromCodeFixtures/dynamicImport.js diff --git a/src/extractFromCode.js b/src/extractFromCode.js index 58172d7..87496a7 100644 --- a/src/extractFromCode.js +++ b/src/extractFromCode.js @@ -52,6 +52,7 @@ export default function extractFromCode(code, options = {}) { 'asyncGenerators', 'functionBind', 'functionSent', + 'dynamicImport', ], }); diff --git a/src/extractFromCode.spec.js b/src/extractFromCode.spec.js index f83a880..bb6166c 100644 --- a/src/extractFromCode.spec.js +++ b/src/extractFromCode.spec.js @@ -93,6 +93,14 @@ describe('#extractFromCode()', () => { '*', ], keys, 'Should return one key.'); }); + + it('should return the right key with dynamic import in code', () => { + const keys = extractFromCode(getCode('dynamicImport.js')); + + assert.deepEqual([ + 'key', + ], keys, 'Should return only one key.'); + }); }); describe('dynamic keys', () => { diff --git a/src/extractFromCodeFixtures/dynamicImport.js b/src/extractFromCodeFixtures/dynamicImport.js new file mode 100644 index 0000000..b6ce826 --- /dev/null +++ b/src/extractFromCodeFixtures/dynamicImport.js @@ -0,0 +1,7 @@ +/* eslint-disable */ + +import i18n from 'i18n'; + +import('other/file'); + +i18n(`key`);