Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved escaping and name-handling defects can produce invalid code or JSON, break JSDoc comments, and alter or leave stale renamed references.
9 open issues
Filter non-identifier exports when building the module index · New Detect intrinsic JSX names instead of checking uppercase runes · New Validate unsafe names in nested destructuring parameter paths · New Use JSON-compatible escaping for config path edits · New Switch quote delimiters when renaming paths with conflicting quotes · New Expand string-named re-exports into correctly quoted alias clauses · New Handle JSX string attributes separately during reference renames · New Quote renamed numeric property names in declarations · New Escape comment terminators in generated JSDoc import specifiers · New
What changed in this PR
This PR hardens escaping in TypeScript’s language service so generated edits preserve unusual names and string contents across renames, completions, imports, and code fixes. It also updates compiler alias selection for non-identifier export names.
Changes:
- Adds context-aware escaping for strings, snippets, JSDoc text, and file-rename edits.
- Improves handling of quoted names, mapped properties, destructuring, and Unicode JSX auto-imports.
- Adds regression tests and updates rename baselines to use an identifier placeholder.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/declarationEmitNonIdentifierExportName.ts |
Tests quoted exports and identifier alias fallback. |
tsc/testdata/baselines/reference/fourslash/state/renameInCommonFile.baseline |
Updates logged rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/renameAncestorProjectRefMangement.baseline |
Updates project-reference rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEditEnd.baseline |
Updates rename placeholder after end edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolutionEdit.baseline |
Updates rename placeholder after edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsNotSolution.baseline |
Updates source-map rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEditEnd.baseline |
Updates rename placeholder after end edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMapsEdit.baseline |
Updates rename placeholder after edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithSourceMaps.baseline |
Updates source-map rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEditEnd.baseline |
Updates project-reference rename placeholder after end edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferencesEdit.baseline |
Updates project-reference rename placeholder after edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithProjectReferences.baseline |
Updates project-reference rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEditEnd.baseline |
Updates redirect-disabled rename placeholder after end edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEdit.baseline |
Updates redirect-disabled rename placeholder after edits. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameWithDisableSourceOfProjectReferenceRedirect.baseline |
Updates redirect-disabled rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameTargetDoesNotExist.baseline |
Updates missing-target rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRenameStartingAtDefinition.baseline |
Updates definition-origin rename placeholder. |
tsc/testdata/baselines/reference/fourslash/state/declarationMapsRename.baseline |
Updates declaration-map rename placeholder. |
tsc/testdata/baselines/reference/compiler/declarationEmitNonIdentifierExportName.types |
Records inferred alias types. |
tsc/testdata/baselines/reference/compiler/declarationEmitNonIdentifierExportName.symbols |
Records quoted export symbols. |
tsc/testdata/baselines/reference/compiler/declarationEmitNonIdentifierExportName.js |
Records JavaScript and declaration output. |
tsc/testdata/baselines/reference/compiler/declarationEmitNonIdentifierExportName.errors.txt |
Records the unnameable-export diagnostic. |
tsc/internal/ls/utilities.go |
Escapes line separators in generated quoted strings. |
tsc/internal/ls/rename.go |
Adds string escaping and non-identifier alias handling. |
tsc/internal/ls/organizeimports.go |
Quotes import-attribute grouping keys to avoid collisions. |
tsc/internal/ls/lsutil/utilities.go |
Adds comment-safe string escaping. |
tsc/internal/ls/file_rename.go |
Escapes replacement paths and guards reference directives. |
tsc/internal/ls/completions.go |
Separates snippet escaping and guards generated JSDoc text. |
tsc/internal/ls/codeactions_missingmemberfixer.go |
Quotes non-identifier mapped member names. |
tsc/internal/ls/codeactions_fixmissingtypeannotation.go |
Uses element access for non-identifier binding properties. |
tsc/internal/ls/autoimport/view.go |
Decodes Unicode initials for JSX completion filtering. |
tsc/internal/ls/autoimport/fix.go |
Escapes JSDoc imports and preserves quoted import names. |
tsc/internal/fourslash/tests/renameEscaping_test.go |
Adds literal and non-identifier rename cases. |
tsc/internal/fourslash/tests/organizeImportsAttributes4_test.go |
Tests quoted import-attribute values. |
tsc/internal/fourslash/tests/importStatementCompletions_noSnippet_test.go |
Tests plain-text imports containing dollar signs. |
tsc/internal/fourslash/tests/getEditsForFileRename_escapedSpecifier_test.go |
Tests escaped paths and JSDoc file-renaming edits. |
tsc/internal/fourslash/tests/completionsSnippetEscaping_test.go |
Tests snippet and plain-text completion escaping. |
tsc/internal/fourslash/tests/completionsOverridingMethod22_test.go |
Updates plain-text dollar-sign completion output. |
tsc/internal/fourslash/tests/completionsImport_jsxOpeningTagImportDefault_test.go |
Adds a non-ASCII JSX default-import case. |
tsc/internal/fourslash/tests/completionFilterText3_test.go |
Tests line-separator property completion escaping. |
tsc/internal/fourslash/tests/codeFixPromoteTypeOnlyOrderingCrash_test.go |
Tests promotion of quoted type-only imports. |
tsc/internal/fourslash/tests/codeFixMissingTypeAnnotationOnExports14_test.go |
Tests extraction of non-identifier binding properties. |
tsc/internal/fourslash/tests/codeFixClassImplementInterfaceMappedType2_test.go |
Tests quoted mapped member generation. |
tsc/internal/fourslash/tests/basicJSDocCompletions_test.go |
Tests comment terminators in parameter completions. |
tsc/internal/fourslash/tests/autoImportQuotedModuleSpecifier_test.go |
Tests comment-safe JSDoc auto-import paths. |
tsc/internal/fourslash/tests/autoCloseTag_test.go |
Tests escaped JSX closing-tag output. |
tsc/internal/fourslash/fourslash.go |
Uses an identifier placeholder for rename baselines. |
tsc/internal/checker/symbolaccessibility.go |
Filters non-identifier aliases for import-type qualifiers. |
Review effort: Max
There was a problem hiding this comment.
🟡 Changes recommended
Code fixes and serialization can emit unresolved or incorrectly bound symbols, while JSX renames can skip valid occurrences in content-mapped files.
4 open issues
9 resolved since last review
Escape comment terminators in generated JSDoc import specifiers Quote renamed numeric property names in declarations Handle JSX string attributes separately during reference renames Expand string-named re-exports into correctly quoted alias clauses Switch quote delimiters when renaming paths with conflicting quotes Use JSON-compatible escaping for config path edits Validate unsafe names in nested destructuring parameter paths Detect intrinsic JSX names instead of checking uppercase runes Filter non-identifier exports when building the module index
Review effort: Max
97c34a4 to
6c2539f
Compare
6c2539f to
e2f8630
Compare
There was a problem hiding this comment.
🟡 Changes recommended
External unique-symbol references can crash declaration emit, and missing-member fixes can generate invalid code with unresolved types, missing value imports, or duplicate bindings.
6 open issues
Declaration emit crashes on indexed static symbol references · New Computed-name imports do not avoid local name collisions · New Qualified symbol references add an unnecessary named import · New Type-only symbol imports are not promoted for computed names · New Export-list unique symbols are not imported for computed members · New Renaming an empty JSX attribute string removes its quotes · New
4 resolved since last review
Review effort: Max
e2f8630 to
fcf2269
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved member-generation and rename bugs can cause missing or conflicting imports, invalid JSX and property accesses, and unintended numeric-key type changes.
8 open issues
Preserve numeric literal types in generated mapped members · New Preserve numeric property syntax when renaming numeric keys · New Use element access when renamed exports need quoting · New Renaming an empty JSX attribute string removes its quotes Export-list unique symbols are not imported for computed members Type-only symbol imports are not promoted for computed names Qualified symbol references add an unnecessary named import Computed-name imports do not avoid local name collisions
1 resolved since last review
Review effort: Max
03914e9 to
94c1b57
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved bugs can produce invalid JSX when renaming empty attribute strings, break namespace accesses when exports are renamed to non-identifiers, and emit incomplete types for computed unique-symbol members.
3 open issues
6 resolved since last review
Preserve numeric property syntax when renaming numeric keys Preserve numeric literal types in generated mapped members Export-list unique symbols are not imported for computed members Type-only symbol imports are not promoted for computed names Qualified symbol references add an unnecessary named import Computed-name imports do not avoid local name collisions
Review effort: Max
|
Opened #65744 |
|
"Escaping" == "qualifying"/"rewriting"? |
|
Sort of, it's more about "some text makes it into the user code via a completion or code action" |
Auto-import should skip or capitalize an export name for a JSX tag only when JSX would read that name as an intrinsic element. Checking the first byte for an uppercase letter misread multi-byte characters: a name starting with a CJK character has a first byte that reads as a lowercase letter, so the component was never offered, and capitalizing the first byte of a multi-byte character produced invalid UTF-8 that crashed when resolving the completion.
Completions that quote a name, such as element access completions for non-identifier properties, built the string literal from JSON escapes. JSON leaves U+2028 and U+2029 raw, but the characters are invisible in source and end a string literal in engines before ES2019, which emit can target. Quote completion text with the escaping shared by other edits, which escapes these characters and comment terminators. It writes lone surrogates with uppercase hex digits, matching the text that JSX attribute completions insert.
When a rename adds an alias to keep a local name, the new name lands in
an export name or property name slot. A new name that is not an
identifier, such as `a-b`, produced `export { foo as a-b }` and
`const { a-b: x } = o`, which do not parse. These slots accept string
literals, so quote the new name there.
An `import { foo }` cannot bind a non-identifier local at all, so it
becomes `import { "a-b" as foo }` and uses of the local `foo` keep
their name.
Config files are JSON, and JavaScript string escapes such as \v or \x00 are invalid there. Renaming a file to a name with such a character wrote a tsconfig.json that no longer parses.
A file renamed to a name with a quote left every reference directive delimited by that quote pointing at the old path. When the path does not contain the other quote character, it can still be written by switching the directive to that quote.
Property names in nested destructuring patterns are copied into the generated @PARAM tags the same way as top-level ones, so a name containing */ or a line break ends the comment or the tag early.
Renaming a numeric property such as 0 in { 0: x } wrote the new name
unquoted, so a name that is not an identifier produced invalid code.
Element accesses of the property were already quoted. A new name that
is itself a non-negative number stays unquoted so the property keeps
its numeric key.
In export { "a b" } from "m", the rename edit covers only the
contents of the string literal. Adding an alias clause there put the
whole clause inside one literal, so each name has to be written as its
own literal within that range.
JSX attribute strings are taken literally, so a renamed string literal reference inside one has to be written as raw text. When the attribute's quote cannot contain the new name, the other quote or an expression container replaces the whole initializer; otherwise the edit stays inside the quotes, which keeps it applicable in content-mapped files where only the value lies in a verbatim span.
The name in `export * as ns` is a module export name that may be a string literal, so renaming it to a non-identifier quotes the name in the same way as an export specifier.
A property synthesized by intersecting mapped types has no declaration to copy its name from, so its name was written as an identifier even when it was not one, which crashed the printer.
Clients compare the filter text against the import statement typed so far, which contains neither tab stops nor snippet escapes. Building the filter text from the plain statement keeps names and module specifiers containing `$` or `\` matchable.
A type reachable only through an export with a string literal name,
such as `export { A as "a b" }`, was printed as `import("./dep").a b`,
which does not parse. Declaration emit wrote it out as is, and code
fixes inserted it into user files.
Import type qualifiers must be identifiers, so these exports cannot be
used to name the type. When the module has another export of the same
type with an identifier name, that name is used; otherwise the type is
not nameable from outside the module, and declaration emit reports the
usual error.
Import type qualifiers must be identifiers, so a module exporting a type only under a string literal name cannot be used to name it. The container index used to find re-exporting modules included such modules, and one could be chosen over a module with a usable name.
A qualified type name such as `dep.x` can only reference an export with
an identifier name, so exports like `export { A as "a b" }` cannot name
a type through a namespace import. Choosing one emits a declaration file
that does not parse instead of falling back to another export or
reporting that the type cannot be named. Values stay reachable through
element access, as in `ns["a b"]`, so type queries for them are written
as indexed access types, as in `(typeof ns)["a b"]`. Static members with
such names are written the same way, including through import types, as
in `typeof import("./dep").C["a b"]`.
8685d29 to
efcf518
Compare
|
Cherry pick this if you feel like it's good to go. I don't want to kick it off prematurely. |
|
TypeScript Bot (@typescript-bot) cherry-pick this to release-7.1 |
|
Hey, Jake Bailey (@jakebailey)! I've created #65792 for you. |


More stuff similar to the last PR but in other areas.
Tests and fixes are split apart, so I would recommend just looking at the fix commits, which are all isolated. That split makes the PR look bigger than it is.