Skip to content

Don't escape unicode characters in import/export paths in reported errors #57550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3881,7 +3881,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
symbolFromModule || symbolFromVariable;
if (!symbol) {
errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name);
errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, getSourceFileOfNode(node), name);
}
return symbol;
}
Expand Down Expand Up @@ -5919,7 +5919,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function symbolToStringWorker(writer: EmitTextWriter) {
const entity = builder(symbol, meaning!, enclosingDeclaration, nodeFlags)!; // TODO: GH#18217
// add neverAsciiEscape for GH#39027
const printer = enclosingDeclaration?.kind === SyntaxKind.SourceFile
? createPrinterWithRemoveCommentsNeverAsciiEscape()
: createPrinterWithRemoveComments();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
main.ts(1,10): error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
main.ts(1,15): error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.
main.ts(2,10): error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
main.ts(2,15): error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.


==== 🦁.ts (0 errors) ====
export const foo = "bar";
const baz = "baz";

==== main.ts (4 errors) ====
import { bar, baz } from './🦁.ts';
~~~
!!! error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
~~~
!!! error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.
!!! related TS2728 🦁.ts:2:7: 'baz' is declared here.
export { bar, baz } from './🦁.ts';
~~~
!!! error TS2305: Module '"./🦁.ts"' has no exported member 'bar'.
~~~
!!! error TS2459: Module '"./🦁.ts"' declares 'baz' locally, but it is not exported.
!!! related TS2728 🦁.ts:2:7: 'baz' is declared here.

18 changes: 18 additions & 0 deletions tests/baselines/reference/unicodeInModuleSpecifierError1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/unicodeInModuleSpecifierError1.ts] ////

=== 🦁.ts ===
export const foo = "bar";
>foo : Symbol(foo, Decl(🦁.ts, 0, 12))

const baz = "baz";
>baz : Symbol(baz, Decl(🦁.ts, 1, 5))

=== main.ts ===
import { bar, baz } from './🦁.ts';
>bar : Symbol(bar, Decl(main.ts, 0, 8))
>baz : Symbol(baz, Decl(main.ts, 0, 13))

export { bar, baz } from './🦁.ts';
>bar : Symbol(bar, Decl(main.ts, 1, 8))
>baz : Symbol(baz, Decl(main.ts, 1, 13))

28 changes: 28 additions & 0 deletions tests/baselines/reference/unicodeInModuleSpecifierError1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/unicodeInModuleSpecifierError1.ts] ////

=== 🦁.ts ===
export const foo = "bar";
>foo : "bar"
> : ^^^^^
>"bar" : "bar"
> : ^^^^^

const baz = "baz";
>baz : "baz"
> : ^^^^^
>"baz" : "baz"
> : ^^^^^

=== main.ts ===
import { bar, baz } from './🦁.ts';
>bar : any
> : ^^^
>baz : any
> : ^^^

export { bar, baz } from './🦁.ts';
>bar : any
> : ^^^
>baz : any
> : ^^^

11 changes: 11 additions & 0 deletions tests/cases/compiler/unicodeInModuleSpecifierError1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @module: commonjs
// @allowImportingTsExtensions: true
// @noEmit: true

// @Filename: 🦁.ts
export const foo = "bar";
const baz = "baz";

// @Filename: main.ts
import { bar, baz } from './🦁.ts';
export { bar, baz } from './🦁.ts';