Skip to content

Commit 28fe3d4

Browse files
authored
Fix a few symbol printing / node builder bugs (#1588)
1 parent fc59d1a commit 28fe3d4

File tree

13,368 files changed

+81458
-475434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

13,368 files changed

+81458
-475434
lines changed

internal/checker/checker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14497,7 +14497,9 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
1449714497
if ancestor == nil {
1449814498
ancestor = ast.FindAncestor(location, ast.IsImportEqualsDeclaration)
1449914499
if ancestor != nil {
14500-
contextSpecifier = ancestor.AsImportEqualsDeclaration().ModuleReference.AsExternalModuleReference().Expression
14500+
if moduleRefrence := ancestor.AsImportEqualsDeclaration().ModuleReference; moduleRefrence.Kind == ast.KindExternalModuleReference {
14501+
contextSpecifier = moduleRefrence.AsExternalModuleReference().Expression
14502+
}
1450114503
}
1450214504
}
1450314505
}

internal/checker/nodebuilder.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
type NodeBuilder struct {
10-
ctxStack []*NodeBuilderContext
11-
host Host
12-
impl *nodeBuilderImpl
10+
ctxStack []*NodeBuilderContext
11+
basicHost Host
12+
impl *nodeBuilderImpl
1313
}
1414

1515
// EmitContext implements NodeBuilderInterface.
@@ -32,10 +32,15 @@ func (b *NodeBuilder) enterContext(enclosingDeclaration *ast.Node, flags nodebui
3232
enclosingSymbolTypes: make(map[ast.SymbolId]*Type),
3333
remappedSymbolReferences: make(map[ast.SymbolId]*ast.Symbol),
3434
}
35-
if tracker == nil {
36-
tracker = NewSymbolTrackerImpl(b.impl.ctx, nil, b.host)
37-
b.impl.ctx.tracker = tracker
35+
// TODO: always provide this; see https://github.com/microsoft/typescript-go/pull/1588#pullrequestreview-3125218673
36+
var moduleResolverHost Host
37+
if tracker != nil {
38+
moduleResolverHost = tracker.GetModuleSpecifierGenerationHost()
39+
} else if internalFlags&nodebuilder.InternalFlagsDoNotIncludeSymbolChain != 0 {
40+
moduleResolverHost = b.basicHost
3841
}
42+
tracker = NewSymbolTrackerImpl(b.impl.ctx, tracker, moduleResolverHost)
43+
b.impl.ctx.tracker = tracker
3944
}
4045

