From bf0c5a1af5afeb96b0b365df0de7e41d285140b9 Mon Sep 17 00:00:00 2001 From: Anton Shchekota Date: Thu, 22 Apr 2021 12:19:39 +0300 Subject: [PATCH] fix: jsx should be included for tsx files but not for ts fixed #1359 ts has conflict syntax with casting type. It is valid TS but not valid TSX --- src/input/dependency.js | 2 +- src/parsers/parse_to_ast.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/input/dependency.js b/src/input/dependency.js index b298ab65d..a2ee9d01e 100644 --- a/src/input/dependency.js +++ b/src/input/dependency.js @@ -8,7 +8,7 @@ const smartGlob = require('../smart_glob.js'); const STANDARD_BABEL_CONFIG = { compact: false, - parserOpts: { plugins: [...standardBabelParserPlugins, 'flow'] } + parserOpts: { plugins: [...standardBabelParserPlugins, 'flow', 'jsx'] } }; /** diff --git a/src/parsers/parse_to_ast.js b/src/parsers/parse_to_ast.js index 9bdbb1c27..9f5673d78 100644 --- a/src/parsers/parse_to_ast.js +++ b/src/parsers/parse_to_ast.js @@ -2,8 +2,8 @@ const babelParser = require('@babel/parser'); const path = require('path'); const TYPESCRIPT_EXTS = { - '.ts': true, - '.tsx': true + '.ts': ['typescript'], + '.tsx': ['typescript', 'jsx'] }; const standardBabelParserPlugins = [ @@ -14,7 +14,6 @@ const standardBabelParserPlugins = [ 'exportDefaultFrom', 'exportExtensions', 'functionBind', - 'jsx', 'partialApplication', ['pipelineOperator', { proposal: 'minimal' }], 'throwExpressions' @@ -29,7 +28,7 @@ function getParserOpts(file) { plugins: [ ...standardBabelParserPlugins, ['decorators', { decoratorsBeforeExport: false }], - TYPESCRIPT_EXTS[path.extname(file || '')] ? 'typescript' : 'flow' + ...(TYPESCRIPT_EXTS[path.extname(file || '')] || ['flow', 'jsx']) ] }; }