Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ebff411
Add tests for file rename edits with quotes in paths
jakebailey Nov 24, 2026
63debea
Escape module specifiers in file rename edits
jakebailey Nov 24, 2026
10ba4db
Add tests for comment terminators in JSDoc module specifiers
jakebailey Nov 25, 2026
596490e
Escape comment terminators in JSDoc module specifiers
jakebailey Nov 24, 2026
ba562d7
Add a test for comment terminators in JSDoc @param completions
jakebailey Nov 25, 2026
525a497
Omit unsafe text from JSDoc @param completions
jakebailey Nov 24, 2026
d583866
Add tests for snippet escaping in member completions
jakebailey Nov 25, 2026
d12ed50
Skip snippet escaping in non-snippet completions
jakebailey Nov 24, 2026
f67a303
Add a test for backslashes in JSX closing tag snippets
jakebailey Nov 25, 2026
67abaf4
Escape backslashes in snippet text
jakebailey Nov 24, 2026
749922c
Add tests for new names in string literal rename edits
jakebailey Nov 25, 2026
5479fe5
Escape new names in string literal rename edits
jakebailey Nov 25, 2026
11ef57d
Add a test for non-identifier mapped property names in member fixes
jakebailey Nov 25, 2026
3c8afb7
Quote non-identifier mapped property names in member fixes
jakebailey Nov 25, 2026
fb37193
Add a test for literal names in binding extraction
jakebailey Nov 25, 2026
b9b9a0e
Use element access for literal names in binding extraction
jakebailey Nov 25, 2026
8b83399
Add a test for string import names when promoting type-only imports
jakebailey Nov 25, 2026
3a6fb85
Preserve string import names when promoting type-only imports
jakebailey Nov 25, 2026
6a08240
Add a test for JSX auto-import names with multi-byte characters
jakebailey Nov 25, 2026
d95d81b
Decode the first character of JSX auto-import names as a rune
jakebailey Nov 25, 2026
055d8f1
Add a test for quotes in import attributes when organizing imports
jakebailey Nov 25, 2026
80864bd
Quote import attributes when grouping imports to organize
jakebailey Nov 25, 2026
dcd1ebe
Add a test for line separators in quoted completion text
jakebailey Nov 25, 2026
02e3a5c
Escape line separators in quoted completion text
jakebailey Nov 25, 2026
982acfd
Add tests for non-identifier names in aliased rename edits
jakebailey Nov 25, 2026
36065c8
Quote non-identifier names in aliased rename edits
jakebailey Nov 25, 2026
68bfda6
Add a test for string export names in declaration emit
jakebailey Nov 25, 2026
11b5d4c
Skip string export names when naming types through import types
jakebailey Nov 25, 2026
2e524bd
Add a test for JSON escapes in tsconfig rename edits
jakebailey Nov 25, 2026
ed44555
Use JSON escapes in tsconfig rename edits
jakebailey Nov 25, 2026
b0a7fc2
Add a test for reference paths containing a quote
jakebailey Nov 25, 2026
465e410
Switch quotes for reference paths containing a quote
jakebailey Nov 25, 2026
432607c
Add a test for JSX auto-import of non-ASCII component names
jakebailey Nov 25, 2026
725e17d
Use JSX intrinsic tag rules for auto-import names
jakebailey Nov 25, 2026
189cf98
Add a test for comment terminators in nested JSDoc @param names
jakebailey Nov 25, 2026
2bcbf1b
Omit unsafe nested property names from JSDoc @param completions
jakebailey Nov 25, 2026
5444ad1
Add a test for string export names in re-exporting modules
jakebailey Nov 25, 2026
dc316a1
Skip string export names when indexing module containers
jakebailey Nov 25, 2026
94f528c
Quote numeric property names renamed to non-identifiers
jakebailey Nov 25, 2026
484ee12
Add a test for alias renames of string-named re-exports
jakebailey Nov 25, 2026
c6ae057
Quote both names when aliasing string-named re-exports
jakebailey Nov 25, 2026
749a411
Add a test for renaming string literals in JSX attributes
jakebailey Nov 25, 2026
fe6956f
Write renamed JSX attribute strings without escapes
jakebailey Nov 25, 2026
c5a5d77
Add a test for quoted names in renamed JSDoc imports
jakebailey Nov 25, 2026
321a27a
Escape comment terminators in names quoted by JSDoc import renames
jakebailey Nov 25, 2026
ffb21ed
Add a test for comment terminators in JSDoc string completions
jakebailey Nov 25, 2026
7ffa8ad
Escape comment terminators in JSDoc string completions
jakebailey Nov 25, 2026
8bf3ea3
Name unique-symbol mapped members with computed names
jakebailey Nov 25, 2026
a0ebe18
Add a test for string export names through namespace imports
jakebailey Nov 25, 2026
ea49fb1
Skip string export names when qualifying through namespace imports
jakebailey Nov 25, 2026
ab0e1d2
Add a test for renaming namespace exports to non-identifiers
jakebailey Nov 25, 2026
b6adb49
Quote non-identifier names in renamed namespace exports
jakebailey Nov 25, 2026
97c34a4
Quote non-identifier names of declarationless members in member fixes
jakebailey Nov 25, 2026
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
24 changes: 18 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,9 @@ 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 name can only reference exports with identifier names
(!ignoreQualification || isIdentifierExportName(symbolFromSymbolTable.Name())) {
Comment on lines +646 to +647
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,62 @@ 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
interface Hidden { x: number }
export { Hidden as "a\\u0062" };
export type I = { [K in "c\\u0064"]: Hidden };
// @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": Hidden;
}`,
Index: 0,
})
}

func TestCodeFixClassImplementInterfaceMappedUniqueSymbolKey(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `declare const key: unique symbol;
type I = { [K in typeof key]: 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: `declare const key: unique symbol;
type I = { [K in typeof key]: number };
class C implements I {
[key]: 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,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ export const z = 42;`,
Index: 0,
})
}

