Registry Mirror
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5f36aed
Add tests for text written into source by the language service
jakebailey Nov 24, 2026
439578a
Share string quoting helpers in language service edits
jakebailey Dec 3, 2026
52b6782
Escape module specifiers in file rename edits
jakebailey Nov 24, 2026
5f25b61
Escape comment terminators in strings written by the language service
jakebailey Dec 3, 2026
3209675
Omit unsafe text from JSDoc @param completions
jakebailey Nov 24, 2026
7a6297c
Skip snippet escaping in non-snippet completions
jakebailey Nov 24, 2026
36b4ce2
Escape backslashes in snippet text
jakebailey Nov 24, 2026
b7d08bb
Escape new names in string literal rename edits
jakebailey Nov 25, 2026
c61395f
Quote non-identifier mapped property names in member fixes
jakebailey Nov 25, 2026
6f51076
Use element access for literal names in binding extraction
jakebailey Nov 25, 2026
810baef
Preserve string import names when promoting type-only imports
jakebailey Nov 25, 2026
30d2d78
Use JSX intrinsic tag rules for auto-import names
jakebailey Dec 3, 2026
74e9f8d
Escape line separators in quoted completion text
jakebailey Nov 25, 2026
05d2835
Quote non-identifier names in aliased rename edits
jakebailey Nov 25, 2026
28c85b8
Use JSON escapes in tsconfig rename edits
jakebailey Nov 25, 2026
44b70e2
Switch quotes for reference paths containing a quote
jakebailey Nov 25, 2026
734efd1
Omit unsafe nested property names from JSDoc @param completions
jakebailey Nov 25, 2026
4ea58b7
Quote numeric property names renamed to non-identifiers
jakebailey Nov 25, 2026
197fdcf
Quote both names when aliasing string-named re-exports
jakebailey Nov 25, 2026
6be487d
Write renamed JSX attribute strings without escapes
jakebailey Nov 25, 2026
78ae0e0
Quote non-identifier names in renamed namespace exports
jakebailey Nov 25, 2026
a6263c4
Quote non-identifier names of declarationless members in member fixes
jakebailey Nov 25, 2026
6ab2511
Omit snippet syntax from import statement filter text
jakebailey Nov 25, 2026
f203b03
Skip string export names when naming types through import types
jakebailey Nov 25, 2026
aaf2505
Skip string export names when indexing module containers
jakebailey Nov 25, 2026
efcf518
Skip string export names when qualifying types through namespace imports
jakebailey Dec 3, 2026
File filter
Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions tsc/internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,24 @@ func (b *NodeBuilderImpl) symbolToTypeNode(symbol *ast.Symbol, mask ast.SymbolFl
return b.f.NewImportTypeNode(isTypeOf, lit, attributes, nonRootParts, typeParameterNodes)
}

splitNode := getTopmostIndexedAccessType(nonRootParts.AsIndexedAccessTypeNode())
qualifier := splitNode.ObjectType.AsTypeReferenceNode().TypeName
return b.f.NewIndexedAccessTypeNode(
b.f.NewImportTypeNode(isTypeOf, lit, attributes, qualifier, typeParameterNodes),
splitNode.IndexType,
)
var rebuild func(node *ast.Node) *ast.Node
rebuild = func(node *ast.Node) *ast.Node {
indexedAccess := node.AsIndexedAccessTypeNode()
var objectType *ast.Node
switch {
case ast.IsIndexedAccessTypeNode(indexedAccess.ObjectType):
objectType = rebuild(indexedAccess.ObjectType)
case ast.IsParenthesizedTypeNode(indexedAccess.ObjectType):
// (typeof A.B)[...] becomes typeof import("...").A.B[...]
qualifier := indexedAccess.ObjectType.Type().AsTypeQueryNode().ExprName
objectType = b.f.NewImportTypeNode(true /*isTypeOf*/, lit, attributes, qualifier, typeParameterNodes)
default:
qualifier := indexedAccess.ObjectType.AsTypeReferenceNode().TypeName
objectType = b.f.NewImportTypeNode(isTypeOf, lit, attributes, qualifier, typeParameterNodes)
}
return b.f.NewIndexedAccessTypeNode(objectType, indexedAccess.IndexType)
}
return rebuild(nonRootParts)

}

Expand All @@ -740,13 +752,6 @@ func (b *NodeBuilderImpl) symbolToTypeNode(symbol *ast.Symbol, mask ast.SymbolFl
return b.f.NewTypeReferenceNode(entityName, typeArguments)
}