4146
func (b *NodeBuilder) popContext() {
@@ -173,7 +178,7 @@ func (b *NodeBuilder) TypeToTypeNode(typ *Type, enclosingDeclaration *ast.Node,
173178

174179
func NewNodeBuilder(ch *Checker, e *printer.EmitContext) *NodeBuilder {
175180
impl := newNodeBuilderImpl(ch, e)
176-
return &NodeBuilder{impl: impl, ctxStack: make([]*NodeBuilderContext, 0, 1), host: ch.program}
181+
return &NodeBuilder{impl: impl, ctxStack: make([]*NodeBuilderContext, 0, 1), basicHost: ch.program}
177182
}
178183

179184
func (c *Checker) getNodeBuilder() *NodeBuilder {

internal/checker/nodebuilderimpl.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ func (b *nodeBuilderImpl) symbolToNode(symbol *ast.Symbol, meaning ast.SymbolFla
450450
if name != nil && ast.IsComputedPropertyName(name) {
451451
return name
452452
}
453-
if b.ch.valueSymbolLinks.Has(symbol) {
454-
nameType := b.ch.valueSymbolLinks.Get(symbol).nameType
455-
if nameType != nil && nameType.flags&(TypeFlagsEnumLiteral|TypeFlagsUniqueESSymbol) != 0 {
456-
oldEnclosing := b.ctx.enclosingDeclaration
457-
b.ctx.enclosingDeclaration = nameType.symbol.ValueDeclaration
458-
result := b.f.NewComputedPropertyName(b.symbolToExpression(nameType.symbol, meaning))
459-
b.ctx.enclosingDeclaration = oldEnclosing
460-
return result
461-
}
453+
}
454+
if b.ch.valueSymbolLinks.Has(symbol) {
455+
nameType := b.ch.valueSymbolLinks.Get(symbol).nameType
456+
if nameType != nil && nameType.flags&(TypeFlagsEnumLiteral|TypeFlagsUniqueESSymbol) != 0 {
457+
oldEnclosing := b.ctx.enclosingDeclaration
458+
b.ctx.enclosingDeclaration = nameType.symbol.ValueDeclaration
459+
result := b.f.NewComputedPropertyName(b.symbolToExpression(nameType.symbol, meaning))
460+
b.ctx.enclosingDeclaration = oldEnclosing
461+
return result
462462
}
463463
}
464464
}
@@ -972,7 +972,7 @@ type sortedSymbolNamePair struct {
972972
func (b *nodeBuilderImpl) getSymbolChain(symbol *ast.Symbol, meaning ast.SymbolFlags, endOfChain bool, yieldModuleSymbol bool) []*ast.Symbol {
973973
accessibleSymbolChain := b.ch.getAccessibleSymbolChain(symbol, b.ctx.enclosingDeclaration, meaning, b.ctx.flags&nodebuilder.FlagsUseOnlyExternalAliasing != 0)
974974
qualifierMeaning := meaning
975-
if len(accessibleSymbolChain) > 0 {
975+
if len(accessibleSymbolChain) > 1 {
976976
qualifierMeaning = getQualifiedLeftMeaning(meaning)
977977
}
978978
if len(accessibleSymbolChain) == 0 ||

internal/checker/symboltracker.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ type SymbolTrackerImpl struct {
1414
}
1515

1616
func NewSymbolTrackerImpl(context *NodeBuilderContext, tracker nodebuilder.SymbolTracker, tchost Host) *SymbolTrackerImpl {
17-
var inner nodebuilder.SymbolTracker
1817
if tracker != nil {
19-
inner = tracker.GetInnerSymbolTracker()
20-
if inner == nil {
21-
inner = tracker
18+
for {
19+
t, ok := tracker.(*SymbolTrackerImpl)
20+
if !ok {
21+
break
22+
}
23+
tracker = t.inner
2224
}
2325
}
2426

25-
return &SymbolTrackerImpl{context, inner, false, tchost}
27+
return &SymbolTrackerImpl{context, tracker, false, tchost}
2628
}
2729

2830
func (this *SymbolTrackerImpl) GetModuleSpecifierGenerationHost() modulespecifiers.ModuleSpecifierGenerationHost {
@@ -32,10 +34,6 @@ func (this *SymbolTrackerImpl) GetModuleSpecifierGenerationHost() modulespecifie
3234
return this.inner.GetModuleSpecifierGenerationHost()
3335
}
3436

35-
func (this *SymbolTrackerImpl) GetInnerSymbolTracker() nodebuilder.SymbolTracker {
36-
return this.inner
37-
}
38-
3937
func (this *SymbolTrackerImpl) TrackSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool {
4038
if !this.DisableTrackSymbol {
4139
if this.inner != nil && this.inner.TrackSymbol(symbol, enclosingDeclaration, meaning) {

internal/fourslash/_scripts/failingTests.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ TestMemberListInReopenedEnum
277277
TestMemberListInWithBlock
278278
TestMemberListOfExportedClass
279279
TestMemberListOnContextualThis
280-
TestModuleReexportedIntoGlobalQuickInfo
281280
TestNgProxy1
282281
TestNoQuickInfoForLabel
283282
TestNoQuickInfoInWhitespace
@@ -364,7 +363,6 @@ TestQuickInfoFromContextualType
364363
TestQuickInfoFunctionKeyword
365364
TestQuickInfoGenerics
366365
TestQuickInfoGetterSetter
367-
TestQuickInfoImportNonunicodePath
368366
TestQuickInfoInInvalidIndexSignature
369367
TestQuickInfoInJsdocInTsFile1
370368
TestQuickInfoInOptionalChain

internal/fourslash/tests/gen/moduleReexportedIntoGlobalQuickInfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestModuleReexportedIntoGlobalQuickInfo(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: /node_modules/@types/three/index.d.ts
1515
export class Vector3 {}

internal/fourslash/tests/gen/quickInfoImportNonunicodePath_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestQuickInfoImportNonunicodePath(t *testing.T) {
1111
t.Parallel()
12-
t.Skip()
12+
1313
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
1414
const content = `// @Filename: /江南今何在/tmp.ts
1515
export const foo = 1;

internal/nodebuilder/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
// TODO: previously all symboltracker methods were optional, but now they're required.
1010
type SymbolTracker interface {
1111
GetModuleSpecifierGenerationHost() modulespecifiers.ModuleSpecifierGenerationHost
12-
GetInnerSymbolTracker() SymbolTracker
1312

1413
TrackSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool
1514
ReportInaccessibleThisError()

internal/testutil/tsbaseline/type_symbol_baseline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (walker *typeWriterWalker) writeTypeOrSymbol(node *ast.Node, isSymbolWalk b
419419
var symbolString strings.Builder
420420
symbolString.Grow(256)
421421
symbolString.WriteString("Symbol(")
422-
symbolString.WriteString(strings.ReplaceAll(fileChecker.SymbolToString(symbol), ast.InternalSymbolNamePrefix, "__"))
422+
symbolString.WriteString(strings.ReplaceAll(fileChecker.SymbolToStringEx(symbol, node.Parent, ast.SymbolFlagsNone, checker.SymbolFormatFlagsAllowAnyNodeKind), ast.InternalSymbolNamePrefix, "__"))
423423
count := 0
424424
for _, declaration := range symbol.Declarations {
425425
if count >= 5 {

internal/transformers/declarations/tracker.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/microsoft/typescript-go/internal/core"
77
"github.com/microsoft/typescript-go/internal/diagnostics"
88
"github.com/microsoft/typescript-go/internal/modulespecifiers"
9-
"github.com/microsoft/typescript-go/internal/nodebuilder"
109
"github.com/microsoft/typescript-go/internal/printer"
1110
"github.com/microsoft/typescript-go/internal/scanner"
1211
)
@@ -23,10 +22,6 @@ func (s *SymbolTrackerImpl) GetModuleSpecifierGenerationHost() modulespecifiers.
2322
return s.host
2423
}
2524

26-
func (s *SymbolTrackerImpl) GetInnerSymbolTracker() nodebuilder.SymbolTracker {
27-
return nil
28-
}
29-
3025
// PopErrorFallbackNode implements checker.SymbolTracker.
3126
func (s *SymbolTrackerImpl) PopErrorFallbackNode() {
3227
s.fallbackStack = s.fallbackStack[:len(s.fallbackStack)-1]

0 commit comments

Comments
 (0)