From 191b934daaf6e768cbd8dbd3a13cd49120824d12 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 2 Aug 2024 16:54:40 +0200 Subject: [PATCH] Fix `tsx` as input language flag --- lib/index.js | 6 +++++- test/fixtures/basic/input.html | 4 ++-- test/fixtures/basic/output.html | 26 ++++++++++++++------------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7e69142..9af585a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -44,6 +44,7 @@ const defaultGrammars = [sourceJson, sourceJs, sourceTsx, sourceTs] const extensionToScopeMap = new Map([ ['json', 'source.json'], ['js', 'source.js'], + ['tsx', 'source.tsx'], ['ts', 'source.ts'] ]) @@ -186,7 +187,10 @@ export default function rehypeTwoslash(options) { let annotations = [] try { - const result = twoslash(value, scope === 'source.js' ? 'js' : 'ts') + const result = twoslash( + value, + scope === 'source.js' ? 'js' : scope === 'source.tsx' ? 'tsx' : 'ts' + ) value = result.code annotations = result.nodes scope = extensionToScopeMap.get(result.meta.extension) diff --git a/test/fixtures/basic/input.html b/test/fixtures/basic/input.html index 173b34d..d6f661d 100644 --- a/test/fixtures/basic/input.html +++ b/test/fixtures/basic/input.html @@ -32,9 +32,9 @@
let fragment = <jsx />
 
-
// @errors: 2304 1005 1161
+
// @errors: 1005 1161 2304
 let fragment = <jsx />
 
-
// @errors: 2304 1005 1161
+
// @errors: 1005 1161 2304 7026
 let fragment = <jsx />
 
diff --git a/test/fixtures/basic/output.html b/test/fixtures/basic/output.html index 08cea74..d6b637f 100644 --- a/test/fixtures/basic/output.html +++ b/test/fixtures/basic/output.html @@ -78,18 +78,20 @@
any
-
let fragment = <jsx />
+
let fragment = <jsx />
 
-
let fragment: jsx
-
Cannot find name 'jsx'. (2304)
-
type jsx = /*unresolved*/ any
-
'>' expected. (1005)
+
let fragment: jsx
+
Cannot find name 'jsx'. (2304)
+
type jsx = /*unresolved*/ any
+
'>' expected. (1005)
-
-
let fragment = <jsx />
-
-
let fragment: jsx
-
Cannot find name 'jsx'. (2304)
-
type jsx = /*unresolved*/ any
-
'>' expected. (1005)
+
+
let fragment = <jsx />
+
+
let fragment: any
+
JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. (7026)
+
JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. (7026)
+
JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. (7026)
+
Cannot find name 'React'. (2304)
+
any