Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion DENO_REBASE_LOG.md → DENO_LOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Deno Rebase Log
# Deno Log

### 2025.12.18 / @dsherret

- Added a `resolveJsxImportSource` method to the resolver for resolving the jsxImportSource based on the referrer.
- This doesn't support resolving for transforms because we don't use any transform code from TypeScript.

### 2025.12.16 / @nayeemrmn

Expand Down
21 changes: 21 additions & 0 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
CallbackGetAccessibleEntries
CallbackReadFile
CallbackRealpath
CallbackResolveJsxImportSource
CallbackResolveModuleName
CallbackResolveTypeReferenceDirective
CallbackGetPackageJsonScopeIfApplicable
Expand Down Expand Up @@ -257,6 +258,24 @@ func (r *resolverWrapper) GetPackageScopeForPath(directory string) *packagejson.
return r.inner.GetPackageScopeForPath(directory)
}

// ResolveJsxImportSource implements module.ResolverInterface.
func (r *resolverWrapper) ResolveJsxImportSource(referrerPath string) string {
if r.server.CallbackEnabled(CallbackResolveJsxImportSource) {
result, err := r.server.call("resolveJsxImportSource", referrerPath)
if err != nil {
panic(err)
}
if len(result) > 0 {
var res string
if err := json.Unmarshal(result, &res); err != nil {
panic(err)
}
return res
}
}
return r.inner.ResolveJsxImportSource(referrerPath)
}

// ResolveModuleName implements module.ResolverInterface.
func (r *resolverWrapper) ResolveModuleName(moduleName string, containingFile string, importAttributeType *string, resolutionMode core.ResolutionMode, redirectedReference module.ResolvedProjectReference) (*module.ResolvedModule, []module.DiagAndArgs) {
if r.server.CallbackEnabled(CallbackResolveModuleName) {
Expand Down Expand Up @@ -524,6 +543,8 @@ func (s *Server) enableCallback(callback string) error {
s.enabledCallbacks |= CallbackReadFile
case "realpath":
s.enabledCallbacks |= CallbackRealpath
case "resolveJsxImportSource":
s.enabledCallbacks |= CallbackResolveJsxImportSource
case "resolveModuleName":
s.enabledCallbacks |= CallbackResolveModuleName
case "resolveTypeReferenceDirective":
Expand Down
9 changes: 8 additions & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2657,12 +2657,19 @@ func IsRequireVariableStatement(node *Node) bool {
return false
}

func GetJSXImplicitImportBase(compilerOptions *core.CompilerOptions, file *SourceFile) string {
func GetJSXImplicitImportBase(compilerOptions *core.CompilerOptions, file *SourceFile, resolveJsxImportSource func(referrer string) string) string {
jsxImportSourcePragma := GetPragmaFromSourceFile(file, "jsximportsource")
jsxRuntimePragma := GetPragmaFromSourceFile(file, "jsxruntime")
if GetPragmaArgument(jsxRuntimePragma, "factory") == "classic" {
return ""
}
// deno: resolve the jsxImportSource based on the referrer
if file != nil && resolveJsxImportSource != nil {
resolvedJsxImportSource := resolveJsxImportSource(file.FileName())
if resolvedJsxImportSource != "" {
return resolvedJsxImportSource
}
}
if compilerOptions.Jsx == core.JsxEmitReactJSX ||
compilerOptions.Jsx == core.JsxEmitReactJSXDev ||
compilerOptions.JsxImportSource != "" ||
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
t.importHelpersImportSpecifier = specifier
}

jsxImport := ast.GetJSXRuntimeImport(ast.GetJSXImplicitImportBase(optionsForFile, file), optionsForFile)
jsxImport := ast.GetJSXRuntimeImport(ast.GetJSXImplicitImportBase(optionsForFile, file, p.resolver.ResolveJsxImportSource), optionsForFile)
if jsxImport != "" {
specifier := p.createSyntheticImport(jsxImport, file)
moduleNames = append(moduleNames, specifier)
Expand Down
5 changes: 5 additions & 0 deletions internal/module/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type ResolverInterface interface {
ResolveModuleName(moduleName string, containingFile string, importAttributeType *string, resolutionMode core.ResolutionMode, redirectedReference ResolvedProjectReference) (*ResolvedModule, []DiagAndArgs)
ResolvePackageDirectory(moduleName string, containingFile string, resolutionMode core.ResolutionMode, redirectedReference ResolvedProjectReference) *ResolvedModule
ResolveTypeReferenceDirective(typeReferenceDirectiveName string, containingFile string, resolutionMode core.ResolutionMode, redirectedReference ResolvedProjectReference) (*ResolvedTypeReferenceDirective, []DiagAndArgs)
ResolveJsxImportSource(referrer string) string
GetPackageScopeForPath(directory string) *packagejson.InfoCacheEntry
GetImpliedNodeFormatForFile(path string, packageJsonType string) core.ModuleKind
}
Expand Down Expand Up @@ -284,6 +285,10 @@ func (r *Resolver) GetImpliedNodeFormatForFile(path string, packageJsonType stri
return ast.GetImpliedNodeFormatForFile(path, packageJsonType)
}

func (r *Resolver) ResolveJsxImportSource(referrer string) string {
return ""
}

func (r *Resolver) tryResolveFromTypingsLocation(moduleName string, containingDirectory string, originalResult *ResolvedModule, traceBuilder *tracer) *ResolvedModule {
if r.typingsLocation == "" ||
tspath.IsExternalModuleNameRelative(moduleName) ||
Expand Down
2 changes: 1 addition & 1 deletion internal/transformers/jsxtransforms/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (tx *JSXTransformer) visitSourceFile(file *ast.SourceFile) *ast.Node {
}

tx.currentSourceFile = file
tx.importSpecifier = ast.GetJSXImplicitImportBase(tx.compilerOptions, file)
tx.importSpecifier = ast.GetJSXImplicitImportBase(tx.compilerOptions, file, nil)
tx.filenameDeclaration = nil
tx.utilizedImplicitRuntimeImports = make(map[string]map[string]*ast.Node)

Expand Down