From 2c383a10a25d9c960bd2f6330ea0a4ef0ca4f4fe Mon Sep 17 00:00:00 2001 From: Ivano Alvino Date: Tue, 7 Aug 2018 10:22:16 +0200 Subject: [PATCH 1/3] Fix ts extract support Since version 2.3.7 ts extract support is broken, reason beeing the ecmaFeatures jsx set to true also in case of ts extension. Added an if case to set this to false for ts, and leave it to true for jsx. --- lib/extract.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/extract.js b/lib/extract.js index bac4935..1c0234a 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -198,7 +198,16 @@ var Extractor = (function () { var syntax; var extension = filename.split('.').pop(); try { - if (extension === 'ts' || extension === 'tsx') { + if (extension === 'ts') { + syntax = tsParser.parse(src, { + sourceType: 'module', + comment: true, + ecmaFeatures: { + jsx: false + } + }); + } + else if (extension === 'tsx') { syntax = tsParser.parse(src, { sourceType: 'module', comment: true, From 288b58d33f6e8aaec1e08d55d4c0dde3c20b040e Mon Sep 17 00:00:00 2001 From: Ivano Alvino Date: Tue, 7 Aug 2018 10:35:23 +0200 Subject: [PATCH 2/3] Fix indentation and unify code styling --- lib/extract.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/extract.js b/lib/extract.js index 1c0234a..d66efec 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -199,15 +199,14 @@ var Extractor = (function () { var extension = filename.split('.').pop(); try { if (extension === 'ts') { - 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: false + } + }); + } else if (extension === 'tsx') { syntax = tsParser.parse(src, { sourceType: 'module', comment: true, From 0ab52fbca4a9f9739e4465b1595e49b340203a2a Mon Sep 17 00:00:00 2001 From: Ivano Alvino Date: Tue, 7 Aug 2018 11:09:41 +0200 Subject: [PATCH 3/3] Add unit tests for casted variables in ts In addition, refactor a bit in order to remove an if/else construct --- lib/extract.js | 12 ++---------- test/extract_extensions.js | 14 +++++++++----- test/fixtures/ts.ts | 1 + 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/extract.js b/lib/extract.js index d66efec..944eceb 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -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 { diff --git a/test/extract_extensions.js b/test/extract_extensions.js index e112572..0e49db5 100644 --- a/test/extract_extensions.js +++ b/test/extract_extensions.js @@ -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[0].msgid, 'Hello'); + assert.equal(catalog.items.length, 3); + assert.equal(catalog.items[0].msgid, 'Casted'); assert.equal(catalog.items[0].msgstr, ''); - assert.deepEqual(catalog.items[0].references, ['test/fixtures/ts.ts:2']); + assert.deepEqual(catalog.items[0].references, ['test/fixtures/ts.ts:6']); - assert.equal(catalog.items[1].msgid, 'One\nTwo\nThree'); + assert.equal(catalog.items[1].msgid, 'Hello'); assert.equal(catalog.items[1].msgstr, ''); - assert.deepEqual(catalog.items[1].references, ['test/fixtures/ts.ts:3']); + assert.deepEqual(catalog.items[1].references, ['test/fixtures/ts.ts:2']); + + assert.equal(catalog.items[2].msgid, 'One\nTwo\nThree'); + assert.equal(catalog.items[2].msgstr, ''); + assert.deepEqual(catalog.items[2].references, ['test/fixtures/ts.ts:3']); }); it('supports TypeScript .tsx files', function () { diff --git a/test/fixtures/ts.ts b/test/fixtures/ts.ts index 1a6d10a..ef46689 100644 --- a/test/fixtures/ts.ts +++ b/test/fixtures/ts.ts @@ -3,5 +3,6 @@ angular.module("myApp").controller("helloController", (gettext) => { var longString: string = gettext(`One Two Three`); + var castedVar: any = gettext("Casted"); gettext(); // Should be ignored. });