Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Improved TypeScript 3.7 Support #64

Open
arabold opened this issue Feb 9, 2020 · 1 comment
Open

Improved TypeScript 3.7 Support #64

arabold opened this issue Feb 9, 2020 · 1 comment

Comments

@arabold
Copy link

arabold commented Feb 9, 2020

I was running into an issue using TypeScript 3.7 with optional chaining and React Fragments using empty tags (<>...</>). In order to get both working properly the TypeScript preprocessor needs some minimal changes:

diff --git a/node_modules/i18n-tag-schema/dist/lib/preprocessors/typescript.js b/node_modules/i18n-tag-schema/dist/lib/preprocessors/typescript.js
index 0e5cd94..60923e3 100644
--- a/node_modules/i18n-tag-schema/dist/lib/preprocessors/typescript.js
+++ b/node_modules/i18n-tag-schema/dist/lib/preprocessors/typescript.js
@@ -15,8 +15,8 @@ exports.default = function (contents, filePath) {
   if (!ts) throw new Error('cannot find typescript compiler. check if \'typescript\' node module is installed.');
   var processed = ts.transpileModule(contents, {
     compilerOptions: {
-      target: ts.ScriptTarget.Latest,
-      jsx: path.extname(filePath) !== '.ts' ? ts.JsxEmit.Preserve : ts.JsxEmit.None
+      target: ts.ScriptTarget.ES2020,
+      jsx: path.extname(filePath) !== '.ts' ? ts.JsxEmit.React : ts.JsxEmit.None
     }
   });
   if (processed && processed.outputText) {

By setting ES2020 we force transpiling optional chaining syntax (such as foo?.bar and foo ?? bar). ts.JsxEmit.React is needed for proper fragment support.

@skolmer
Copy link
Owner

skolmer commented Feb 14, 2020

Thank you for your contribution!

I don't want to enable ES2020 for the default preprocessor because it is still a draft. But you could release your preprocessor as an npm package with more sophisticated features and configurations.
https://github.com/skolmer/i18n-tag-schema#-preprocessors
I could add a link to your npm package to the readme of this repository.

The preprocessor that comes out of the box is really just a basic implementation for starters and to show what's possible with this library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants