Skip to content

Commit

Permalink
Add unit tests for casted variables in ts
Browse files Browse the repository at this point in the history
In addition, refactor a bit in order to remove an if/else construct
  • Loading branch information
IvanoAlvino committed Aug 7, 2018
1 parent 288b58d commit d5b2388
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
12 changes: 2 additions & 10 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,12 @@ var Extractor = (function () {
var syntax;
var extension = filename.split('.').pop();
try {
if (extension === 'ts') {
if (extension === 'ts' || extension === 'tsx') {
syntax = tsParser.parse(src, {
sourceType: 'module',
comment: true,
ecmaFeatures: {
jsx: false
}
});
} else if (extension === 'tsx') {
syntax = tsParser.parse(src, {
sourceType: 'module',
comment: true,
ecmaFeatures: {
jsx: true
jsx: extension === 'tsx'
}
});
} else {
Expand Down
6 changes: 5 additions & 1 deletion test/extract_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ describe('Extracting files with different extensions', function () {
];
var catalog = testExtract(files);

assert.equal(catalog.items.length, 2);
assert.equal(catalog.items.length, 3);
assert.equal(catalog.items[0].msgid, 'Hello');
assert.equal(catalog.items[0].msgstr, '');
assert.deepEqual(catalog.items[0].references, ['test/fixtures/ts.ts:2']);

assert.equal(catalog.items[1].msgid, 'One\nTwo\nThree');
assert.equal(catalog.items[1].msgstr, '');
assert.deepEqual(catalog.items[1].references, ['test/fixtures/ts.ts:3']);

assert.equal(catalog.items[2].msgid, 'Casted');
assert.equal(catalog.items[2].msgstr, '');
assert.deepEqual(catalog.items[2].references, ['test/fixtures/ts.ts:6']);
});

it('supports TypeScript .tsx files', function () {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ angular.module("myApp").controller("helloController", (gettext) => {
var longString: string = gettext(`One
Two
Three`);
var castedVar: any = <any> gettext("Casted");
gettext(); // Should be ignored.
});

0 comments on commit d5b2388

Please sign in to comment.