diff --git a/lib/extract.js b/lib/extract.js index dd8fdca..3513cb2 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -172,6 +172,7 @@ var Extractor = (function () { attachComment: true, loc: true, ecmaVersion: 6, + sourceType: 'module', ecmaFeatures: { jsx: true, experimentalObjectRestSpread: true, diff --git a/test/extract.js b/test/extract.js index bd90414..00d36a4 100644 --- a/test/extract.js +++ b/test/extract.js @@ -404,4 +404,34 @@ describe('Extract', function () { assert.equal(catalog.items[1].msgid, 'Hello!'); assert.equal(catalog.items[1].msgstr, ''); }); + + it('Extracts strings from an ES6 export', function () { + var files = [ + 'test/fixtures/es6-export.js' + ]; + var catalog = testExtract(files); + + assert.equal(catalog.items.length, 2); + + assert.equal(catalog.items[0].msgid, 'Hi from an ES6 export default!'); + assert.equal(catalog.items[0].msgstr, ''); + assert.deepEqual(catalog.items[0].references, ['test/fixtures/es6-export.js:6']); + + assert.equal(catalog.items[1].msgid, 'Hi from an ES6 export!'); + assert.equal(catalog.items[1].msgstr, ''); + assert.deepEqual(catalog.items[1].references, ['test/fixtures/es6-export.js:2']); + }); + + it('Extracts strings from an ES6 import', function () { + var files = [ + 'test/fixtures/es6-import.js' + ]; + var catalog = testExtract(files); + + assert.equal(catalog.items.length, 1); + + assert.equal(catalog.items[0].msgid, 'Hi from ES6 file with import!'); + assert.equal(catalog.items[0].msgstr, ''); + assert.deepEqual(catalog.items[0].references, ['test/fixtures/es6-import.js:5']); + }); }); diff --git a/test/fixtures/es6-export.js b/test/fixtures/es6-export.js new file mode 100644 index 0000000..ab1c0a2 --- /dev/null +++ b/test/fixtures/es6-export.js @@ -0,0 +1,7 @@ +export function exportTest() { + return gettext('Hi from an ES6 export!') +} + +export default function exportTestDefault() { + return gettext('Hi from an ES6 export default!'); +} diff --git a/test/fixtures/es6-import.js b/test/fixtures/es6-import.js new file mode 100644 index 0000000..f9e6b64 --- /dev/null +++ b/test/fixtures/es6-import.js @@ -0,0 +1,5 @@ +import exportTestDefault, { exportTest } from './es6-export'; + +const fromDefaultExport = exportTestDefault(); // should be ignored +const fromExport = exportTest(); // should be ignored +gettext('Hi from ES6 file with import!');