Skip to content

Save off another closure in emitResolver #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30574,7 +30574,7 @@ func (c *Checker) GetTypeAtLocation(node *ast.Node) *Type {

func (c *Checker) GetEmitResolver(file *ast.SourceFile) *emitResolver {
c.emitResolverOnce.Do(func() {
c.emitResolver = &emitResolver{checker: c}
c.emitResolver = newEmitResolver(c)
})

return c.emitResolver
Expand Down
15 changes: 10 additions & 5 deletions internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/microsoft/typescript-go/internal/printer"
)

var _ printer.EmitResolver = &emitResolver{}
var _ printer.EmitResolver = (*emitResolver)(nil)

// Links for jsx
type JSXLinks struct {
Expand All @@ -35,12 +35,20 @@ type emitResolver struct {
checker *Checker
checkerMu sync.Mutex
isValueAliasDeclaration func(node *ast.Node) bool
aliasMarkingVisitor func(node *ast.Node) bool
referenceResolver binder.ReferenceResolver
jsxLinks core.LinkStore[*ast.Node, JSXLinks]
declarationLinks core.LinkStore[*ast.Node, DeclarationLinks]
declarationFileLinks core.LinkStore[*ast.Node, DeclarationFileLinks]
}

func newEmitResolver(checker *Checker) *emitResolver {
e := &emitResolver{checker: checker}
e.isValueAliasDeclaration = e.isValueAliasDeclarationWorker
e.aliasMarkingVisitor = e.aliasMarkingVisitorWorker
return e
}

func (r *emitResolver) GetJsxFactoryEntity(location *ast.Node) *ast.Node {
r.checkerMu.Lock()
defer r.checkerMu.Unlock()
Expand Down Expand Up @@ -227,7 +235,7 @@ func (r *emitResolver) PrecalculateDeclarationEmitVisibility(file *ast.SourceFil
file.AsNode().ForEachChild(r.aliasMarkingVisitor)
}

func (r *emitResolver) aliasMarkingVisitor(node *ast.Node) bool {
func (r *emitResolver) aliasMarkingVisitorWorker(node *ast.Node) bool {
switch node.Kind {
case ast.KindExportAssignment, ast.KindJSExportAssignment:
if node.AsExportAssignment().Expression.Kind == ast.KindIdentifier {
Expand Down Expand Up @@ -670,9 +678,6 @@ func (r *emitResolver) isValueAliasDeclarationWorker(node *ast.Node) bool {
return symbol != nil && r.isAliasResolvedToValue(symbol, true /*excludeTypeOnlyValues*/)
case ast.KindExportDeclaration:
exportClause := node.AsExportDeclaration().ExportClause
if r.isValueAliasDeclaration == nil {
r.isValueAliasDeclaration = r.isValueAliasDeclarationWorker
}
return exportClause != nil && (ast.IsNamespaceExport(exportClause) ||
core.Some(exportClause.AsNamedExports().Elements.Nodes, r.isValueAliasDeclaration))
case ast.KindExportAssignment, ast.KindJSExportAssignment:
Expand Down