Skip to content

Commit 1b414f4

Browse files
Copilotjakebailey
andcommitted
Fix jsx-runtime imports being treated as unsafe in declaration emit
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent 3f43d34 commit 1b414f4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

internal/checker/nodebuilderimpl.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ import (
1818
"github.com/microsoft/typescript-go/internal/tspath"
1919
)
2020

21+
// isJSXRuntimeImport checks if a specifier is a safe JSX runtime import
22+
// JSX runtime imports (jsx-runtime and jsx-dev-runtime) are considered safe
23+
// as they are standard React APIs that should be allowed in declaration files
24+
func isJSXRuntimeImport(specifier string) bool {
25+
return strings.Contains(specifier, "/jsx-runtime") ||
26+
strings.Contains(specifier, "/jsx-dev-runtime") ||
27+
strings.Contains(specifier, "@types/react/jsx-runtime") ||
28+
strings.Contains(specifier, "react/jsx-runtime")
29+
}
30+
2131
type CompositeSymbolIdentity struct {
2232
isConstructorNode bool
2333
symbolId ast.SymbolId
@@ -433,7 +443,7 @@ func (b *nodeBuilderImpl) symbolToTypeNode(symbol *ast.Symbol, mask ast.SymbolFl
433443
if len(specifier) == 0 {
434444
specifier = b.getSpecifierForModuleSymbol(chain[0], core.ResolutionModeNone)
435445
}
436-
if (b.ctx.flags&nodebuilder.FlagsAllowNodeModulesRelativePaths == 0) /* && b.ch.compilerOptions.GetModuleResolutionKind() != core.ModuleResolutionKindClassic */ && strings.Contains(specifier, "/node_modules/") {
446+
if (b.ctx.flags&nodebuilder.FlagsAllowNodeModulesRelativePaths == 0) /* && b.ch.compilerOptions.GetModuleResolutionKind() != core.ModuleResolutionKindClassic */ && strings.Contains(specifier, "/node_modules/") && !isJSXRuntimeImport(specifier) {
437447
oldSpecifier := specifier
438448

439449
if b.ch.compilerOptions.GetModuleResolutionKind() == core.ModuleResolutionKindNode16 || b.ch.compilerOptions.GetModuleResolutionKind() == core.ModuleResolutionKindNodeNext {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test case to reproduce jsx-runtime declaration emit issue
2+
3+
// @jsx: react-jsx
4+
// @declaration: true
5+
// @emitDeclarationOnly: true
6+
// @strict: true
7+
// @target: esnext
8+
// @module: esnext
9+
10+
// This should trigger the jsx-runtime import without type annotation error
11+
12+
export const FunctionComponent = () => {
13+
return <div>Hello World</div>
14+
}
15+
16+
export const AnotherComponent = () => {
17+
return <FunctionComponent />
18+
}

0 commit comments

Comments
 (0)