func getTopmostIndexedAccessType(node *ast.IndexedAccessTypeNode) *ast.IndexedAccessTypeNode {
if ast.IsIndexedAccessTypeNode(node.ObjectType) {
return getTopmostIndexedAccessType(node.ObjectType.AsIndexedAccessTypeNode())
}
return node
}

func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index int, stopper int, overrideTypeArguments *ast.NodeList) *ast.Node {
typeParameterNodes := overrideTypeArguments
if index != (len(chain) - 1) {
Expand Down Expand Up @@ -791,6 +796,7 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index
}
}

exportName := symbolName
if len(symbolName) == 0 {
var name *ast.Node
for _, d := range symbol.Declarations() {
Expand All @@ -810,6 +816,7 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index
return lhs
}
symbolName = b.getNameOfSymbolAsWritten(symbol)
exportName = symbol.Name()
}
b.ctx.approximateLength += len(symbolName) + 1

Expand All @@ -830,11 +837,24 @@ func (b *NodeBuilderImpl) createAccessFromSymbolChain(chain []*ast.Symbol, index
)
}

if index > stopper && !scanner.IsIdentifierText(exportName, core.LanguageVariantStandard) {
// Type names can't reference exports with string literal names, so these
// chains reach a value, as in (typeof ns)["a b"]
lhs := b.createAccessFromSymbolChain(chain, index-1, stopper, overrideTypeArguments)
if !ast.IsIndexedAccessTypeNode(lhs) {
lhs = b.f.NewParenthesizedTypeNode(b.f.NewTypeQueryNode(lhs, nil))
}
return b.f.NewIndexedAccessTypeNode(lhs, b.f.NewLiteralTypeNode(b.newStringLiteral(exportName)))
Comment thread
jakebailey marked this conversation as resolved.
Resolved
Comment thread
jakebailey marked this conversation as resolved.
Resolved
}

identifier := b.newIdentifier(symbolName, symbol)
b.e.AddEmitFlags(identifier, printer.EFNoAsciiEscaping)

if index > stopper {
lhs := b.createAccessFromSymbolChain(chain, index-1, stopper, overrideTypeArguments)
if ast.IsIndexedAccessTypeNode(lhs) {
return b.f.NewIndexedAccessTypeNode(lhs, b.f.NewLiteralTypeNode(b.newStringLiteral(exportName)))
}
if b.ctx.flags&nodebuilder.FlagsUseInstantiationExpressions != 0 && index < len(chain)-1 && typeParameterNodes != nil && len(typeParameterNodes.Nodes) != 0 {
b.e.SetDisplayTypeArguments(identifier, typeParameterNodes)
}
Expand Down
25 changes: 19 additions & 6 deletions tsc/internal/checker/symbolaccessibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/microsoft/TypeScript/tsc/internal/collections"
"github.com/microsoft/TypeScript/tsc/internal/core"
"github.com/microsoft/TypeScript/tsc/internal/printer"
"github.com/microsoft/TypeScript/tsc/internal/scanner"
)

