Skip to content

Commit 008ab55

Browse files
committed
Always have host
1 parent 28fe3d4 commit 008ab55

File tree

1,166 files changed

+14846
-3949
lines changed

Some content is hidden

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

1,166 files changed

+14846
-3949
lines changed

internal/checker/nodebuilder.go

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

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

1515
// EmitContext implements NodeBuilderInterface.
@@ -20,6 +20,7 @@ func (b *NodeBuilder) EmitContext() *printer.EmitContext {
2020
func (b *NodeBuilder) enterContext(enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) {
2121
b.ctxStack = append(b.ctxStack, b.impl.ctx)
2222
b.impl.ctx = &NodeBuilderContext{
23+
host: b.host,
2324
tracker: tracker,
2425
flags: flags,
2526
internalFlags: internalFlags,
@@ -32,14 +33,7 @@ func (b *NodeBuilder) enterContext(enclosingDeclaration *ast.Node, flags nodebui
3233
enclosingSymbolTypes: make(map[ast.SymbolId]*Type),
3334
remappedSymbolReferences: make(map[ast.SymbolId]*ast.Symbol),
3435
}
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
41-
}
42-
tracker = NewSymbolTrackerImpl(b.impl.ctx, tracker, moduleResolverHost)
36+
tracker = NewSymbolTrackerImpl(b.impl.ctx, tracker)
4337
b.impl.ctx.tracker = tracker
4438
}
4539

@@ -178,7 +172,7 @@ func (b *NodeBuilder) TypeToTypeNode(typ *Type, enclosingDeclaration *ast.Node,
178172

179173
func NewNodeBuilder(ch *Checker, e *printer.EmitContext) *NodeBuilder {
180174
impl := newNodeBuilderImpl(ch, e)
181-
return &NodeBuilder{impl: impl, ctxStack: make([]*NodeBuilderContext, 0, 1), basicHost: ch.program}
175+
return &NodeBuilder{impl: impl, ctxStack: make([]*NodeBuilderContext, 0, 1), host: ch.program}
182176
}
183177

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

internal/checker/nodebuilderimpl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type NodeBuilderSymbolLinks struct {
5353
specifierCache module.ModeAwareCache[string]
5454
}
5555
type NodeBuilderContext struct {
56+
host Host
5657
tracker nodebuilder.SymbolTracker
5758
approximateLength int
5859
encounteredError bool
@@ -1155,7 +1156,7 @@ func (b *nodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
11551156
return stringutil.StripQuotes(symbol.Name)
11561157
}
11571158
}
1158-
if b.ctx.enclosingFile == nil || b.ctx.tracker.GetModuleSpecifierGenerationHost() == nil {
1159+
if b.ctx.enclosingFile == nil {
11591160
if isAmbientModuleSymbolName(symbol.Name) {
11601161
return stringutil.StripQuotes(symbol.Name)
11611162
}
@@ -1188,7 +1189,7 @@ func (b *nodeBuilderImpl) getSpecifierForModuleSymbol(symbol *ast.Symbol, overri
11881189
// just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
11891190
// using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative
11901191
// specifier preference
1191-
host := b.ctx.tracker.GetModuleSpecifierGenerationHost()
1192+
host := b.ctx.host
11921193
specifierCompilerOptions := b.ch.compilerOptions
11931194
specifierPref := modulespecifiers.ImportModuleSpecifierPreferenceProjectRelative
11941195
endingPref := modulespecifiers.ImportModuleSpecifierEndingPreferenceNone

internal/checker/symboltracker.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ package checker
22

33
import (
44
"github.com/microsoft/typescript-go/internal/ast"
5-
"github.com/microsoft/typescript-go/internal/modulespecifiers"
65
"github.com/microsoft/typescript-go/internal/nodebuilder"
76
)
87

98
type SymbolTrackerImpl struct {
109
context *NodeBuilderContext
1110
inner nodebuilder.SymbolTracker
1211
DisableTrackSymbol bool
13-
tchost Host
1412
}
1513

16-
func NewSymbolTrackerImpl(context *NodeBuilderContext, tracker nodebuilder.SymbolTracker, tchost Host) *SymbolTrackerImpl {
14+
func NewSymbolTrackerImpl(context *NodeBuilderContext, tracker nodebuilder.SymbolTracker) *SymbolTrackerImpl {
1715
if tracker != nil {
1816
for {
1917
t, ok := tracker.(*SymbolTrackerImpl)
@@ -24,14 +22,7 @@ func NewSymbolTrackerImpl(context *NodeBuilderContext, tracker nodebuilder.Symbo
2422
}
2523
}
2624

27-
return &SymbolTrackerImpl{context, tracker, false, tchost}
28-
}
29-
30-
func (this *SymbolTrackerImpl) GetModuleSpecifierGenerationHost() modulespecifiers.ModuleSpecifierGenerationHost {
31-
if this.inner == nil {
32-
return this.tchost
33-
}
34-
return this.inner.GetModuleSpecifierGenerationHost()
25+
return &SymbolTrackerImpl{context, tracker, false}
3526
}
3627

3728
func (this *SymbolTrackerImpl) TrackSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool {

internal/fourslash/_scripts/manualTests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ completionListInClosedFunction05
22
completionsAtIncompleteObjectLiteralProperty
33
completionsSelfDeclaring1
44
completionsWithDeprecatedTag4
5+
moduleReexportedIntoGlobalQuickInfo
6+
quickInfoImportNonunicodePath

internal/fourslash/tests/gen/moduleReexportedIntoGlobalQuickInfo_test.go renamed to internal/fourslash/tests/manual/moduleReexportedIntoGlobalQuickInfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ declare global {
2323
// @Filename: /index.ts
2424
let v = new /*1*/THREE.Vector3();`
2525
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
26-
f.VerifyQuickInfoAt(t, "1", "const THREE: typeof import(\"/node_modules/@types/three/index\")", "")
26+
f.VerifyQuickInfoAt(t, "1", "const THREE: typeof import(\"three\")", "")
2727
}

internal/fourslash/tests/gen/quickInfoImportNonunicodePath_test.go renamed to internal/fourslash/tests/manual/quickInfoImportNonunicodePath_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export const foo = 1;
1616
// @Filename: /test.ts
1717
import { foo } from "./江南/*1*/今何在/tmp";`
1818
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
19-
f.VerifyQuickInfoAt(t, "1", "module \"/江南今何在/tmp\"", "")
19+
f.VerifyQuickInfoAt(t, "1", "module \"./江南今何在/tmp\"", "")
2020
}

internal/nodebuilder/types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ package nodebuilder
33

44
import (
55
"github.com/microsoft/typescript-go/internal/ast"
6-
"github.com/microsoft/typescript-go/internal/modulespecifiers"
76
)
87

98
// TODO: previously all symboltracker methods were optional, but now they're required.
109
type SymbolTracker interface {
11-
GetModuleSpecifierGenerationHost() modulespecifiers.ModuleSpecifierGenerationHost
12-
1310
TrackSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool
1411
ReportInaccessibleThisError()
1512
ReportPrivateInBaseOfClassExpression(propertyName string)

internal/transformers/declarations/tracker.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/microsoft/typescript-go/internal/checker"
66
"github.com/microsoft/typescript-go/internal/core"
77
"github.com/microsoft/typescript-go/internal/diagnostics"
8-
"github.com/microsoft/typescript-go/internal/modulespecifiers"
98
"github.com/microsoft/typescript-go/internal/printer"
109
"github.com/microsoft/typescript-go/internal/scanner"
1110
)
@@ -17,11 +16,6 @@ type SymbolTrackerImpl struct {
1716
fallbackStack []*ast.Node
1817
}
1918

20-
// GetModuleSpecifierGenerationHost implements checker.SymbolTracker.
21-
func (s *SymbolTrackerImpl) GetModuleSpecifierGenerationHost() modulespecifiers.ModuleSpecifierGenerationHost {
22-
return s.host
23-
}
24-
2519
// PopErrorFallbackNode implements checker.SymbolTracker.
2620
func (s *SymbolTrackerImpl) PopErrorFallbackNode() {
2721
s.fallbackStack = s.fallbackStack[:len(s.fallbackStack)-1]

testdata/baselines/reference/compiler/declarationEmitAugmentationUsesCorrectSourceFile.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ declare namespace Knex {
2727
}
2828

2929
export = knex;
30-
>knex : typeof import("index.ts")
30+
>knex : typeof import("knex")
3131

3232
=== index.ts ===
3333
import "knex";
3434
declare module "knex" {
35-
>"knex" : typeof import("node_modules/knex/index")
35+
>"knex" : typeof import("knex")
3636

3737
namespace Knex {
3838
>Knex : typeof Knex

testdata/baselines/reference/compiler/symbolLinkDeclarationEmitModuleNamesRootDir.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { BindingKey } from '@loopback/context';
1717
export const CONTROLLER_CLASS = BindingKey.create<ControllerClass>(null as any); // line in question
1818
>CONTROLLER_CLASS : BindingKey<ControllerClass>
1919
>BindingKey.create<ControllerClass>(null as any) : BindingKey<ControllerClass>
20-
>BindingKey.create : <T extends import("/monorepo/context/index").Constructor<any>>(ctor: T) => BindingKey<T>
20+
>BindingKey.create : <T extends import("@loopback/context").Constructor<any>>(ctor: T) => BindingKey<T>
2121
>BindingKey : typeof BindingKey
22-
>create : <T extends import("/monorepo/context/index").Constructor<any>>(ctor: T) => BindingKey<T>
22+
>create : <T extends import("@loopback/context").Constructor<any>>(ctor: T) => BindingKey<T>
2323
>null as any : any
2424

2525
=== /monorepo/context/src/value-promise.d.ts ===

0 commit comments

Comments
 (0)