func TestCodeFixMissingTypeAnnotationOnExportsNonIdentifierProperty(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @isolatedDeclarations: true
// @declaration: true
function foo() {
return { 0: 1, "a\\u0062": 1 };
}
export const { 0: x, "a\\u0062": y } = foo();`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCodeFix(t, fourslash.VerifyCodeFixOptions{
Description: "Extract binding expressions to variable",
NewFileContent: `function foo() {
return { 0: 1, "a\\u0062": 1 };
}
const dest = foo();
export const x: number = dest[0];
export const y: number = dest["a\\u0062"];`,
Index: 0,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,23 @@ let x: AAA = new BBB()`
let x: AAA = new BBB()`,
}, nil /*preferences*/)
}

func TestCodeFixPromoteTypeOnlyStringName(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @module: esnext
// @Filename: /m.ts
class K {}
export { K as "a\\u0062" };
export const b = 1;
// @Filename: /a.ts
import { b, type "a\\u0062" as A } from "./m";
b;
new A();`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.GoToFile(t, "/a.ts")
f.VerifyImportFixAtPosition(t, []string{`import { "a\\u0062" as A, b } from "./m";
b;
new A();`}, nil /*preferences*/)
}
28 changes: 28 additions & 0 deletions tsc/internal/fourslash/tests/completionFilterText3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,31 @@ if (true) {
},
})
}

func TestCompletionPropertyAccessLineSeparator(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = "declare const o: { \"a\\u2028b\": number };\no[|.|]/*1*/"
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{
&lsproto.CompletionItem{
Label: "a\u2028b",
InsertText: new(`["a\u2028b"]`),
TextEdit: &lsproto.TextEditOrInsertReplaceEdit{
TextEdit: &lsproto.TextEdit{
NewText: `["a\u2028b"]`,
Range: f.Ranges()[0].LSRange,
},
},
},
},
},
})
}
Loading
Loading