func (c *Checker) IsTypeSymbolAccessible(typeSymbol *ast.Symbol, enclosingDeclaration *ast.Node) bool {
Expand Down Expand Up @@ -262,8 +263,10 @@ func (c *Checker) buildExternalModuleContainerIndex() {
}
container := c.getSymbolOfDeclaration(file.AsNode())
index.moduleOrder[container] = len(index.moduleOrder)
for _, exported := range c.getExportsOfSymbol(container).All() {
index.add(c.getResolvedTarget(exported), container)
for name, exported := range c.getExportsOfSymbol(container).All() {
if isIdentifierExportName(name) {
index.add(c.getResolvedTarget(exported), container)
}
}
if exportEquals := container.Exports().Get(ast.InternalSymbolNameExportEquals); exportEquals != nil {
index.add(c.getResolvedTarget(exportEquals), container)
Expand Down Expand Up @@ -401,6 +404,13 @@ func (c *Checker) getContainersOfSymbol(symbol *ast.Symbol, enclosingDeclaration
return append(bestContainers, alternativeContainers...)
}

// isIdentifierExportName reports whether an export can be written as the
// qualifier of an import type, such as `b` in `import("a").b`. Exports with
// string literal names, such as `export { x as "a b" }`, cannot.
func isIdentifierExportName(name string) bool {
return scanner.IsIdentifierText(name, core.LanguageVariantStandard)
}

func (c *Checker) getAliasForSymbolInContainer(container *ast.Symbol, symbol *ast.Symbol) *ast.Symbol {
if container == c.getParentOfSymbol(symbol) {
// fast path, `symbol` is either already the alias or isn't aliased
Expand All @@ -416,12 +426,12 @@ func (c *Checker) getAliasForSymbolInContainer(container *ast.Symbol, symbol *as
}
exports := c.getExportsOfSymbol(container)
quick, ok := exports.Lookup(symbol.Name())
if ok && quick != nil && c.getSymbolIfSameReference(quick, symbol) != nil {
if ok && quick != nil && isIdentifierExportName(quick.Name()) && c.getSymbolIfSameReference(quick, symbol) != nil {
return quick
}
var candidates []*ast.Symbol
for _, exported := range exports.All() {
if c.getSymbolIfSameReference(exported, symbol) != nil {
for name, exported := range exports.All() {
if isIdentifierExportName(name) && c.getSymbolIfSameReference(exported, symbol) != nil {
Comment thread
jakebailey marked this conversation as resolved.
Resolved
candidates = append(candidates, exported)
}
}
Expand Down Expand Up @@ -632,7 +642,10 @@ func (c *Checker) trySymbolTable(
(isLocalNameLookup && !core.Some(symbolFromSymbolTable.Declarations(), isNamespaceReexportDeclaration) || !isLocalNameLookup) &&
// While exports are generally considered to be in scope, export-specifier declared symbols are _not_
// See similar comment in `resolveName` for details
(ignoreQualification || len(getDeclarationsOfKind(symbolFromSymbolTable, ast.KindExportSpecifier)) == 0) {
(ignoreQualification || len(getDeclarationsOfKind(symbolFromSymbolTable, ast.KindExportSpecifier)) == 0) &&
// A qualified type name can only reference exports with identifier names;
// values can use element access, as in `ns["a b"]`
(!ignoreQualification || ctx.meaning&ast.SymbolFlagsValue == ast.SymbolFlagsValue || isIdentifierExportName(symbolFromSymbolTable.Name())) {
resolvedImportedSymbol := c.resolveAlias(symbolFromSymbolTable)
candidate := c.getCandidateListForSymbol(ctx, symbolFromSymbolTable, resolvedImportedSymbol, ignoreQualification)
if len(candidate) > 0 {
Expand Down
10 changes: 7 additions & 3 deletions tsc/internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4763,6 +4763,10 @@ func (f *FourslashTest) BaselineAutoImportsCompletions(t *testing.T, markerNames
// string | *Marker | *RangeMarker
type MarkerOrRangeOrName = any

// renameBaselinePlaceholder is an identifier, so rename edits take the same form
// as renames to an ordinary new name.
const renameBaselinePlaceholder = "RENAME_PLACEHOLDER"

func (f *FourslashTest) VerifyBaselineRename(
t *testing.T,
preferences *lsutil.UserPreferences,
Expand Down Expand Up @@ -4806,7 +4810,7 @@ func (f *FourslashTest) verifyBaselineRename(
Uri: lsconv.FileNameToDocumentURI(f.activeFilename),
},
Position: f.currentCaretPosition,
NewName: "?",
NewName: renameBaselinePlaceholder,
}

result := f.sendRequest(t, lsproto.TextDocumentRenameInfo, params)
Expand Down Expand Up @@ -4843,15 +4847,15 @@ func (f *FourslashTest) verifyBaselineRename(
endMarker: "RENAME|]",
startMarkerPrefix: func(span documentSpan) *string {
text := spanToText[span]
prefixAndSuffix := strings.Split(text, "?")
prefixAndSuffix := strings.Split(text, renameBaselinePlaceholder)
if prefixAndSuffix[0] != "" {
return new("/*START PREFIX*/" + prefixAndSuffix[0])
}
return nil
},
endMarkerSuffix: func(span documentSpan) *string {
text := spanToText[span]
prefixAndSuffix := strings.Split(text, "?")
prefixAndSuffix := strings.Split(text, renameBaselinePlaceholder)
if prefixAndSuffix[1] != "" {
return new(prefixAndSuffix[1] + "/*END SUFFIX*/")
}
Expand Down
13 changes: 13 additions & 0 deletions tsc/internal/fourslash/tests/autoCloseTag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,16 @@ const x = <p>
"9": new("</div>"),
})
}

func TestAutoCloseTagEscapedName(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @noLib: true
// @Filename: /a.tsx
const x = <div\u0024bar>/*0*/;`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyJsxClosingTag(t, map[string]*string{
"0": new(`</div\\u0024bar>`),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,21 @@ func TestAutoImportQuotedModuleSpecifier(t *testing.T) {
}
}
}

func TestAutoImportJSDocCommentTerminator(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowJs: true
// @checkJs: true
// @Filename: /dir*/mod.js
export {};
/** @typedef {number} T */
// @Filename: /b.js
/** @type {T} */
const x = 0;`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToFile(t, "/b.js")
f.VerifyImportFixAtPosition(t, []string{`/** @type {import("./dir*\/mod").T} */
const x = 0;`}, nil /*preferences*/)
}
93 changes: 93 additions & 0 deletions tsc/internal/fourslash/tests/basicJSDocCompletions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/microsoft/TypeScript/tsc/internal/fourslash"
. "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util"
"github.com/microsoft/TypeScript/tsc/internal/ls"
"github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)
Expand Down Expand Up @@ -122,3 +123,95 @@ function baz(x = 0) {
},
})
}

func TestJSDocParamCompletionsWithCommentTerminators(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @filename: file.js
// @allowJs: true
/**
* @/*1*/
*/
function f(a = "*/", b = { "*/": 1 }) {}
/**
* @/*2*/
*/
function g({ "*/": c }) {}
/**
* @/*3*/
*/
function h({ "*/": { x } }) {}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
"param {string} [a] ",
"param {*} [b] ",
},
},
})
f.VerifyCompletions(t, "2", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
"param {*} param0 ",
},
},
})
f.VerifyCompletions(t, "3", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
},
Items: &fourslash.CompletionsExpectedItems{
Includes: []fourslash.CompletionsExpectedItem{
"param {*} param0 ",
},
},
})
}

