Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes default sourceType of js extraction from 'script' to 'module'… #145

Merged
merged 3 commits into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ var Extractor = (function () {
attachComment: true,
loc: true,
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true,
Expand Down
30 changes: 30 additions & 0 deletions test/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});
7 changes: 7 additions & 0 deletions test/fixtures/es6-export.js
Original file line number Diff line number Diff line change
@@ -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!');
}
5 changes: 5 additions & 0 deletions test/fixtures/es6-import.js
Original file line number Diff line number Diff line change
@@ -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!');