func TestJSDocStringCompletionWithCommentTerminator(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @allowJs: true
// @checkJs: true
// @Filename: /types.ts
export interface Obj { "a*/b": number }
// @Filename: /user.js
/** @type {import("./types").Obj["[|a/*1*/|]"]} */
let a;`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCompletions(t, "1", &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
EditRange: Ignored,
},
Items: &fourslash.CompletionsExpectedItems{
Exact: []fourslash.CompletionsExpectedItem{
&lsproto.CompletionItem{
Label: "a*/b",
Kind: new(lsproto.CompletionItemKindField),
SortText: new(string(ls.SortTextLocationPriority)),
InsertText: new(`a*\/b`),
TextEdit: &lsproto.TextEditOrInsertReplaceEdit{
TextEdit: &lsproto.TextEdit{
NewText: `a*\/b`,
Range: f.Ranges()[0].LSRange,
},
},
},
},
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,59 @@ type ClickEventSupport = ListenActionable<{ Click: 'some-click-event-payload' }>
Index: 0,
})
}

func TestCodeFixClassImplementInterfaceNonIdentifierNames(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @Filename: /node_modules/dep/index.d.ts
export type I = { [K in "c\\u0064"]: number };
// @Filename: /a.ts
import { I } from "dep";
class C implements I {}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToFile(t, "/a.ts")
f.VerifyCodeFix(t, fourslash.VerifyCodeFixOptions{
Description: "Implement interface 'I'",
NewFileContent: `import { I } from "dep";
class C implements I {
"c\\u0064": number;
}`,
Index: 0,
})
}

func TestCodeFixClassImplementInterfaceMappedNumericKeys(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `type I = { [K in 0 | -1]: number };
class C implements I {}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCodeFix(t, fourslash.VerifyCodeFixOptions{
Description: "Implement interface 'I'",
NewFileContent: `type I = { [K in 0 | -1]: number };
class C implements I {
[-1]: number;
0: number;
}`,
Index: 0,
})
}

func TestCodeFixClassImplementInterfaceIntersectedMappedNonIdentifier(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `type I = { [K in "a b"]: string | number } & { [K in "a b"]: number };
class C implements I {}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCodeFix(t, fourslash.VerifyCodeFixOptions{
Description: "Implement interface 'I'",
NewFileContent: `type I = { [K in "a b"]: string | number } & { [K in "a b"]: number };
class C implements I {
"a b": number;
}`,
Index: 0,
})
}
Loading
Loading